markus 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/AUTHORS +4 -0
- data/COPYING +165 -0
- data/Changelog +7 -0
- data/README.md +64 -0
- data/Rakefile +25 -0
- data/TODO +5 -0
- data/lib/markus.rb +269 -0
- data/markus.gemspec +22 -0
- data/test/change.mt_ +9 -0
- data/test/change_include.mt_ +11 -0
- data/test/change_include_common.mt_ +7 -0
- data/test/common.mt_ +13 -0
- data/test/html.mt_ +16 -0
- data/test/includes.mt_ +12 -0
- data/test/json.mt_ +44 -0
- data/test/json_arguments.mt_ +11 -0
- data/test/smartrunner.rb +5 -0
- data/test/tc_basic_html.rb +24 -0
- data/test/tc_basic_json.rb +32 -0
- data/test/tc_change.rb +19 -0
- data/test/tc_change_include.rb +20 -0
- metadata +92 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 302769335ce5674d341daff8af15d45ca013f9dd
|
|
4
|
+
data.tar.gz: 78aac46cc7603e179113bfd5790010f5e309d408
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 590ee58065246b123da720639255222168f3e9f59f12157ebd7addbed2799e9e8cb7fb2ec9445d26d19bf9923e4708bd9cc104391b5389638c85eb840d407542
|
|
7
|
+
data.tar.gz: 62e03778492adec7492e2c2148fd35ed3a771b9cd452ac21a78d3ab667e504a44ad39b431eb0055a2ff29b25313baab38c36d9eec5b969abf942aa4e135ab8e7
|
data/AUTHORS
ADDED
data/COPYING
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
data/Changelog
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Markup UnderScore
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2004-2016 Jürgen Mangler <juergen.mangler@univie.ac.at>
|
|
4
|
+
|
|
5
|
+
MarkUS is freely distributable according to the terms of the
|
|
6
|
+
GNU Lesser General Public License (see the file 'COPYING').
|
|
7
|
+
|
|
8
|
+
This program is distributed without any warranty. See the file
|
|
9
|
+
'COPYING' for details.
|
|
10
|
+
|
|
11
|
+
## Introduction
|
|
12
|
+
|
|
13
|
+
All template libraries suck. But sometimes they are useful, for building
|
|
14
|
+
quick'n dirty creation of documents. This template library will of course suck
|
|
15
|
+
as well. It is inspired by _why's markaby. It supports JSON and XML.
|
|
16
|
+
|
|
17
|
+
## HTML Example Template
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
html_ do
|
|
21
|
+
body_ :class => 'test' do
|
|
22
|
+
a_ 'Ruby', :href => 'https://ruby-lang.org'
|
|
23
|
+
span_ do
|
|
24
|
+
'Some Text'
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## JSON Example Template
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
query_ do
|
|
34
|
+
filtered_ do
|
|
35
|
+
filter_ do
|
|
36
|
+
bool_ do
|
|
37
|
+
must_ do |array|
|
|
38
|
+
nested_ do
|
|
39
|
+
path_ "contact"
|
|
40
|
+
query_ do
|
|
41
|
+
term_ do
|
|
42
|
+
element_! "contact.durchwahl", 1
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Why the f**k would i use a template library for JSON when i can just create a
|
|
54
|
+
big hash or array and create a json out of it? If you ever find yourself feeling bad or
|
|
55
|
+
lost with your big hashes, try this out. Maybe you like it, maybe not. Who
|
|
56
|
+
knows.
|
|
57
|
+
|
|
58
|
+
## Installation
|
|
59
|
+
|
|
60
|
+
* You need a least ruby 1.9.2
|
|
61
|
+
|
|
62
|
+
## Documentation
|
|
63
|
+
|
|
64
|
+
View the examples in the ./examples subdirectory.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'rake'
|
|
2
|
+
require 'rubygems/package_task'
|
|
3
|
+
require 'rake/testtask'
|
|
4
|
+
|
|
5
|
+
Rake::TestTask.new do |t|
|
|
6
|
+
t.libs << "test"
|
|
7
|
+
t.test_files = FileList['./test/tc_*.rb']
|
|
8
|
+
t.verbose = false
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
spec = eval(File.read('markus.gemspec'))
|
|
12
|
+
Gem::PackageTask.new(spec) do |pkg|
|
|
13
|
+
pkg.need_zip = true
|
|
14
|
+
pkg.need_tar = true
|
|
15
|
+
`rm pkg/* -rf`
|
|
16
|
+
`ln -sf #{pkg.name}.gem pkg/markus.gem`
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
task :push => :gem do |r|
|
|
20
|
+
`gem push pkg/markus.gem`
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
task :install => :gem do |r|
|
|
24
|
+
`sudo gem install pkg/markus.gem`
|
|
25
|
+
end
|
data/TODO
ADDED
data/lib/markus.rb
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
#
|
|
3
|
+
# This file is part of MarkUS.
|
|
4
|
+
#
|
|
5
|
+
# MarkUS is free software: you can redistribute it and/or modify it under the terms
|
|
6
|
+
# of the GNU General Public License as published by the Free Software Foundation,
|
|
7
|
+
# either version 3 of the License, or (at your option) any later version.
|
|
8
|
+
#
|
|
9
|
+
# MarkUS is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
10
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
11
|
+
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
12
|
+
#
|
|
13
|
+
# You should have received a copy of the GNU General Public License along with
|
|
14
|
+
# MarkUS (file COPYING in the main directory). If not, see
|
|
15
|
+
# <http://www.gnu.org/licenses/>.
|
|
16
|
+
|
|
17
|
+
# Markup UnderScore
|
|
18
|
+
# ---- - -
|
|
19
|
+
|
|
20
|
+
class MarkUS
|
|
21
|
+
class << self
|
|
22
|
+
attr_accessor :__markus_reload
|
|
23
|
+
attr_accessor :__markus_reload_timestamp
|
|
24
|
+
attr_accessor :__markus_file
|
|
25
|
+
attr_accessor :__markus_templates
|
|
26
|
+
attr_accessor :__markus_indent
|
|
27
|
+
attr_accessor :__markus_includes
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
attr_reader :__markus_indent, :__markus_reload
|
|
31
|
+
def __markus_indent=(value) #{{{
|
|
32
|
+
self.class.__markus_indent = value == true ? true : false
|
|
33
|
+
end #}}}
|
|
34
|
+
def __markus_reload=(value) #{{{
|
|
35
|
+
self.class.__markus_reload = value == true ? true : false
|
|
36
|
+
end #}}}
|
|
37
|
+
|
|
38
|
+
def json_!(name) #{{{
|
|
39
|
+
markus_! name, :json
|
|
40
|
+
end #}}}
|
|
41
|
+
def xml_!(name) #{{{
|
|
42
|
+
markus_! name, :xml
|
|
43
|
+
end #}}}
|
|
44
|
+
def html_!(name) #{{{
|
|
45
|
+
markus_! name, :html
|
|
46
|
+
end #}}}
|
|
47
|
+
|
|
48
|
+
def markus_!(name,type) #{{{
|
|
49
|
+
@__markus = []
|
|
50
|
+
@__markus_buffer = []
|
|
51
|
+
@__markus_level = -1
|
|
52
|
+
@__markus_parent = nil
|
|
53
|
+
|
|
54
|
+
self.class.__markus_do_reload
|
|
55
|
+
self.class.__markus_includes.each do |some|
|
|
56
|
+
if some.__markus_do_reload
|
|
57
|
+
self.class.__markus_templates.merge! some.__markus_templates
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
@__markus_mode = type
|
|
61
|
+
|
|
62
|
+
template_!(name)
|
|
63
|
+
@__markus_buffer.last.chop! if @__markus_mode == :json
|
|
64
|
+
self.class.__markus_indent ? @__markus_buffer.join("\n") : @__markus_buffer.join
|
|
65
|
+
end
|
|
66
|
+
#}}}
|
|
67
|
+
|
|
68
|
+
def element_!(name=nil, *args, &blk) #{{{
|
|
69
|
+
__markus_method_missing name, *args, &blk
|
|
70
|
+
end #}}}
|
|
71
|
+
def template_!(name) #{{{
|
|
72
|
+
instance_eval &self.class.__markus_templates[name]
|
|
73
|
+
end #}}}
|
|
74
|
+
|
|
75
|
+
def method_missing(name,*args, &blk) #{{{
|
|
76
|
+
if name.to_s =~ /(.*)(__)$/ || name.to_s =~ /(.*)(_)$/
|
|
77
|
+
__markus_method_missing $1, *args, &blk
|
|
78
|
+
else
|
|
79
|
+
super
|
|
80
|
+
end
|
|
81
|
+
end #}}}
|
|
82
|
+
def __markus_method_missing(name,*args, &blk) #{{{
|
|
83
|
+
if @__markus_mode == :json
|
|
84
|
+
__markus_json name, *args, &blk
|
|
85
|
+
else
|
|
86
|
+
__markus_xml name, *args, &blk
|
|
87
|
+
end
|
|
88
|
+
end #}}}
|
|
89
|
+
def __markus_xml(tname,*args) #{{{
|
|
90
|
+
attrs = ""
|
|
91
|
+
content = nil
|
|
92
|
+
args.each do |a|
|
|
93
|
+
case a
|
|
94
|
+
when Hash
|
|
95
|
+
attrs << " " + a.collect { |key,value|
|
|
96
|
+
value.nil? ? nil : "#{key}=\"#{value.to_s.gsub(/"/,""")}\""
|
|
97
|
+
}.compact.join(" ")
|
|
98
|
+
when String,Integer
|
|
99
|
+
content = a
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
attrs = '' if attrs == ' '
|
|
103
|
+
if block_given?
|
|
104
|
+
@__markus_level += 1
|
|
105
|
+
if self.class.__markus_indent
|
|
106
|
+
@__markus_buffer << "#{" " * @__markus_level}<#{tname}#{attrs}>"
|
|
107
|
+
else
|
|
108
|
+
@__markus_buffer << "<#{tname}#{attrs}>"
|
|
109
|
+
end
|
|
110
|
+
unless content.nil?
|
|
111
|
+
if self.class.__markus_indent
|
|
112
|
+
@__markus_buffer << "#{" " * (@__markus_level+1)}#{content}"
|
|
113
|
+
else
|
|
114
|
+
@__markus_buffer << "#{content}"
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
res = yield
|
|
118
|
+
@__markus_buffer << res if String === res
|
|
119
|
+
if self.class.__markus_indent
|
|
120
|
+
@__markus_buffer << "#{" " * @__markus_level}</#{tname}>"
|
|
121
|
+
else
|
|
122
|
+
@__markus_buffer << "</#{tname}>"
|
|
123
|
+
end
|
|
124
|
+
@__markus_level -= 1
|
|
125
|
+
else
|
|
126
|
+
if @__markus_mode == :xml && content.nil?
|
|
127
|
+
if self.class.__markus_indent
|
|
128
|
+
@__markus_buffer << "#{" " * (@__markus_level+1)}<#{tname}#{attrs}/>"
|
|
129
|
+
else
|
|
130
|
+
@__markus_buffer << "<#{tname}#{attrs}/>"
|
|
131
|
+
end
|
|
132
|
+
else
|
|
133
|
+
if self.class.__markus_indent
|
|
134
|
+
@__markus_buffer << "#{" " * (@__markus_level+1)}<#{tname}#{attrs}>#{content}</#{tname}>"
|
|
135
|
+
else
|
|
136
|
+
@__markus_buffer << "<#{tname}#{attrs}>#{content}</#{tname}>"
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end #}}}
|
|
141
|
+
def __markus_json(tname,*args,&blk) #{{{
|
|
142
|
+
attrs = nil
|
|
143
|
+
content = "null"
|
|
144
|
+
args.each do |a|
|
|
145
|
+
case a
|
|
146
|
+
when Array
|
|
147
|
+
attrs = "[ " + a.collect { |value|
|
|
148
|
+
case value
|
|
149
|
+
when Integer, Float
|
|
150
|
+
value.nil? ? nil : value.to_s
|
|
151
|
+
else
|
|
152
|
+
value.nil? ? nil : "\"#{value.to_s.gsub(/"/,'\\\"')}\""
|
|
153
|
+
end
|
|
154
|
+
}.compact.join(", ").strip + " ]"
|
|
155
|
+
attrs = nil if attrs == "[ ]"
|
|
156
|
+
when Hash
|
|
157
|
+
attrs = "{ " + a.collect { |key,value|
|
|
158
|
+
case value
|
|
159
|
+
when Integer, Float
|
|
160
|
+
value.nil? ? nil : "\"#{key}\": #{value}"
|
|
161
|
+
else
|
|
162
|
+
value.nil? ? nil : "\"#{key}\": \"#{value.to_s.gsub(/"/,'\\\"')}\""
|
|
163
|
+
end
|
|
164
|
+
}.compact.join(", ").strip + " }"
|
|
165
|
+
attrs = nil if attrs == "{ }"
|
|
166
|
+
when String
|
|
167
|
+
content = "\"#{a.gsub(/"/,'\\\"')}\""
|
|
168
|
+
when Integer, Float
|
|
169
|
+
content = a
|
|
170
|
+
else
|
|
171
|
+
content = "\"#{a.to_s}\""
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
if blk
|
|
175
|
+
@__markus_level += 1
|
|
176
|
+
mpsic = @__markus_parent
|
|
177
|
+
if mpsic == :a
|
|
178
|
+
@__markus_parent = nil
|
|
179
|
+
if self.class.__markus_indent
|
|
180
|
+
@__markus_buffer << "#{" " * @__markus_level}{"
|
|
181
|
+
else
|
|
182
|
+
@__markus_buffer << "{"
|
|
183
|
+
end
|
|
184
|
+
__markus_json tname, *args, &blk
|
|
185
|
+
@__markus_buffer.last.chop!
|
|
186
|
+
if self.class.__markus_indent
|
|
187
|
+
@__markus_buffer << "#{" " * @__markus_level}},"
|
|
188
|
+
else
|
|
189
|
+
@__markus_buffer << "},"
|
|
190
|
+
end
|
|
191
|
+
else
|
|
192
|
+
@__markus_parent = type = blk.parameters.length == 1 && blk.parameters[0][1] == :array ? :a : :h
|
|
193
|
+
if self.class.__markus_indent
|
|
194
|
+
@__markus_buffer << "#{" " * @__markus_level}#{tname.nil? ? '' : "\"#{tname}\": "}#{type == :a ? '[' : '{'}"
|
|
195
|
+
else
|
|
196
|
+
@__markus_buffer << "#{tname.nil? ? '' : "\"#{tname}\": "}#{type == :a ? '[' : '{'}"
|
|
197
|
+
end
|
|
198
|
+
res = blk.call
|
|
199
|
+
@__markus_buffer << res + ',' if type == :a && res.is_a?(String)
|
|
200
|
+
@__markus_buffer.last.chop!
|
|
201
|
+
if self.class.__markus_indent
|
|
202
|
+
@__markus_buffer << "#{" " * @__markus_level}#{type == :a ? ']' : '}'},"
|
|
203
|
+
else
|
|
204
|
+
@__markus_buffer << "#{type == :a ? ']' : '}'},"
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
@__markus_level -= 1
|
|
208
|
+
@__markus_parent = mpsic
|
|
209
|
+
else
|
|
210
|
+
if self.class.__markus_indent
|
|
211
|
+
@__markus_buffer << "#{" " * (@__markus_level+1)}\"#{tname}\": #{attrs || content},"
|
|
212
|
+
else
|
|
213
|
+
@__markus_buffer << "\"#{tname}\": #{attrs || content},"
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
end #}}}
|
|
217
|
+
|
|
218
|
+
def self::inherited(subclass) #{{{
|
|
219
|
+
subclass.instance_eval do |i|
|
|
220
|
+
# This array contains strings like "/path/to/a.rb:3:in `instance_eval'".
|
|
221
|
+
strings_ary = caller
|
|
222
|
+
|
|
223
|
+
# We look for the last string containing "<top (required)>".
|
|
224
|
+
# only works in > 1.9
|
|
225
|
+
val = "<top (required)>"
|
|
226
|
+
until require_index = strings_ary.index {|x| x.include?(val) }
|
|
227
|
+
val = "<main>"
|
|
228
|
+
end
|
|
229
|
+
require_string = strings_ary[require_index]
|
|
230
|
+
filepath = File.expand_path(require_string[/^(.*):\d+:in/, 1])
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
# We use a regex to extract the filepath from require_string. Other defaults.
|
|
234
|
+
self.__markus_reload = false
|
|
235
|
+
self.__markus_reload_timestamp = nil
|
|
236
|
+
self.__markus_file = filepath
|
|
237
|
+
self.__markus_templates = {}
|
|
238
|
+
self.__markus_indent = false
|
|
239
|
+
self.__markus_includes = []
|
|
240
|
+
end
|
|
241
|
+
end #}}}
|
|
242
|
+
|
|
243
|
+
def self::reload #{{{
|
|
244
|
+
self.__markus_reload = true
|
|
245
|
+
self.__markus_reload_timestamp = File.stat(self.__markus_file).mtime
|
|
246
|
+
end #}}}
|
|
247
|
+
def self:: __markus_do_reload #{{{
|
|
248
|
+
if self.__markus_reload && self.__markus_reload_timestamp
|
|
249
|
+
if File.stat(self.__markus_file).mtime > self.__markus_reload_timestamp
|
|
250
|
+
load self.__markus_file
|
|
251
|
+
return true
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
false
|
|
255
|
+
end #}}}
|
|
256
|
+
|
|
257
|
+
def self::template(name,&p) #{{{
|
|
258
|
+
self.__markus_templates ||= {}
|
|
259
|
+
self.__markus_templates[name] = p
|
|
260
|
+
end #}}}
|
|
261
|
+
def self::indent #{{{
|
|
262
|
+
self.__markus_indent = true
|
|
263
|
+
end #}}}
|
|
264
|
+
|
|
265
|
+
def self::templates(some)
|
|
266
|
+
self.__markus_includes << some
|
|
267
|
+
self.__markus_templates.merge! some.__markus_templates
|
|
268
|
+
end
|
|
269
|
+
end
|
data/markus.gemspec
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
s.name = "markus"
|
|
3
|
+
s.version = "4.0.1"
|
|
4
|
+
s.platform = Gem::Platform::RUBY
|
|
5
|
+
s.license = "LGPL-3"
|
|
6
|
+
s.summary = "MarkUS - Markup UnderScore. Quick n' dirty templating in the spirit of markaby."
|
|
7
|
+
|
|
8
|
+
s.description = "see http://cpee.org"
|
|
9
|
+
|
|
10
|
+
s.files = Dir['{example/**/*,lib/*}'] + %w(COPYING Changelog Rakefile markus.gemspec README.md AUTHORS TODO)
|
|
11
|
+
s.require_path = 'lib'
|
|
12
|
+
s.extra_rdoc_files = ['README.md']
|
|
13
|
+
s.test_files = Dir['{test/smartrunner.rb,test/tc_*.rb,test/*.mt_}']
|
|
14
|
+
|
|
15
|
+
s.required_ruby_version = '>=1.9.3'
|
|
16
|
+
|
|
17
|
+
s.authors = ['Juergen eTM Mangler']
|
|
18
|
+
s.email = 'juergen.mangler@gmail.com'
|
|
19
|
+
s.homepage = 'https://github.com/etm/markus.rb'
|
|
20
|
+
|
|
21
|
+
s.add_runtime_dependency 'minitest', '~> 5.8'
|
|
22
|
+
end
|
data/test/change.mt_
ADDED
data/test/common.mt_
ADDED
data/test/html.mt_
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class TestHTML < MarkUS
|
|
2
|
+
indent
|
|
3
|
+
|
|
4
|
+
template :main do
|
|
5
|
+
html_ do
|
|
6
|
+
body_ :class => 'test' do
|
|
7
|
+
a_ 'Ruby', :href => 'https://ruby-lang.org'
|
|
8
|
+
span_ do
|
|
9
|
+
'Some Text'
|
|
10
|
+
end
|
|
11
|
+
input_ :type => 'text', :value => 'hello world'
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
data/test/includes.mt_
ADDED
data/test/json.mt_
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
class TestJSON < MarkUS
|
|
2
|
+
indent
|
|
3
|
+
|
|
4
|
+
template :common do
|
|
5
|
+
from_ 1
|
|
6
|
+
size_ 6
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
template :main do
|
|
10
|
+
template_! :common
|
|
11
|
+
query_ do
|
|
12
|
+
filtered_ do
|
|
13
|
+
filter_ do
|
|
14
|
+
bool_ do
|
|
15
|
+
must_ do |array|
|
|
16
|
+
bool_ do
|
|
17
|
+
should_ do |array|
|
|
18
|
+
nested_ do
|
|
19
|
+
path_ "contact"
|
|
20
|
+
query_ do
|
|
21
|
+
term_ do
|
|
22
|
+
element_! "contact.durchwahl", 1
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
nested_ do
|
|
28
|
+
path_ "contact"
|
|
29
|
+
query_ do
|
|
30
|
+
term_ do
|
|
31
|
+
element_! "contact.durchwahl", "aaa"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
data/test/smartrunner.rb
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/smartrunner')
|
|
2
|
+
load File.expand_path(File.dirname(__FILE__) + '/html.mt_')
|
|
3
|
+
|
|
4
|
+
class TestBasicHTML < Minitest::Test
|
|
5
|
+
|
|
6
|
+
def test_xml
|
|
7
|
+
s = TestHTML.new
|
|
8
|
+
s.__markus_indent = true
|
|
9
|
+
assert s.xml_!(:main) == "<html>\n <body class=\"test\">\n <a href=\"https://ruby-lang.org\">Ruby</a>\n <span>\nSome Text\n </span>\n <input type=\"text\" value=\"hello world\"/>\n </body>\n</html>"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_html
|
|
13
|
+
s = TestHTML.new
|
|
14
|
+
s.__markus_indent = true
|
|
15
|
+
assert s.html_!(:main) == "<html>\n <body class=\"test\">\n <a href=\"https://ruby-lang.org\">Ruby</a>\n <span>\nSome Text\n </span>\n <input type=\"text\" value=\"hello world\"></input>\n </body>\n</html>"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_xml_noindent
|
|
19
|
+
s = TestHTML.new
|
|
20
|
+
s.__markus_indent = false
|
|
21
|
+
assert s.xml_!(:main) == "<html><body class=\"test\"><a href=\"https://ruby-lang.org\">Ruby</a><span>Some Text</span><input type=\"text\" value=\"hello world\"/></body></html>"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/smartrunner')
|
|
2
|
+
load File.expand_path(File.dirname(__FILE__) + '/json.mt_')
|
|
3
|
+
load File.expand_path(File.dirname(__FILE__) + '/includes.mt_')
|
|
4
|
+
load File.expand_path(File.dirname(__FILE__) + '/json_arguments.mt_')
|
|
5
|
+
|
|
6
|
+
class TestBasicJSON < Minitest::Test
|
|
7
|
+
|
|
8
|
+
def test_json
|
|
9
|
+
s = TestJSON.new
|
|
10
|
+
s.__markus_indent = true
|
|
11
|
+
assert s.json_!(:main) == "\"from\": 1,\n\"size\": 6,\n\"query\": {\n \"filtered\": {\n \"filter\": {\n \"bool\": {\n \"must\": [\n {\n \"bool\": {\n \"should\": [\n {\n \"nested\": {\n \"path\": \"contact\",\n \"query\": {\n \"term\": {\n \"contact.durchwahl\": 1\n }\n }\n }\n },\n {\n \"nested\": {\n \"path\": \"contact\",\n \"query\": {\n \"term\": {\n \"contact.durchwahl\": \"aaa\"\n }\n }\n }\n }\n ]\n }\n }\n ]\n }\n }\n }\n}"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_json_noindent
|
|
15
|
+
s = TestJSON.new
|
|
16
|
+
s.__markus_indent = false
|
|
17
|
+
assert s.json_!(:main) == "\"from\": 1,\"size\": 6,\"query\": {\"filtered\": {\"filter\": {\"bool\": {\"must\": [{\"bool\": {\"should\": [{\"nested\": {\"path\": \"contact\",\"query\": {\"term\": {\"contact.durchwahl\": 1}}}},{\"nested\": {\"path\": \"contact\",\"query\": {\"term\": {\"contact.durchwahl\": \"aaa\"}}}}]}}]}}}}"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_json_arguments
|
|
21
|
+
s = TestJSONArguments.new
|
|
22
|
+
assert s.json_!(:array) == "\"query\": [ 2, 3, \"world\" ]"
|
|
23
|
+
assert s.json_!(:hash) == "\"query\": { \"a\": 2, \"b\": \"hello\" }"
|
|
24
|
+
assert s.json_!(:date) =~ /"query": "\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \+\d{4}\"/
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_json_includes
|
|
28
|
+
s = TestIncludes.new
|
|
29
|
+
assert s.json_!(:main) == "\"query\": [ 2, 3, \"world\" ],\n\"query\": { \"a\": 2, \"b\": \"hello\" }"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
data/test/tc_change.rb
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/smartrunner')
|
|
2
|
+
|
|
3
|
+
$fname = File.expand_path(File.dirname(__FILE__) + '/change.mt_')
|
|
4
|
+
load $fname
|
|
5
|
+
|
|
6
|
+
class TestChange < Minitest::Test
|
|
7
|
+
|
|
8
|
+
def test_json
|
|
9
|
+
s = TestJsonChange.new
|
|
10
|
+
newnum = nil
|
|
11
|
+
newcontent = File.read($fname).gsub(/query_ (\d+)/) do
|
|
12
|
+
newnum = ($1.to_i + 1).to_s
|
|
13
|
+
"query_ " + newnum
|
|
14
|
+
end
|
|
15
|
+
File.write($fname,newcontent)
|
|
16
|
+
assert s.json_!(:main) == %Q({"query": #{newnum}})
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/smartrunner')
|
|
2
|
+
load File.expand_path(File.dirname(__FILE__) + '/change_include.mt_')
|
|
3
|
+
|
|
4
|
+
$fname = File.expand_path(File.dirname(__FILE__) + '/change_include_common.mt_')
|
|
5
|
+
|
|
6
|
+
class TestChangeInclude < Minitest::Test
|
|
7
|
+
|
|
8
|
+
def test_json
|
|
9
|
+
s = ChangeInclude.new
|
|
10
|
+
newnum = nil
|
|
11
|
+
newcontent = File.read($fname).gsub(/query_ (\d+)/) do
|
|
12
|
+
newnum = ($1.to_i + 1).to_s
|
|
13
|
+
"query_ " + newnum
|
|
14
|
+
end
|
|
15
|
+
File.write($fname,newcontent)
|
|
16
|
+
|
|
17
|
+
assert s.json_!(:main) == %Q("query": #{newnum})
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: markus
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 4.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Juergen eTM Mangler
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-01-09 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: minitest
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '5.8'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '5.8'
|
|
27
|
+
description: see http://cpee.org
|
|
28
|
+
email: juergen.mangler@gmail.com
|
|
29
|
+
executables: []
|
|
30
|
+
extensions: []
|
|
31
|
+
extra_rdoc_files:
|
|
32
|
+
- README.md
|
|
33
|
+
files:
|
|
34
|
+
- AUTHORS
|
|
35
|
+
- COPYING
|
|
36
|
+
- Changelog
|
|
37
|
+
- README.md
|
|
38
|
+
- Rakefile
|
|
39
|
+
- TODO
|
|
40
|
+
- lib/markus.rb
|
|
41
|
+
- markus.gemspec
|
|
42
|
+
- test/change.mt_
|
|
43
|
+
- test/change_include.mt_
|
|
44
|
+
- test/change_include_common.mt_
|
|
45
|
+
- test/common.mt_
|
|
46
|
+
- test/html.mt_
|
|
47
|
+
- test/includes.mt_
|
|
48
|
+
- test/json.mt_
|
|
49
|
+
- test/json_arguments.mt_
|
|
50
|
+
- test/smartrunner.rb
|
|
51
|
+
- test/tc_basic_html.rb
|
|
52
|
+
- test/tc_basic_json.rb
|
|
53
|
+
- test/tc_change.rb
|
|
54
|
+
- test/tc_change_include.rb
|
|
55
|
+
homepage: https://github.com/etm/markus.rb
|
|
56
|
+
licenses:
|
|
57
|
+
- LGPL-3
|
|
58
|
+
metadata: {}
|
|
59
|
+
post_install_message:
|
|
60
|
+
rdoc_options: []
|
|
61
|
+
require_paths:
|
|
62
|
+
- lib
|
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: 1.9.3
|
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
|
+
requirements:
|
|
70
|
+
- - ">="
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
version: '0'
|
|
73
|
+
requirements: []
|
|
74
|
+
rubyforge_project:
|
|
75
|
+
rubygems_version: 2.4.8
|
|
76
|
+
signing_key:
|
|
77
|
+
specification_version: 4
|
|
78
|
+
summary: MarkUS - Markup UnderScore. Quick n' dirty templating in the spirit of markaby.
|
|
79
|
+
test_files:
|
|
80
|
+
- test/smartrunner.rb
|
|
81
|
+
- test/tc_change.rb
|
|
82
|
+
- test/tc_basic_json.rb
|
|
83
|
+
- test/tc_basic_html.rb
|
|
84
|
+
- test/tc_change_include.rb
|
|
85
|
+
- test/includes.mt_
|
|
86
|
+
- test/json_arguments.mt_
|
|
87
|
+
- test/change_include.mt_
|
|
88
|
+
- test/change_include_common.mt_
|
|
89
|
+
- test/html.mt_
|
|
90
|
+
- test/json.mt_
|
|
91
|
+
- test/change.mt_
|
|
92
|
+
- test/common.mt_
|