markus 4.0.15 → 4.0.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43483dab17abf88bbfea4c2bb2df649de3fb0bb2
4
- data.tar.gz: b80d758fffbe7baa08ee39f8e2189155b2990bff
3
+ metadata.gz: 7f0ffc073e5244986b80b5ea4387179a4f6c45a7
4
+ data.tar.gz: dea294a898cd66808c01d51aaa2117ce8ba7469f
5
5
  SHA512:
6
- metadata.gz: 100bdfbec50cf4e401a97cd7ba1722cdb842be3d08a712d0fd0987e254d6ff63e0c0c1c600796e6533bde336002ca963fd64c4bbd7d5d8a2d7894a288f9bc241
7
- data.tar.gz: 357465f48812642cf15aa29daf82c2c96915e54ead942f109f825bd4a3d98069a6b3e30b0a0211b7247ea579fb575df96b6578ea4e0f46178047f02d9d4168e8
6
+ metadata.gz: c34f01d5632b892fd3bd60ab731249d23126f8596c316c1b99d0940e111e856b4ed395cb93fe709b0fa7008bd371762046bbf537fa22ed1e9596a563dc607b03
7
+ data.tar.gz: a9c0e966baaf7954e11f1bdfd4d9de6849db78beb5ed9cc6d7ebb32de8c44638ad1ce1151299e3aa5d2ebac2f71627b01855cbf1970db3473d6ac9488de33b1a
data/README.md CHANGED
@@ -2,17 +2,23 @@
2
2
 
3
3
  Copyright (C) 2004-2016 Jürgen "eTM" Mangler <juergen.mangler@gmail.com>
4
4
 
5
- MarkUS is freely distributable according to the terms of the
6
- GNU Lesser General Public License 3.0 (see the file 'COPYING').
5
+ MarkUS is freely distributable according to the terms of the GNU Lesser General
6
+ Public License 3.0 (see the file 'COPYING').
7
7
 
8
- This code is distributed without any warranty. See the file
9
- 'COPYING' for details.
8
+ This code is distributed without any warranty. See the file 'COPYING' for
9
+ details.
10
10
 
11
11
  ## Introduction
12
12
 
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
- as well. It is inspired by _why's markaby. It supports JSON and XML.
13
+ All template libraries suck. But sometimes they are useful, for quick n' dirty
14
+ building of documents. This template library will of course suck as well. It is
15
+ inspired by _why's markaby. It supports JSON and XML.
16
+
17
+ ## Possible Applications
18
+
19
+ It can be used for better handling of big elasticsearch querys (json), for
20
+ creating html documents, or for stuff that ought to return json, xml, or
21
+ switchable json<=>xml.
16
22
 
17
23
  ## Usage - Jump Start
18
24
 
@@ -75,9 +81,8 @@ main.rb:
75
81
  puts result
76
82
  ```
77
83
 
78
- 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).
79
-
80
-
84
+ If you add `reload` to any of the template classes, they will be reloaded if
85
+ they change (if templates are use in a long-running service).
81
86
 
82
87
  ## HTML Example Template
83
88
 
@@ -116,21 +121,24 @@ end
116
121
  ```
117
122
 
118
123
  Why the f**k would i use a template library for JSON when i can just create a
119
- big hash or array and create a json out of it? If you ever find yourself feeling bad or
120
- lost with your big hashes, try this out. Maybe you like it, maybe not. Who
121
- knows.
124
+ big hash or array and create a json out of it? If you ever find yourself
125
+ feeling bad or lost with your big hashes, try this out. Maybe you like it,
126
+ maybe not. Who knows.
122
127
 
123
128
  ## Installation
124
129
 
125
130
  * You need a least ruby 1.9.2
131
+ * gem install markus.rb
126
132
 
127
133
  ## Further Reading
128
134
 
129
- 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.
135
+ View the example in the ./examples subdirectory. View the tests in the ./test
136
+ subdirectory. From there you should be able to figure it out yourself. Tip:
137
+ neat combinations with heredocs are possible, e.g. to create script tags in
138
+ html.
130
139
 
131
140
  ```ruby
132
141
  script_ <<~end
133
142
  var foo = "bar";
134
143
  end
135
144
  ```
136
-
data/lib/markus.rb CHANGED
@@ -96,6 +96,10 @@ class MarkUS
96
96
  instance_exec *args, &self.class.__markus_templates[name]
97
97
  end #}}}
98
98
 
99
+ def __markus_indent(lvl=0) #{{{
100
+ self.class.__markus_indent ? "#{" " * (@__markus_level + lvl)}" : ""
101
+ end #}}}
102
+
99
103
  def method_missing(name,*args, &blk) #{{{ # :nodoc:
100
104
  if name.to_s =~ /(.*)(__)$/ || name.to_s =~ /(.*)(_)$/
