deklarativna 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rvmrc +46 -0
- data/GPL_v2 +252 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +24 -0
- data/LICENSE +19 -0
- data/README.md +111 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/deklarativna.gemspec +72 -0
- data/examples/class_based_example.rb +20 -0
- data/examples/dinamic_sinatra_example.rb +28 -0
- data/examples/simple_example.rb +20 -0
- data/examples/static_sinatra_example.rb +72 -0
- data/lib/deklarativna.rb +88 -0
- data/lib/deklarativna_core.rb +77 -0
- data/lib/deklarativna_utils.rb +28 -0
- data/run_test.sh +7 -0
- data/test/helper.rb +18 -0
- data/test/test_deklarativna.rb +130 -0
- data/test/test_deklarativna_core.rb +82 -0
- metadata +161 -0
data/.document
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
|
7
|
+
environment_id="ruby-1.9.2@deklarativna"
|
8
|
+
|
9
|
+
#
|
10
|
+
# First we attempt to load the desired environment directly from the environment
|
11
|
+
# file. This is very fast and efficicent compared to running through the entire
|
12
|
+
# CLI and selector. If you want feedback on which environment was used then
|
13
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
14
|
+
#
|
15
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
16
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]] ; then
|
17
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
18
|
+
else
|
19
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
20
|
+
rvm --create use "$environment_id"
|
21
|
+
fi
|
22
|
+
|
23
|
+
#
|
24
|
+
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
|
25
|
+
# it be automatically loaded. Uncomment the following and adjust the filename if
|
26
|
+
# necessary.
|
27
|
+
#
|
28
|
+
# filename=".gems"
|
29
|
+
# if [[ -s "$filename" ]] ; then
|
30
|
+
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
|
31
|
+
# fi
|
32
|
+
|
33
|
+
#
|
34
|
+
# If you use bundler and would like to run bundle each time you enter the
|
35
|
+
# directory, you can uncomment the following code.
|
36
|
+
#
|
37
|
+
# # Ensure that Bundler is installed. Install it if it is not.
|
38
|
+
# if ! command -v bundle >/dev/null; then
|
39
|
+
# printf "The rubygem 'bundler' is not installed. Installing it now.\n"
|
40
|
+
# gem install bundler
|
41
|
+
# fi
|
42
|
+
#
|
43
|
+
# # Bundle while reducing excess noise.
|
44
|
+
# printf "Bundling your gems. This may take a few minutes on a fresh clone.\n"
|
45
|
+
# bundle | grep -v '^Using ' | grep -v ' is complete' | sed '/^$/d'
|
46
|
+
#
|
data/GPL_v2
ADDED
@@ -0,0 +1,252 @@
|
|
1
|
+
GNU GENERAL PUBLIC LICENSE
|
2
|
+
|
3
|
+
Version 2, June 1991
|
4
|
+
|
5
|
+
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
6
|
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
7
|
+
|
8
|
+
Everyone is permitted to copy and distribute verbatim copies
|
9
|
+
of this license document, but changing it is not allowed.
|
10
|
+
|
11
|
+
Preamble
|
12
|
+
|
13
|
+
The licenses for most software are designed to take away your freedom to share
|
14
|
+
and change it. By contrast, the GNU General Public License is intended to
|
15
|
+
guarantee your freedom to share and change free software--to make sure the
|
16
|
+
software is free for all its users. This General Public License applies to most
|
17
|
+
of the Free Software Foundation's software and to any other program whose
|
18
|
+
authors commit to using it. (Some other Free Software Foundation software is
|
19
|
+
covered by the GNU Lesser General Public License instead.) You can apply it to
|
20
|
+
your programs, too.
|
21
|
+
|
22
|
+
When we speak of free software, we are referring to freedom, not price.
|
23
|
+
Our General Public Licenses are designed to make sure that you have the freedom
|
24
|
+
to distribute copies of free software (and charge for this service if you
|
25
|
+
wish), that you receive source code or can get it if you want it, that you can
|
26
|
+
change the software or use pieces of it in new free programs; and that you know
|
27
|
+
you can do these things.
|
28
|
+
|
29
|
+
To protect your rights, we need to make restrictions that forbid anyone to deny
|
30
|
+
you these rights or to ask you to surrender the rights. These restrictions
|
31
|
+
translate to certain responsibilities for you if you distribute copies of the
|
32
|
+
software, or if you modify it.
|
33
|
+
|
34
|
+
For example, if you distribute copies of such a program, whether gratis or for
|
35
|
+
a fee, you must give the recipients all the rights that you have. You must make
|
36
|
+
sure that they, too, receive or can get the source code. And you must show them
|
37
|
+
these terms so they know their rights.
|
38
|
+
|
39
|
+
We protect your rights with two steps: (1) copyright the software, and (2)
|
40
|
+
offer you this license which gives you legal permission to copy, distribute
|
41
|
+
and/or modify the software.
|
42
|
+
|
43
|
+
Also, for each author's protection and ours, we want to make certain that
|
44
|
+
everyone understands that there is no warranty for this free software. If the
|
45
|
+
software is modified by someone else and passed on, we want its recipients to
|
46
|
+
know that what they have is not the original, so that any problems introduced
|
47
|
+
by others will not reflect on the original authors' reputations.
|
48
|
+
|
49
|
+
Finally, any free program is threatened constantly by software patents.
|
50
|
+
We wish to avoid the danger that redistributors of a free program will
|
51
|
+
individually obtain patent licenses, in effect making the program proprietary.
|
52
|
+
To prevent this, we have made it clear that any patent must be licensed for
|
53
|
+
everyone's free use or not licensed at all.
|
54
|
+
|
55
|
+
The precise terms and conditions for copying, distribution and modification
|
56
|
+
follow.
|
57
|
+
|
58
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
59
|
+
|
60
|
+
0. This License applies to any program or other work which contains a notice
|
61
|
+
placed by the copyright holder saying it may be distributed under the terms of
|
62
|
+
this General Public License. The "Program", below, refers to any such program
|
63
|
+
or work, and a "work based on the Program" means either the Program or any
|
64
|
+
derivative work under copyright law: that is to say, a work containing the
|
65
|
+
Program or a portion of it, either verbatim or with modifications and/or
|
66
|
+
translated into another language. (Hereinafter, translation is included without
|
67
|
+
limitation in the term "modification".) Each licensee is addressed as "you".
|
68
|
+
|
69
|
+
Activities other than copying, distribution and modification are not covered by
|
70
|
+
this License; they are outside its scope. The act of running the Program is not
|
71
|
+
restricted, and the output from the Program is covered only if its contents
|
72
|
+
constitute a work based on the Program (independent of having been made by
|
73
|
+
running the Program). Whether that is true depends on what the Program does.
|
74
|
+
|
75
|
+
1. You may copy and distribute verbatim copies of the Program's source code as
|
76
|
+
you receive it, in any medium, provided that you conspicuously and
|
77
|
+
appropriately publish on each copy an appropriate copyright notice and
|
78
|
+
disclaimer of warranty; keep intact all the notices that refer to this License
|
79
|
+
and to the absence of any warranty; and give any other recipients of the
|
80
|
+
Program a copy of this License along with the Program.
|
81
|
+
|
82
|
+
You may charge a fee for the physical act of transferring a copy, and you may
|
83
|
+
at your option offer warranty protection in exchange for a fee.
|
84
|
+
|
85
|
+
2. You may modify your copy or copies of the Program or any portion of it, thus
|
86
|
+
forming a work based on the Program, and copy and distribute such modifications
|
87
|
+
or work under the terms of Section 1 above, provided that you also meet all of
|
88
|
+
these conditions:
|
89
|
+
|
90
|
+
a) You must cause the modified files to carry prominent notices stating that
|
91
|
+
you changed the files and the date of any change.
|
92
|
+
b) You must cause any work that you distribute or publish, that in whole or in
|
93
|
+
part contains or is derived from the Program or any part thereof, to be
|
94
|
+
licensed as a whole at no charge to all third parties under the terms of this
|
95
|
+
License.
|
96
|
+
c) If the modified program normally reads commands interactively when run, you
|
97
|
+
must cause it, when started running for such interactive use in the most
|
98
|
+
ordinary way, to print or display an announcement including an appropriate
|
99
|
+
copyright notice and a notice that there is no warranty (or else, saying that
|
100
|
+
you provide a warranty) and that users may redistribute the program under these
|
101
|
+
conditions, and telling the user how to view a copy of this License.
|
102
|
+
(Exception: if the Program itself is interactive but does not normally print
|
103
|
+
such an announcement, your work based on the Program is not required to print
|
104
|
+
an announcement.)
|
105
|
+
These requirements apply to the modified work as a whole. If identifiable
|
106
|
+
sections of that work are not derived from the Program, and can be reasonably
|
107
|
+
considered independent and separate works in themselves, then this License,
|
108
|
+
and its terms, do not apply to those sections when you distribute them as
|
109
|
+
separate works. But when you distribute the same sections as part of a whole
|
110
|
+
which is a work based on the Program, the distribution of the whole must be on
|
111
|
+
the terms of this License, whose permissions for other licensees extend to the
|
112
|
+
entire whole, and thus to each and every part regardless of who wrote it.
|
113
|
+
|
114
|
+
Thus, it is not the intent of this section to claim rights or contest your
|
115
|
+
rights to work written entirely by you; rather, the intent is to exercise the
|
116
|
+
right to control the distribution of derivative or collective works based on
|
117
|
+
the Program.
|
118
|
+
|
119
|
+
In addition, mere aggregation of another work not based on the Program with the
|
120
|
+
Program (or with a work based on the Program) on a volume of a storage or
|
121
|
+
distribution medium does not bring the other work under the scope
|
122
|
+
of this License.
|
123
|
+
|
124
|
+
3. You may copy and distribute the Program (or a work based on it,
|
125
|
+
under Section 2) in object code or executable form under the terms of
|
126
|
+
Sections 1 and 2 above provided that you also do one of the following:
|
127
|
+
|
128
|
+
a) Accompany it with the complete corresponding machine-readable source code,
|
129
|
+
which must be distributed under the terms of Sections 1 and 2 above on a medium
|
130
|
+
customarily used for software interchange; or,
|
131
|
+
b) Accompany it with a written offer, valid for at least three years, to give
|
132
|
+
any third party, for a charge no more than your cost of physically performing
|
133
|
+
source distribution, a complete machine-readable copy of the corresponding
|
134
|
+
source code, to be distributed under the terms of Sections 1 and 2 above on a
|
135
|
+
medium customarily used for software interchange; or,
|
136
|
+
c) Accompany it with the information you received as to the offer to distribute
|
137
|
+
corresponding source code. (This alternative is allowed only for noncommercial
|
138
|
+
distribution and only if you received the program in object code or executable
|
139
|
+
form with such an offer, in accord with Subsection b above.)
|
140
|
+
The source code for a work means the preferred form of the work for making
|
141
|
+
modifications to it. For an executable work, complete source code means all the
|
142
|
+
source code for all modules it contains, plus any associated interface
|
143
|
+
definition files, plus the scripts used to control compilation and installation
|
144
|
+
of the executable. However, as a special exception, the source code distributed
|
145
|
+
need not include anything that is normally distributed (in either source or
|
146
|
+
binary form) with the major components (compiler, kernel, and so on) of the
|
147
|
+
operating system on which the executable runs, unless that component itself
|
148
|
+
accompanies the executable.
|
149
|
+
|
150
|
+
If distribution of executable or object code is made by offering access to copy
|
151
|
+
from a designated place, then offering equivalent access to copy the source
|
152
|
+
code from the same place counts as distribution of the source code, even though
|
153
|
+
third parties are not compelled to copy the source along with the object code.
|
154
|
+
|
155
|
+
4. You may not copy, modify, sublicense, or distribute the Program except as
|
156
|
+
expressly provided under this License. Any attempt otherwise to copy, modify,
|
157
|
+
sublicense or distribute the Program is void, and will automatically terminate
|
158
|
+
your rights under this License. However, parties who have received copies, or
|
159
|
+
rights, from you under this License will not have their licenses terminated so
|
160
|
+
long as such parties remain in full compliance.
|
161
|
+
|
162
|
+
5. You are not required to accept this License, since you have not signed it.
|
163
|
+
However, nothing else grants you permission to modify or distribute the Program
|
164
|
+
or its derivative works. These actions are prohibited by law if you do not
|
165
|
+
accept this License. Therefore, by modifying or distributing the Program (or
|
166
|
+
any work based on the Program), you indicate your acceptance of this License
|
167
|
+
to do so, and all its terms and conditions for copying, distributing
|
168
|
+
or modifying the Program or works based on it.
|
169
|
+
|
170
|
+
6. Each time you redistribute the Program (or any work based on the Program),
|
171
|
+
the recipient automatically receives a license from the original licensor to
|
172
|
+
copy, distribute or modify the Program subject to these terms and conditions.
|
173
|
+
You may not impose any further restrictions on the recipients' exercise of the
|
174
|
+
rights granted herein. You are not responsible for enforcing compliance by
|
175
|
+
third parties to this License.
|
176
|
+
|
177
|
+
7. If, as a consequence of a court judgment or allegation of patent
|
178
|
+
infringement or for any other reason (not limited to patent issues),
|
179
|
+
conditions are imposed on you (whether by court order, agreement or otherwise)
|
180
|
+
that contradict the conditions of this License, they do not excuse you from
|
181
|
+
the conditions of this License. If you cannot distribute so as to satisfy
|
182
|
+
simultaneously your obligations under this License and any other pertinent
|
183
|
+
obligations, then as a consequence you may not distribute the Program at all.
|
184
|
+
For example, if a patent license would not permit royalty-free redistribution
|
185
|
+
of the Program by all those who receive copies directly or indirectly through
|
186
|
+
you, then the only way you could satisfy both it and this License would be to
|
187
|
+
refrain entirely from distribution of the Program.
|
188
|
+
|
189
|
+
If any portion of this section is held invalid or unenforceable under any
|
190
|
+
particular circumstance, the balance of the section is intended to apply and
|
191
|
+
the section as a whole is intended to apply in other circumstances.
|
192
|
+
|
193
|
+
It is not the purpose of this section to induce you to infringe any patents or
|
194
|
+
other property right claims or to contest validity of any such claims; this
|
195
|
+
section has the sole purpose of protecting the integrity of the free software
|
196
|
+
distribution system, which is implemented by public license practices. Many
|
197
|
+
people have made generous contributions to the wide range of software
|
198
|
+
distributed through that system in reliance on consistent application of that
|
199
|
+
system; it is up to the author/donor to decide if he or she is willing to
|
200
|
+
distribute software through any other system and a licensee cannot
|
201
|
+
impose that choice.
|
202
|
+
|
203
|
+
This section is intended to make thoroughly clear what is believed to be a
|
204
|
+
consequence of the rest of this License.
|
205
|
+
|
206
|
+
8. If the distribution and/or use of the Program is restricted in certain
|
207
|
+
countries either by patents or by copyrighted interfaces, the original
|
208
|
+
copyright holder who places the Program under this License may add an explicit
|
209
|
+
geographical distribution limitation excluding those countries, so that
|
210
|
+
distribution is permitted only in or among countries not thus excluded.
|
211
|
+
In such case, this License incorporates the limitation as if written
|
212
|
+
in the body of this License.
|
213
|
+
|
214
|
+
9. The Free Software Foundation may publish revised and/or new versions of the
|
215
|
+
General Public License from time to time. Such new versions will be similar in
|
216
|
+
spirit to the present version, but may differ in detail to address new
|
217
|
+
problems or concerns.
|
218
|
+
|
219
|
+
Each version is given a distinguishing version number. If the Program specifies
|
220
|
+
a version number of this License which applies to it and "any later version",
|
221
|
+
you have the option of following the terms and conditions either of that
|
222
|
+
version or of any later version published by the Free Software Foundation.
|
223
|
+
If the Program does not specify a version number of this License,
|
224
|
+
you may choose any version ever published by the Free Software Foundation.
|
225
|
+
|
226
|
+
10. If you wish to incorporate parts of the Program into other free programs
|
227
|
+
whose distribution conditions are different, write to the author to ask for
|
228
|
+
permission. For software which is copyrighted by the Free Software Foundation,
|
229
|
+
write to the Free Software Foundation; we sometimes make exceptions for this.
|
230
|
+
Our decision will be guided by the two goals of preserving the free status of
|
231
|
+
all derivatives of our free software and of promoting the sharing and reuse of
|
232
|
+
software generally.
|
233
|
+
|
234
|
+
NO WARRANTY
|
235
|
+
|
236
|
+
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR
|
237
|
+
THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE
|
238
|
+
STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE
|
239
|
+
PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
|
240
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
241
|
+
FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
|
242
|
+
PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE,
|
243
|
+
YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
244
|
+
|
245
|
+
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
|
246
|
+
ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE
|
247
|
+
PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
248
|
+
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
|
249
|
+
INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA
|
250
|
+
BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
251
|
+
FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER
|
252
|
+
OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
gem "launchy"
|
6
|
+
|
7
|
+
# Add dependencies to develop your gem here.
|
8
|
+
# Include everything needed to run rake, tests, features, etc.
|
9
|
+
group :development do
|
10
|
+
gem "shoulda", ">= 0"
|
11
|
+
gem "bundler", "~> 1.0.0"
|
12
|
+
gem "jeweler", "~> 1.6.4"
|
13
|
+
gem "rcov", ">= 0"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.2.6)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.6.4)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
launchy (2.0.5)
|
11
|
+
addressable (~> 2.2.6)
|
12
|
+
rake (0.9.2.2)
|
13
|
+
rcov (0.9.11)
|
14
|
+
shoulda (2.11.3)
|
15
|
+
|
16
|
+
PLATFORMS
|
17
|
+
ruby
|
18
|
+
|
19
|
+
DEPENDENCIES
|
20
|
+
bundler (~> 1.0.0)
|
21
|
+
jeweler (~> 1.6.4)
|
22
|
+
launchy
|
23
|
+
rcov
|
24
|
+
shoulda
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Deklarativna - An HTML DSL for declarative template creation
|
2
|
+
Copyright (C) 2011 David Litvak Bruno
|
3
|
+
|
4
|
+
This program is free software; you can redistribute it and/or
|
5
|
+
modify it under the terms of the GNU General Public License
|
6
|
+
as published by the Free Software Foundation; either version 2
|
7
|
+
of the License, or (at your option) any later version.
|
8
|
+
|
9
|
+
This program is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public License
|
15
|
+
along with this program; if not, write to the Free Software
|
16
|
+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
17
|
+
|
18
|
+
Contact me at
|
19
|
+
david (dot) litvakb (at) gmail (dot) com
|
data/README.md
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
#Deklarativna
|
2
|
+
###A declarative HTML embedded DSL
|
3
|
+
|
4
|
+
##Purpose
|
5
|
+
The purpose of **Deklarativna** is to make HTML template creation
|
6
|
+
an integrated part of frontend development, allowing the programmer
|
7
|
+
to write *human readable code* with not much effort.
|
8
|
+
|
9
|
+
##Conception
|
10
|
+
This work has been started as a tool for teaching *declarative programming*
|
11
|
+
and *DSL creation* to univeritary students.
|
12
|
+
This is a work in progress and *I hope* someday will have integration
|
13
|
+
with the most popular web frameworks
|
14
|
+
|
15
|
+
##Current Status
|
16
|
+
All *HTML* common tags are implemented - frame, iframe and some html5 tags
|
17
|
+
had not been added.
|
18
|
+
Support for *XML* tags with *xml_single_tag* and *xml_double_tag*
|
19
|
+
is added.
|
20
|
+
Core module classes and helpers have *full support* for attributes.
|
21
|
+
|
22
|
+
##Usage
|
23
|
+
###Function Based Approach
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'deklarativna'
|
27
|
+
require 'deklarativna_utils'
|
28
|
+
|
29
|
+
include Deklarativna
|
30
|
+
include DeklarativnaUtils
|
31
|
+
|
32
|
+
renderable = html {[
|
33
|
+
head {
|
34
|
+
css {
|
35
|
+
".hello { float: right; color: #456546 }"
|
36
|
+
}
|
37
|
+
},
|
38
|
+
body {
|
39
|
+
p("class"=>"hello") {
|
40
|
+
"Hello World!"
|
41
|
+
}
|
42
|
+
}
|
43
|
+
]}
|
44
|
+
|
45
|
+
HTMLExporter.new.launch_rendered_html_on_browser renderable
|
46
|
+
```
|
47
|
+
|
48
|
+
###Class Based Approach
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
require 'deklarativna'
|
52
|
+
require 'deklarativna_utils'
|
53
|
+
|
54
|
+
class ChildTemplate < BaseTemplate
|
55
|
+
def _head
|
56
|
+
css { "h1 { color: red; }" }
|
57
|
+
end
|
58
|
+
|
59
|
+
def _body
|
60
|
+
[
|
61
|
+
h1 { "Deklarativna" },
|
62
|
+
p { "how cool is this??" },
|
63
|
+
p { "really cool" }
|
64
|
+
]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
include DeklarativnaUtils
|
69
|
+
|
70
|
+
HTMLExporter.new.launch_rendered_html_on_browser ChildTemplate.new.render
|
71
|
+
```
|
72
|
+
|
73
|
+
###Sinatra Integration
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
require 'rubygems'
|
77
|
+
require 'sinatra/base'
|
78
|
+
require 'deklarativna'
|
79
|
+
|
80
|
+
class IndexTemplate < BaseTemplate
|
81
|
+
def _body
|
82
|
+
[
|
83
|
+
p { "Testing Dinamic File Generation using sinatra" },
|
84
|
+
table("border"=>"1") {[
|
85
|
+
tr {[
|
86
|
+
td { "row 1, value 1" },
|
87
|
+
td { "row 1, value 2" }
|
88
|
+
]},
|
89
|
+
tr {[
|
90
|
+
td("colspan"=>"2") { "Only value in this row" }
|
91
|
+
]}
|
92
|
+
]}
|
93
|
+
]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
class DeklarativnaSinatra < Sinatra::Base
|
98
|
+
get '/' do
|
99
|
+
IndexTemplate.new.render
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
DeklarativnaSinatra.run!
|
104
|
+
```
|
105
|
+
|
106
|
+
Test this by running
|
107
|
+
|
108
|
+
```bash
|
109
|
+
$ruby dinamic_sinatra_example.rb
|
110
|
+
```
|
111
|
+
And open your browser on **localhost:4567**
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "deklarativna"
|
18
|
+
gem.homepage = "http://github.com/dlitvakb/deklarativna"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{A Declarative HMTL embedded DSL for HTML/XML Templating in Ruby}
|
21
|
+
gem.description = %Q{A Declarative HTML embedded DSL for HTML/XML Templating in Ruby,
|
22
|
+
This gem was intended to be use as teaching material for universitary students.}
|
23
|
+
gem.email = "david.litvakb@gmail.com"
|
24
|
+
gem.authors = ["David Litvak"]
|
25
|
+
# dependencies defined in Gemfile
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'rcov/rcovtask'
|
37
|
+
Rcov::RcovTask.new do |test|
|
38
|
+
test.libs << 'test'
|
39
|
+
test.pattern = 'test/**/test_*.rb'
|
40
|
+
test.verbose = true
|
41
|
+
test.rcov_opts << '--exclude "gems/*"'
|
42
|
+
end
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rake/rdoctask'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
|
+
|
50
|
+
rdoc.rdoc_dir = 'rdoc'
|
51
|
+
rdoc.title = "deklarativna #{version}"
|
52
|
+
rdoc.rdoc_files.include('README*')
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "deklarativna"
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["David Litvak"]
|
12
|
+
s.date = "2012-01-03"
|
13
|
+
s.description = "A Declarative HTML embedded DSL for HTML/XML Templating in Ruby,\n This gem was intended to be use as teaching material for universitary students."
|
14
|
+
s.email = "david.litvakb@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rvmrc",
|
22
|
+
"GPL_v2",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE",
|
26
|
+
"README.md",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"deklarativna.gemspec",
|
30
|
+
"examples/class_based_example.rb",
|
31
|
+
"examples/dinamic_sinatra_example.rb",
|
32
|
+
"examples/simple_example.rb",
|
33
|
+
"examples/static_sinatra_example.rb",
|
34
|
+
"lib/deklarativna.rb",
|
35
|
+
"lib/deklarativna_core.rb",
|
36
|
+
"lib/deklarativna_utils.rb",
|
37
|
+
"run_test.sh",
|
38
|
+
"test/helper.rb",
|
39
|
+
"test/test_deklarativna.rb",
|
40
|
+
"test/test_deklarativna_core.rb"
|
41
|
+
]
|
42
|
+
s.homepage = "http://github.com/dlitvakb/deklarativna"
|
43
|
+
s.licenses = ["MIT"]
|
44
|
+
s.require_paths = ["lib"]
|
45
|
+
s.rubygems_version = "1.8.11"
|
46
|
+
s.summary = "A Declarative HMTL embedded DSL for HTML/XML Templating in Ruby"
|
47
|
+
|
48
|
+
if s.respond_to? :specification_version then
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_runtime_dependency(%q<launchy>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
54
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
55
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
56
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<launchy>, [">= 0"])
|
59
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
60
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
61
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
62
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
63
|
+
end
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<launchy>, [">= 0"])
|
66
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
67
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
68
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
69
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'deklarativna'
|
2
|
+
require 'deklarativna_utils'
|
3
|
+
|
4
|
+
class ChildTemplate < BaseTemplate
|
5
|
+
def _head
|
6
|
+
css { "h1 { color: red; }" }
|
7
|
+
end
|
8
|
+
|
9
|
+
def _body
|
10
|
+
[
|
11
|
+
h1 { "Deklarativna" },
|
12
|
+
p { "how cool is this??" },
|
13
|
+
p { "really cool" }
|
14
|
+
]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
include DeklarativnaUtils
|
19
|
+
|
20
|
+
HTMLExporter.new.launch_rendered_html_on_browser ChildTemplate.new.render
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sinatra/base'
|
3
|
+
require 'deklarativna'
|
4
|
+
|
5
|
+
class IndexTemplate < BaseTemplate
|
6
|
+
def _body
|
7
|
+
[
|
8
|
+
p { "Testing Dinamic File Generation using sinatra" },
|
9
|
+
table("border"=>"1") {[
|
10
|
+
tr {[
|
11
|
+
td { "row 1, value 1" },
|
12
|
+
td { "row 1, value 2" }
|
13
|
+
]},
|
14
|
+
tr {[
|
15
|
+
td("colspan"=>"2") { "Only value in this row" }
|
16
|
+
]}
|
17
|
+
]}
|
18
|
+
]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class DeklarativnaSinatra < Sinatra::Base
|
23
|
+
get '/' do
|
24
|
+
IndexTemplate.new.render
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
DeklarativnaSinatra.run!
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'deklarativna'
|
2
|
+
require 'deklarativna_utils'
|
3
|
+
|
4
|
+
include Deklarativna
|
5
|
+
include DeklarativnaUtils
|
6
|
+
|
7
|
+
renderable = html {[
|
8
|
+
head {
|
9
|
+
css {
|
10
|
+
"p { font-size: 38px; color: red; }"
|
11
|
+
}
|
12
|
+
},
|
13
|
+
body {
|
14
|
+
paragraphs = []
|
15
|
+
["john", "dani", "david"].each { |e| paragraphs.push(p { "hola #{e}" }) }
|
16
|
+
paragraphs
|
17
|
+
}
|
18
|
+
]}
|
19
|
+
|
20
|
+
HTMLExporter.new.launch_rendered_html_on_browser renderable
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sinatra/base'
|
3
|
+
require 'deklarativna'
|
4
|
+
require 'deklarativna_utils'
|
5
|
+
|
6
|
+
class BaseTemplate
|
7
|
+
include Deklarativna
|
8
|
+
include DeklarativnaUtils
|
9
|
+
|
10
|
+
def initialize url
|
11
|
+
@url = url
|
12
|
+
end
|
13
|
+
|
14
|
+
def render
|
15
|
+
html {[
|
16
|
+
head {[
|
17
|
+
title {
|
18
|
+
_title
|
19
|
+
},
|
20
|
+
_head
|
21
|
+
]},
|
22
|
+
body {[
|
23
|
+
h1 {
|
24
|
+
"Deklarativna"
|
25
|
+
},
|
26
|
+
div {
|
27
|
+
_content
|
28
|
+
}
|
29
|
+
]}
|
30
|
+
]}
|
31
|
+
end
|
32
|
+
|
33
|
+
def _title
|
34
|
+
"Deklarativna"
|
35
|
+
end
|
36
|
+
|
37
|
+
def _head
|
38
|
+
end
|
39
|
+
|
40
|
+
def _content
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_file
|
44
|
+
HTMLExporter.new.render_to_file @url, render
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class IndexTemplate < BaseTemplate
|
49
|
+
def _content
|
50
|
+
[
|
51
|
+
p { "Testing Static File Generation using sinatra" },
|
52
|
+
table("border"=>"1") {[
|
53
|
+
tr {[
|
54
|
+
td { "row 1, value 1" },
|
55
|
+
td { "row 1, value 2" }
|
56
|
+
]},
|
57
|
+
tr {[
|
58
|
+
td("colspan"=>"2") { "Only value in this row" }
|
59
|
+
]}
|
60
|
+
]}
|
61
|
+
]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class DeklarativnaSinatra < Sinatra::Base
|
66
|
+
set :static, true
|
67
|
+
set :public_folder, File.dirname(__FILE__)
|
68
|
+
end
|
69
|
+
|
70
|
+
(BaseTemplate.new "base.html").to_file
|
71
|
+
(IndexTemplate.new "index.html").to_file
|
72
|
+
DeklarativnaSinatra.run!
|
data/lib/deklarativna.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'deklarativna_core'
|
2
|
+
|
3
|
+
module Deklarativna
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
nesting_renderables = ["html", "head", "body", "p", "div", "span",
|
7
|
+
"table", "tr", "td", "ul", "ol", "li",
|
8
|
+
"center", "dd", "dl", "dt", "i", "b",
|
9
|
+
"em", "strong", "title", "pre", "script",
|
10
|
+
"style", "a", "form"]
|
11
|
+
(1..6).each { |e| nesting_renderables.push "h#{e}" }
|
12
|
+
|
13
|
+
nesting_renderables.each do
|
14
|
+
|tag_name|
|
15
|
+
send :define_method, tag_name do
|
16
|
+
|*args, &block|
|
17
|
+
attributes = args[0] if !args.nil?
|
18
|
+
nesting_renderable_string tag_name, block, attributes
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
single_tag_renderables = ["meta", "br", "link", "input", "img"]
|
23
|
+
single_tag_renderables.each do
|
24
|
+
|tag_name|
|
25
|
+
send :define_method, tag_name do
|
26
|
+
|*args|
|
27
|
+
attributes = args[0] if !args.nil?
|
28
|
+
single_tag_renderable_string tag_name, attributes
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
form_input_renderables = ["text", "password", "textarea", "checkbox",
|
33
|
+
"radio", "submit"]
|
34
|
+
form_input_renderables.each do
|
35
|
+
|type|
|
36
|
+
send :define_method, type do
|
37
|
+
|*args|
|
38
|
+
attributes = args[9] if !args.nil?
|
39
|
+
attributes ||= {}
|
40
|
+
attributes["type"] = type
|
41
|
+
input attributes
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def javascript attributes={}, &script_text_block
|
47
|
+
attributes["type"] = "text/javascript"
|
48
|
+
script attributes, &script_text_block
|
49
|
+
end
|
50
|
+
|
51
|
+
def css attributes={}, &style_text_block
|
52
|
+
attributes["type"] = "text/css"
|
53
|
+
style attributes, &style_text_block
|
54
|
+
end
|
55
|
+
|
56
|
+
def comment &comment_block
|
57
|
+
comment_renderable_string comment_block
|
58
|
+
end
|
59
|
+
|
60
|
+
def xml_single_tag tag_name, attributes={}
|
61
|
+
single_tag_renderable_string tag_name.downcase, attributes
|
62
|
+
end
|
63
|
+
|
64
|
+
def xml_double_tag tag_name, attributes={}, &html_block
|
65
|
+
nesting_renderable_string tag_name.downcase, html_block, attributes
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class BaseTemplate
|
70
|
+
include Deklarativna
|
71
|
+
|
72
|
+
def render
|
73
|
+
html {[
|
74
|
+
head {
|
75
|
+
_head
|
76
|
+
},
|
77
|
+
body {
|
78
|
+
_body
|
79
|
+
}
|
80
|
+
]}
|
81
|
+
end
|
82
|
+
|
83
|
+
def _head
|
84
|
+
end
|
85
|
+
|
86
|
+
def _body
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Deklarativna
|
2
|
+
|
3
|
+
class Renderable
|
4
|
+
attr_accessor :tag_name,:attributes
|
5
|
+
|
6
|
+
def initialize &initialization_block
|
7
|
+
initialization_block.call self
|
8
|
+
end
|
9
|
+
|
10
|
+
def render_attributes
|
11
|
+
rendering_tags = []
|
12
|
+
attribute_list = @attributes.sort if @attributes.respond_to? :sort
|
13
|
+
if attribute_list.respond_to? :each
|
14
|
+
attribute_list.each do |e|
|
15
|
+
rendering_tags.push "#{e[0]}=\"#{e[1]}\""
|
16
|
+
end
|
17
|
+
end
|
18
|
+
return " " + (rendering_tags.join " ") if !rendering_tags.empty?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class NestingRenderable < Renderable
|
23
|
+
attr_accessor :content
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
"<#{@tag_name}#{render_attributes}>#{proc_call}</#{@tag_name}>"
|
27
|
+
end
|
28
|
+
|
29
|
+
def proc_call
|
30
|
+
if @content.nil?
|
31
|
+
return ""
|
32
|
+
end
|
33
|
+
_proc_call
|
34
|
+
end
|
35
|
+
|
36
|
+
def _proc_call
|
37
|
+
if @content.call.respond_to? :join
|
38
|
+
return @content.call.join("")
|
39
|
+
end
|
40
|
+
@content.call
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class CommentRenderable < NestingRenderable
|
45
|
+
def to_s
|
46
|
+
"<!--#{proc_call}-->"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class SingleTagRenderable < Renderable
|
51
|
+
def to_s
|
52
|
+
"<#{@tag_name}#{render_attributes} />"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def renderable_string renderable_class, block, attributes={}, tag_name=""
|
57
|
+
(renderable_class.new { |instance|
|
58
|
+
instance.tag_name = tag_name
|
59
|
+
instance.attributes = attributes
|
60
|
+
if instance.respond_to? :content
|
61
|
+
instance.content = block
|
62
|
+
end
|
63
|
+
}).to_s
|
64
|
+
end
|
65
|
+
|
66
|
+
def single_tag_renderable_string tag_name, attributes={}
|
67
|
+
renderable_string SingleTagRenderable, nil, attributes, tag_name
|
68
|
+
end
|
69
|
+
|
70
|
+
def nesting_renderable_string tag_name, block, attributes={}
|
71
|
+
renderable_string NestingRenderable, block, attributes, tag_name
|
72
|
+
end
|
73
|
+
|
74
|
+
def comment_renderable_string comment_block
|
75
|
+
renderable_string CommentRenderable, comment_block
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'launchy'
|
3
|
+
|
4
|
+
module DeklarativnaUtils
|
5
|
+
class HTMLExporter
|
6
|
+
@@default_filename = 'rendered_html.html'
|
7
|
+
|
8
|
+
def render_to_file filename, rendered_html
|
9
|
+
File.open(filename, 'w') { |f| f.write(rendered_html) }
|
10
|
+
filename
|
11
|
+
end
|
12
|
+
|
13
|
+
#Requires Firefox or Chrome
|
14
|
+
def launch_file_on_browser filename_or_url
|
15
|
+
Launchy.open filename_or_url
|
16
|
+
end
|
17
|
+
|
18
|
+
#Requires Firefox or Chrome
|
19
|
+
def launch_rendered_html_on_browser rendered_html, filename=nil
|
20
|
+
filename ||= @@default_filename
|
21
|
+
launch_file_on_browser(
|
22
|
+
render_to_file filename,
|
23
|
+
rendered_html
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
data/run_test.sh
ADDED
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'deklarativna'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'deklarativna'
|
3
|
+
|
4
|
+
class DeklarativnaTest < Test::Unit::TestCase
|
5
|
+
include Deklarativna
|
6
|
+
|
7
|
+
def test_html_renders_single_element
|
8
|
+
assert_equal "<html></html>", html
|
9
|
+
assert_equal "<head></head>", head
|
10
|
+
assert_equal "<title></title>", title
|
11
|
+
assert_equal "<link />", link
|
12
|
+
assert_equal "<meta />", meta
|
13
|
+
assert_equal "<script></script>", script
|
14
|
+
assert_equal "<script type=\"text/javascript\"></script>", javascript
|
15
|
+
assert_equal "<style></style>", style
|
16
|
+
assert_equal "<style type=\"text/css\"></style>", css
|
17
|
+
assert_equal "<body></body>", body
|
18
|
+
assert_equal "<h1></h1>", h1
|
19
|
+
assert_equal "<h2></h2>", h2
|
20
|
+
assert_equal "<h3></h3>", h3
|
21
|
+
assert_equal "<h4></h4>", h4
|
22
|
+
assert_equal "<h5></h5>", h5
|
23
|
+
assert_equal "<h6></h6>", h6
|
24
|
+
assert_equal "<p></p>", p
|
25
|
+
assert_equal "<div></div>", div
|
26
|
+
assert_equal "<span></span>", span
|
27
|
+
assert_equal "<table></table>", table
|
28
|
+
assert_equal "<tr></tr>", tr
|
29
|
+
assert_equal "<td></td>", td
|
30
|
+
assert_equal "<ul></ul>", ul
|
31
|
+
assert_equal "<ol></ol>", ol
|
32
|
+
assert_equal "<li></li>", li
|
33
|
+
assert_equal "<a></a>", a
|
34
|
+
assert_equal "<form></form>", form
|
35
|
+
assert_equal "<input />", input
|
36
|
+
assert_equal "<input type=\"text\" />", text
|
37
|
+
assert_equal "<input type=\"password\" />", password
|
38
|
+
assert_equal "<input type=\"radio\" />", radio
|
39
|
+
assert_equal "<input type=\"checkbox\" />", checkbox
|
40
|
+
assert_equal "<input type=\"textarea\" />", textarea
|
41
|
+
assert_equal "<input type=\"submit\" />", submit
|
42
|
+
assert_equal "<center></center>", center
|
43
|
+
assert_equal "<dd></dd>", dd
|
44
|
+
assert_equal "<dl></dl>", dl
|
45
|
+
assert_equal "<dt></dt>", dt
|
46
|
+
assert_equal "<i></i>", i
|
47
|
+
assert_equal "<b></b>", b
|
48
|
+
assert_equal "<em></em>", em
|
49
|
+
assert_equal "<strong></strong>", strong
|
50
|
+
assert_equal "<pre></pre>", pre
|
51
|
+
|
52
|
+
assert_equal "<br />", br
|
53
|
+
assert_equal "<img />", img
|
54
|
+
assert_equal "<!---->", comment
|
55
|
+
|
56
|
+
assert_equal "<mysingletag />", (xml_single_tag "mysingletag")
|
57
|
+
assert_equal "<mydoubletag></mydoubletag>", (xml_double_tag "mydoubletag")
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_render_any_number_of_nestings
|
61
|
+
renderable = html {
|
62
|
+
body {
|
63
|
+
p {
|
64
|
+
"hola"
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|
68
|
+
assert_equal "<html><body><p>hola</p></body></html>", renderable
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_render_many_tags_on_the_same_level
|
72
|
+
renderable = html {[
|
73
|
+
head,
|
74
|
+
body
|
75
|
+
]}
|
76
|
+
assert_equal "<html><head></head><body></body></html>", renderable
|
77
|
+
|
78
|
+
renderable = html {[
|
79
|
+
head {
|
80
|
+
javascript
|
81
|
+
},
|
82
|
+
body {[
|
83
|
+
p { "hola" },
|
84
|
+
p { "chau" }
|
85
|
+
]}
|
86
|
+
]}
|
87
|
+
assert_equal "<html><head><script type=\"text/javascript\"></script></head><body><p>hola</p><p>chau</p></body></html>", renderable
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_style_can_render_css
|
91
|
+
renderable = css {
|
92
|
+
"h1, p {text-align: left;}"
|
93
|
+
}
|
94
|
+
assert_equal "<style type=\"text/css\">h1, p {text-align: left;}</style>", renderable
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_script_can_render_javascript
|
98
|
+
renderable = javascript {
|
99
|
+
"var y = 2; alert(y);"
|
100
|
+
}
|
101
|
+
assert_equal "<script type=\"text/javascript\">var y = 2; alert(y);</script>", renderable
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_comment_block
|
105
|
+
renderable = comment {
|
106
|
+
"This is a test"
|
107
|
+
}
|
108
|
+
assert_equal "<!--This is a test-->", renderable
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_img
|
112
|
+
renderable = img "src"=>"/this.jpg"
|
113
|
+
assert_equal "<img src=\"/this.jpg\" />", renderable
|
114
|
+
|
115
|
+
renderable = img "alt"=>"a photo"
|
116
|
+
assert_equal "<img alt=\"a photo\" />", renderable
|
117
|
+
|
118
|
+
renderable = img "src"=>"/this.jpg", "alt"=>"a photo"
|
119
|
+
assert_equal "<img alt=\"a photo\" src=\"/this.jpg\" />", renderable
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_nesting_elements_can_have_attributes
|
123
|
+
renderable = p("class"=>"foo") { "something" }
|
124
|
+
assert_equal "<p class=\"foo\">something</p>", renderable
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_base_template
|
128
|
+
assert_equal "<html><head></head><body></body></html>", BaseTemplate.new.render
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'deklarativna_core'
|
3
|
+
|
4
|
+
class DeklarativnaCoreTest < Test::Unit::TestCase
|
5
|
+
include Deklarativna
|
6
|
+
|
7
|
+
def test_nesting_renderable
|
8
|
+
renderable = NestingRenderable.new { |instance|
|
9
|
+
instance.tag_name = "html"
|
10
|
+
}
|
11
|
+
assert_equal "<html></html>", renderable.to_s
|
12
|
+
renderable = NestingRenderable.new { |instance|
|
13
|
+
instance.tag_name = "html"
|
14
|
+
instance.content = Proc.new {
|
15
|
+
NestingRenderable.new { |instance|
|
16
|
+
instance.tag_name = "body"
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
assert_equal "<html><body></body></html>", renderable.to_s
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_comment_renderable
|
24
|
+
renderable = CommentRenderable.new { |instance|
|
25
|
+
instance.content = Proc.new {
|
26
|
+
"some whacky comment"
|
27
|
+
}
|
28
|
+
}
|
29
|
+
assert_equal "<!--some whacky comment-->", renderable.to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_single_tag_renderable
|
33
|
+
renderable = SingleTagRenderable.new { |instance|
|
34
|
+
instance.tag_name = "br"
|
35
|
+
}
|
36
|
+
assert_equal "<br />", renderable.to_s
|
37
|
+
renderable = SingleTagRenderable.new { |instance|
|
38
|
+
instance.tag_name = "link"
|
39
|
+
}
|
40
|
+
assert_equal "<link />", renderable.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_attributes_display_correctly
|
44
|
+
renderable = SingleTagRenderable.new { |instance|
|
45
|
+
instance.tag_name = "link"
|
46
|
+
instance.attributes = {"rel"=>"stylesheet/css",
|
47
|
+
"src"=>"/style.css"}
|
48
|
+
}
|
49
|
+
assert_equal "<link rel=\"stylesheet/css\" src=\"/style.css\" />", renderable.to_s
|
50
|
+
|
51
|
+
renderable = SingleTagRenderable.new { |instance|
|
52
|
+
instance.tag_name = "link"
|
53
|
+
instance.attributes = {"rel"=>"stylesheet/css",
|
54
|
+
"src"=>"/style2.css"}
|
55
|
+
}
|
56
|
+
assert_equal "<link rel=\"stylesheet/css\" src=\"/style2.css\" />", renderable.to_s
|
57
|
+
|
58
|
+
renderable = NestingRenderable.new { |instance|
|
59
|
+
instance.tag_name = "script"
|
60
|
+
instance.attributes = {"type"=>"text/javascript"}
|
61
|
+
}
|
62
|
+
assert_equal "<script type=\"text/javascript\"></script>", renderable.to_s
|
63
|
+
|
64
|
+
renderable = NestingRenderable.new { |instance|
|
65
|
+
instance.tag_name = "body"
|
66
|
+
instance.attributes = {"class"=>"some-class"}
|
67
|
+
instance.content = Proc.new {
|
68
|
+
NestingRenderable.new { |instance|
|
69
|
+
instance.tag_name = "h1"
|
70
|
+
instance.content = Proc.new { "Hi!" }
|
71
|
+
}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
assert_equal "<body class=\"some-class\"><h1>Hi!</h1></body>", renderable.to_s
|
75
|
+
|
76
|
+
renderable = CommentRenderable.new { |instance|
|
77
|
+
instance.content = Proc.new { "Hi!" }
|
78
|
+
instance.attributes = {"nothing"=>"will happen"}
|
79
|
+
}
|
80
|
+
assert_equal "<!--Hi!-->", renderable.to_s
|
81
|
+
end
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: deklarativna
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- David Litvak
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-01-03 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 3
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
version_requirements: *id001
|
31
|
+
name: launchy
|
32
|
+
prerelease: false
|
33
|
+
type: :runtime
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
hash: 3
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
version_requirements: *id002
|
45
|
+
name: shoulda
|
46
|
+
prerelease: false
|
47
|
+
type: :development
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
hash: 23
|
55
|
+
segments:
|
56
|
+
- 1
|
57
|
+
- 0
|
58
|
+
- 0
|
59
|
+
version: 1.0.0
|
60
|
+
version_requirements: *id003
|
61
|
+
name: bundler
|
62
|
+
prerelease: false
|
63
|
+
type: :development
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ~>
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 7
|
71
|
+
segments:
|
72
|
+
- 1
|
73
|
+
- 6
|
74
|
+
- 4
|
75
|
+
version: 1.6.4
|
76
|
+
version_requirements: *id004
|
77
|
+
name: jeweler
|
78
|
+
prerelease: false
|
79
|
+
type: :development
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
version_requirements: *id005
|
91
|
+
name: rcov
|
92
|
+
prerelease: false
|
93
|
+
type: :development
|
94
|
+
description: |-
|
95
|
+
A Declarative HTML embedded DSL for HTML/XML Templating in Ruby,
|
96
|
+
This gem was intended to be use as teaching material for universitary students.
|
97
|
+
email: david.litvakb@gmail.com
|
98
|
+
executables: []
|
99
|
+
|
100
|
+
extensions: []
|
101
|
+
|
102
|
+
extra_rdoc_files:
|
103
|
+
- LICENSE
|
104
|
+
- README.md
|
105
|
+
files:
|
106
|
+
- .document
|
107
|
+
- .rvmrc
|
108
|
+
- GPL_v2
|
109
|
+
- Gemfile
|
110
|
+
- Gemfile.lock
|
111
|
+
- LICENSE
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- VERSION
|
115
|
+
- deklarativna.gemspec
|
116
|
+
- examples/class_based_example.rb
|
117
|
+
- examples/dinamic_sinatra_example.rb
|
118
|
+
- examples/simple_example.rb
|
119
|
+
- examples/static_sinatra_example.rb
|
120
|
+
- lib/deklarativna.rb
|
121
|
+
- lib/deklarativna_core.rb
|
122
|
+
- lib/deklarativna_utils.rb
|
123
|
+
- run_test.sh
|
124
|
+
- test/helper.rb
|
125
|
+
- test/test_deklarativna.rb
|
126
|
+
- test/test_deklarativna_core.rb
|
127
|
+
homepage: http://github.com/dlitvakb/deklarativna
|
128
|
+
licenses:
|
129
|
+
- MIT
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
none: false
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
hash: 3
|
141
|
+
segments:
|
142
|
+
- 0
|
143
|
+
version: "0"
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
hash: 3
|
150
|
+
segments:
|
151
|
+
- 0
|
152
|
+
version: "0"
|
153
|
+
requirements: []
|
154
|
+
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 1.8.11
|
157
|
+
signing_key:
|
158
|
+
specification_version: 3
|
159
|
+
summary: A Declarative HMTL embedded DSL for HTML/XML Templating in Ruby
|
160
|
+
test_files: []
|
161
|
+
|