目录

Markup for Objective C

Markup is simple and useful Markup Language。it was wirtten by Js and widely used in web. We alse can use it in Native code, So I rewrite it by Objective C . When you write iOS App , you can think about it .

Why use markup

1.markup is powerful,simple, and lightly

2.markup can combine temple and data,which help you merge data to view. you need not write hard code in your project.

3.lots of project use markup ,such as vue.js.

How to use

  1. import WKMarkup.h and WKMarkup.m
  2. use the interface.

-(NSString*) markupWithTemp:(id)tpContent withContent:(id)context withOption:(id)options;

NSDictionary *reDic = [NSJSONSerialization JSONObjectWithData:[self.dataContent dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableLeaves error:&err];
    
value = [markup markupWithTemp:self.templateStr withContent:reDic withOption:nil];

example

value

template: Hi, {{name.first}}!

data: { name: { first: “John”, last: “Doe” } }

output:"Hi, John!"

Array

template:Favorite color: {{colors.0}}
data:{ name: “John Doe”, colors: [“Red”, “Blue”, “Green”] }
output:"Favorite color: Red"

Loops

  • template:<ul>{{brothers}}<li>{{.}}</li>{{/brothers}}</ul>
  • data:{ name: “John Doe”, brothers: [“Jack”, “Joe”, “Jim”] }
  • output:<ul><li>Jack</li><li>Joe</li><li>Jim</li></ul>

Pipes

  • template:Name: {{name|upcase}}
  • data:{ name: “John Doe”, alias: “ J-Do “, phone: null, gender: “male”, age: 33.33, vitals: [68, 162.5, “AB”], brothers: [“Jack”, “Joe”, “Jim”], sisters: [{name: “Jill”}, {name: “Jen”}], jiggy: true }
  • “Name: JOHN DOE”

Chaining pipes

  • template:Alias: {{alias|trim|downcase}}
  • data:{ name: “John Doe”, alias: “ J-Do “, phone: null, gender: “male”, age: 33.33, vitals: [68, 162.5, “AB”], brothers: [“Jack”, “Joe”, “Jim”], sisters: [{name: “Jill”}, {name: “Jen”}], jiggy: true }
  • output:Alias: j-do

IF and IF/ELSE statements

  • template:{{if children|empty}} John has no kids. {{/if}}
  • data:{ name: “John Doe”, alias: “ J-Do “, phone: null, gender: “male”, age: 33.33, vitals: [68, 162.5, “AB”], brothers: [“Jack”, “Joe”, “Jim”], sisters: [{name: “Jill”}, {name: “Jen”}], jiggy: true }
  • output:John has no kids.
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802032778号