101
105
  __markus_method_missing $1, *args, &blk
@@ -104,10 +108,11 @@ class MarkUS
104
108
  end
105
109
  end #}}}
106
110
  def __markus_method_missing(name,*args, &blk) #{{{ # :nodoc:
107
- if @__markus_mode == :json
108
- __markus_json name, *args, &blk
109
- else
110
- __markus_xml name, *args, &blk
111
+ case @__markus_mode
112
+ when :json
113
+ __markus_json name, *args, &blk
114
+ else
115
+ __markus_xml name, *args, &blk
111
116
  end
112
117
  end #}}}
113
118
  def __markus_xml(tname,*args) #{{{ # :nodoc:
@@ -119,54 +124,31 @@ class MarkUS
119
124
  attrs << " " + a.collect { |key,value|
120
125
  value.nil? ? nil : "#{key}=\"#{value.to_s.gsub(/"/,"&#34;")}\""
121
126
  }.compact.join(" ")
127
+ attrs = '' if attrs == ' '
122
128
  when String
123
129
  content = EscapeUtils.escape_html(a)
124
130
  when Integer
125
131
  content = a
126
132
  end
127
133
  end
128
- attrs = '' if attrs == ' '
134
+ @__markus_level += 1
129
135
  if block_given?
130
- @__markus_level += 1
131
- if self.class.__markus_indent
132
- @__markus_buffer << "#{" " * @__markus_level}<#{tname}#{attrs}>"
133
- else
134
- @__markus_buffer << "<#{tname}#{attrs}>"
135
- end
136
- unless content.nil?
137
- if self.class.__markus_indent
138
- @__markus_buffer << "#{" " * (@__markus_level+1)}#{content}"
139
- else
140
- @__markus_buffer << "#{content}"
141
- end
142
- end
136
+ @__markus_buffer << __markus_indent + "<#{tname}#{attrs}>"
137
+ @__markus_buffer << __markus_indent(1) + "#{content}" unless content.nil?
143
138
  res = yield
144
139
  @__markus_buffer << res if String === res
145
- if self.class.__markus_indent
146
- @__markus_buffer << "#{" " * @__markus_level}</#{tname}>"
147
- else
148
- @__markus_buffer << "</#{tname}>"
149
- end
150
- @__markus_level -= 1
140
+ @__markus_buffer << __markus_indent + "</#{tname}>"
151
141
  else
152
142
  if @__markus_mode == :xml && content.nil?
153
- if self.class.__markus_indent
154
- @__markus_buffer << "#{" " * (@__markus_level+1)}<#{tname}#{attrs}/>"
155
- else
156
- @__markus_buffer << "<#{tname}#{attrs}/>"
157
- end
143
+ @__markus_buffer << __markus_indent + "<#{tname}#{attrs}/>"
158
144
  else
159
- if self.class.__markus_indent
160
- @__markus_buffer << "#{" " * (@__markus_level+1)}<#{tname}#{attrs}>#{content}</#{tname}>"
161
- else
162
- @__markus_buffer << "<#{tname}#{attrs}>#{content}</#{tname}>"
163
- end
145
+ @__markus_buffer << __markus_indent + "<#{tname}#{attrs}>#{content}</#{tname}>"
164
146
  end
165
147
  end
148
+ @__markus_level -= 1
166
149
  end #}}}
167
150
  def __markus_json(tname,*args,&blk) #{{{ # :nodoc:
168
- attrs = nil
169
- content = "null"
151
+ attrs = content = nil
170
152
  args.each do |a|
171
153
  case a
172
154
  when Array
@@ -197,75 +179,55 @@ class MarkUS
197
179
  content = "\"#{a.to_s}\""
198
180
  end
199
181
  end
200
- if blk
201
- @__markus_level += 1
202
- mpsic = @__markus_parent
203
- if mpsic == :a && !tname.nil?
204
- @__markus_parent = nil
205
- if self.class.__markus_indent
206
- @__markus_buffer << "#{" " * @__markus_level}{"
207
- else
208
- @__markus_buffer << "{"
209
- end
210
- __markus_json tname, *args, &blk
211
- @__markus_buffer.last.chomp!(',')
212
- if self.class.__markus_indent
213
- @__markus_buffer << "#{" " * @__markus_level}},"
214
- else
215
- @__markus_buffer << "},"
216
- end
217
- else
218
- @__markus_parent = type = blk.parameters.length == 1 && blk.parameters[0][1] == :array ? :a : :h
219
- if self.class.__markus_indent
220
- @__markus_buffer << "#{" " * @__markus_level}#{tname.nil? ? '' : "\"#{tname}\": "}#{type == :a ? '[' : '{'}"
221
- else
222
- @__markus_buffer << "#{tname.nil? ? '' : "\"#{tname}\": "}#{type == :a ? '[' : '{'}"
223
- end
224
182
 
