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 .
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.
- import WKMarkup.h and WKMarkup.m
- 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];
template:
Hi, {{name.first}}!
data: { name: { first: "John", last: "Doe" } }
output:"Hi, John!"
template:Favorite color: {{colors.0}}
data:{
name: "John Doe",
colors: ["Red", "Blue", "Green"]
}
output:"Favorite color: Red"
- 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>
- 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"
- 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
- 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.