markus 4.0.2 → 4.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +69 -7
- data/markus.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57c28ac410d72c1221d6fa228e2be6ac5e5f3f0b
|
4
|
+
data.tar.gz: fd2e2836a0e6cdf937f662844e6ff5b7df770885
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 757040ac2a15bb434a8f0d5be83ff576069340947ebd7a565cc38af3745b99570f2b22e3a65fa77ccdd3b0867eeca3150a93ee32ab3f5acb4ef6608f03e06a63
|
7
|
+
data.tar.gz: 1dd4d8bc8250c282b9adb15ee7c5294636ba1a6951855087e9160df9a8c6320c75ca4f42f17dd2a92efee0af461532980fa1965e20da090acaf6b7ef0bceb4ba
|
data/README.md
CHANGED
@@ -1,19 +1,74 @@
|
|
1
1
|
# Markup UnderScore
|
2
2
|
|
3
|
-
Copyright (C) 2004-2016 Jürgen Mangler <juergen.mangler@
|
3
|
+
Copyright (C) 2004-2016 Jürgen "eTM" Mangler <juergen.mangler@gmail.com>
|
4
4
|
|
5
5
|
MarkUS is freely distributable according to the terms of the
|
6
|
-
GNU Lesser General Public License (see the file 'COPYING').
|
6
|
+
GNU Lesser General Public License 3.0 (see the file 'COPYING').
|
7
7
|
|
8
|
-
This
|
8
|
+
This code is distributed without any warranty. See the file
|
9
9
|
'COPYING' for details.
|
10
10
|
|
11
11
|
## Introduction
|
12
12
|
|
13
|
-
All template libraries suck. But sometimes they are useful, for
|
14
|
-
quick'
|
13
|
+
All template libraries suck. But sometimes they are useful, for
|
14
|
+
quick n' dirty building of documents. This template library will of course suck
|
15
15
|
as well. It is inspired by _why's markaby. It supports JSON and XML.
|
16
16
|
|
17
|
+
## Usage - Jump Start
|
18
|
+
|
19
|
+
Its fairly simple:
|
20
|
+
|
21
|
+
1. Create classes that inherit from MarkUS, and add templates with a name to them (see below).
|
22
|
+
2. In the templates use arbitrary code, mixed with functions that have an _ at the end.
|
23
|
+
3. Everything with an _ at the end is added to the result buffer
|
24
|
+
- If the first parameter is a String or Integer it will be used as content of the element
|
25
|
+
- If any parameter is a Hash it will be used as attributes in XML, or you-know-what in JSON
|
26
|
+
- If any parameter is an Array it will be used as you-know-what in JSON
|
27
|
+
- If it has a block, a nested data structure is implied (see template examples below)
|
28
|
+
- JSON only: by default a Hash is assumed, if you pass a paramter ```array```, e.g. ```value_ do |array| ... end```, the result is ```"value": [ ... ]```
|
29
|
+
- ```#template_!``` is a special method to include other templates
|
30
|
+
- ```#element_!``` allows you to include stuff in your result that is not a valid ruby function name (e.g. with a dot in the name - see below)
|
31
|
+
4. Get the result by instantiating the class and calling one of ```#json_!```, ```#xml_!```, ```#html_!```
|
32
|
+
- ```#xml_!``` and ```#html_!``` differ in the way elements with no content are printed. XML uses short-handed tags, HTML doesn't.
|
33
|
+
|
34
|
+
## Usage - Example
|
35
|
+
|
36
|
+
template1.rb:
|
37
|
+
```
|
38
|
+
class Common < MarkUS
|
39
|
+
template :test1 do
|
40
|
+
query_ [2, 3, "world"]
|
41
|
+
end
|
42
|
+
template :test2 do
|
43
|
+
query_ :a => 2, :b => "hello"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
template2.rb:
|
49
|
+
```
|
50
|
+
require File.expand_path(File.dirname(__FILE__) + '/template1')
|
51
|
+
class Something < MarkUS
|
52
|
+
templates Common
|
53
|
+
|
54
|
+
indent
|
55
|
+
|
56
|
+
template :main do
|
57
|
+
template_! :test1
|
58
|
+
template_! :test2
|
59
|
+
end
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
main.rb:
|
64
|
+
```
|
65
|
+
require File.expand_path(File.dirname(__FILE__) + '/template2')
|
66
|
+
s = Something.new
|
67
|
+
result = s.json_! :main
|
68
|
+
```
|
69
|
+
|
70
|
+
If you add ```reload``` to any of the template classes, they will be reloaded if they change (if templates are use in a long-running service).
|
71
|
+
|
17
72
|
## HTML Example Template
|
18
73
|
|
19
74
|
```
|
@@ -59,6 +114,13 @@ knows.
|
|
59
114
|
|
60
115
|
* You need a least ruby 1.9.2
|
61
116
|
|
62
|
-
##
|
117
|
+
## Further Reading
|
118
|
+
|
119
|
+
View the example in the ./examples subdirectory. View the tests in the ./test subdirectory. From there you should be able to figure it out yourself. Tip: neat combinations with heredocs are possible, e.g. to create script tags in html.
|
120
|
+
|
121
|
+
```
|
122
|
+
script_ <<~end
|
123
|
+
var foo = "bar";
|
124
|
+
end
|
125
|
+
```
|
63
126
|
|
64
|
-
View the examples in the ./examples subdirectory.
|
data/markus.gemspec
CHANGED