225
- c1 = @__markus_buffer.length
226
- res = blk.call
227
- c2 = @__markus_buffer.length
228
- if c1 == c2
229
- @__markus_buffer.last << "#{type == :a ? ']' : '}'},"
230
- else
231
- @__markus_buffer << res + ',' if type == :a && res.is_a?(String)
183
+ @__markus_level += 1
184
+ mpsic = @__markus_parent
185
+
186
+ if mpsic == :a
187
+ @__markus_buffer << __markus_indent + "{"
188
+ end
189
+
190
+ if [content, attrs, blk].compact.length > 1
191
+ @__markus_parent = nil
192
+
193
+ @__markus_buffer << __markus_indent + "\"#{tname}\": {"
194
+ __markus_json "attributes", attrs if attrs
195
+ __markus_json "value", content if content
196
+ __markus_json "content", &blk if blk
197
+ @__markus_buffer.last.chomp!(',')
198
+ @__markus_buffer << __markus_indent + "},"
199
+ else
200
+ if blk
201
+ if mpsic == :a && !tname.nil?
202
+ @__markus_parent = nil
203
+ __markus_json tname, *args, &blk
232
204
  @__markus_buffer.last.chomp!(',')
233
- if self.class.__markus_indent
234
- @__markus_buffer << "#{" " * @__markus_level}#{type == :a ? ']' : '}'},"
205
+ else
206
+ @__markus_parent = type = blk.parameters.length == 1 && blk.parameters[0][1] == :array ? :a : :h
207
+ @__markus_buffer << __markus_indent + "#{tname.nil? ? '' : "\"#{tname}\": "}#{type == :a ? '[' : '{'}"
208
+
209
+ c1 = @__markus_buffer.length
210
+ res = blk.call
211
+ c2 = @__markus_buffer.length
212
+ if c1 == c2
213
+ @__markus_buffer.last << "#{type == :a ? ']' : '}'},"
235
214
  else
236
- @__markus_buffer << "#{type == :a ? ']' : '}'},"
215
+ @__markus_buffer << res + ',' if type == :a && res.is_a?(String)
216
+ @__markus_buffer.last.chomp!(',')
217
+ @__markus_buffer << __markus_indent + "#{type == :a ? ']' : '}'},"
237
218
  end
238
219
  end
239
- end
240
- @__markus_level -= 1
241
- @__markus_parent = mpsic
242
- else
243
- if @__markus_parent == :a
244
- @__markus_level += 1
245
- if self.class.__markus_indent
246
- @__markus_buffer << "#{" " * @__markus_level}{"
247
- else
248
- @__markus_buffer << "{"
249
- end
250
- if self.class.__markus_indent
251
- @__markus_buffer << "#{" " * (@__markus_level+1)}\"#{tname}\": #{attrs || content}"
252
- else
253
- @__markus_buffer << "\"#{tname}\": #{attrs || content}"
254
- end
255
- if self.class.__markus_indent
256
- @__markus_buffer << "#{" " * @__markus_level}},"
257
- else
258
- @__markus_buffer << "},"
259
- end
260
- @__markus_level -= 1
261
- else
262
- if self.class.__markus_indent
263
- @__markus_buffer << "#{" " * (@__markus_level+1)}\"#{tname}\": #{attrs || content},"
264
- else
265
- @__markus_buffer << "\"#{tname}\": #{attrs || content},"
266
- end
267
- end
220
+ else
221
+ @__markus_buffer << __markus_indent + "\"#{tname}\": #{attrs || content},"
222
+ end
223
+ end
224
+
225
+ if mpsic == :a
226
+ @__markus_buffer << __markus_indent + "},"
268
227
  end
228
+
229
+ @__markus_level -= 1
230
+ @__markus_parent = mpsic
269
231
  end #}}}
270
232
 
271
233
  def self::inherited(subclass) #{{{ # :nodoc:
data/markus.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "markus"
3
- s.version = "4.0.15"
3
+ s.version = "4.0.16"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.license = "LGPL-3"
6
6
  s.summary = "MarkUS - Markup UnderScore. Quick n' dirty templating in the spirit of markaby."
data/test/change.mt_ CHANGED
@@ -3,7 +3,7 @@ class TestJsonChange < MarkUS
3
3
 
4
4
  template :main do
5
5
  element_! do
6
- query_ 75
6
+ query_ 76
7
7
  end
8
8
  end
9
9
  end
@@ -2,6 +2,6 @@ class ChangeIncludeCommon < MarkUS
2
2
  reload
3
3
 
4
4
  template :test do
5
- query_ 117
5
+ query_ 118
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markus
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.15
4
+ version: 4.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen eTM Mangler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-17 00:00:00.000000000 Z
11
+ date: 2016-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest