stonean-ruhl 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +73 -11
- data/VERSION +1 -1
- data/lib/ruhl/errors.rb +1 -0
- data/lib/ruhl.rb +18 -2
- data/ruhl.gemspec +3 -1
- data/spec/html/main_with_sidebar.html +22 -0
- data/spec/html/sidebar.html +7 -0
- data/spec/ruhl_spec.rb +16 -1
- metadata +3 -1
data/README
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
Ruhl (Ruby Hypertext Language)
|
2
2
|
|
3
|
-
This project is here to flesh out an idea. What I want is to have developers
|
3
|
+
This project is here to flesh out an idea. What I want is to have developers
|
4
|
+
work with HTML and with the simple addition of a 'ruby' attribute, convert it
|
5
|
+
to a dynamic page.
|
4
6
|
|
5
|
-
At no time in the dev process would the view be unviewable in a browser.
|
7
|
+
At no time in the dev process would the view be unviewable in a browser.
|
8
|
+
The view could actually retain the original template data the designer used
|
9
|
+
because this replaces the content. I think this is a nice plus.
|
6
10
|
|
7
11
|
|
8
12
|
Notes (use cases) for me to remember:
|
@@ -13,17 +17,21 @@ Notes (use cases) for me to remember:
|
|
13
17
|
|
14
18
|
<h1 ruby="page_header">
|
15
19
|
|
16
|
-
Method :page_header would know how to represent itself in the context of
|
20
|
+
Method :page_header would know how to represent itself in the context of
|
21
|
+
the h1 element.
|
17
22
|
|
18
|
-
The ruby executed would replace the content of the element it was being
|
23
|
+
The ruby executed would replace the content of the element it was being
|
24
|
+
called on.
|
19
25
|
|
20
26
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
21
27
|
:: Replacing attribute values ::
|
22
28
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
23
29
|
|
24
|
-
<meta ruby="content: meta_description" content='This is a description template'
|
30
|
+
<meta ruby="content: meta_description" content='This is a description template'
|
31
|
+
id='metaDescription' name='description' />
|
25
32
|
|
26
|
-
content: meta_description is telling the parser to replace attribute 'content'
|
33
|
+
content: meta_description is telling the parser to replace attribute 'content'
|
34
|
+
with results from meta_description method.
|
27
35
|
|
28
36
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
29
37
|
:: Don't use iterators in views ::
|
@@ -34,7 +42,9 @@ content: meta_description is telling the parser to replace attribute 'content' w
|
|
34
42
|
<li>consectetur adipiscing elit</li>
|
35
43
|
</ul>
|
36
44
|
|
37
|
-
Method :present_results would know how to represent itself in the
|
45
|
+
Method :present_results would know how to represent itself in the
|
46
|
+
context of the ul element. In other words, it would know how to
|
47
|
+
produce <li> elements.
|
38
48
|
|
39
49
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
40
50
|
:: Using a Layout ::
|
@@ -58,7 +68,59 @@ To use:
|
|
58
68
|
|
59
69
|
Ruhl::Engine.new(File.read(fragment), :layout => path_to_layout).render(self)
|
60
70
|
|
61
|
-
Returns the expected result of parsed Layout w/ parsed Fragment.
|
71
|
+
Returns the expected result of parsed Layout w/ parsed Fragment.
|
72
|
+
|
73
|
+
Note the use of the _render_ method. This is a 'special' method that
|
74
|
+
Ruhl uses to inject the results of the parsed fragment into the layout.
|
75
|
+
|
76
|
+
|
77
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
78
|
+
:: Using a Partial ::
|
79
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
80
|
+
|
81
|
+
Main:
|
82
|
+
<html>
|
83
|
+
<head>
|
84
|
+
<title>This is a title template</title>
|
85
|
+
</head>
|
86
|
+
<body>
|
87
|
+
<div id="wrap">
|
88
|
+
<div id="sidebar" ruby="_partial: sidebar_partial">
|
89
|
+
<h3>Sidebar links</h3>
|
90
|
+
<ul>
|
91
|
+
<li><a href="#">Link 1</a></li>
|
92
|
+
<li><a href="#">Link 2</a></li>
|
93
|
+
<li><a href="#">Link 3</a></li>
|
94
|
+
<li><a href="#">Link 4</a></li>
|
95
|
+
</ul>
|
96
|
+
</div>
|
97
|
+
<div id="main">
|
98
|
+
<h1> My main content</h1>
|
99
|
+
<p>Text designers would put here to test their layout</p>
|
100
|
+
</div>
|
101
|
+
</div>
|
102
|
+
</body>
|
103
|
+
</html>
|
104
|
+
|
105
|
+
Sidebar:
|
106
|
+
<h3>Real Sidebarlinks</h3>
|
107
|
+
<ul>
|
108
|
+
<li><a href="#">Real Link 1</a></li>
|
109
|
+
<li><a href="#">Real Link 2</a></li>
|
110
|
+
<li><a href="#">Real Link 3</a></li>
|
111
|
+
<li><a href="#">Real Link 4</a></li>
|
112
|
+
</ul>
|
113
|
+
|
114
|
+
To use:
|
115
|
+
|
116
|
+
Ruhl::Engine.new(File.read(fragment)).render(self)
|
117
|
+
|
118
|
+
Returns the expected result of parsed Main with sidebar div contents
|
119
|
+
replaced with parsed sidebar partial contents.
|
120
|
+
|
121
|
+
Note the use of the _partial key. This is a 'special' key that Ruhl
|
122
|
+
uses to inject the results of the parsed partial into the contents
|
123
|
+
of the calling node.
|
62
124
|
|
63
125
|
|
64
126
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
@@ -72,7 +134,8 @@ Returns the expected result of parsed Layout w/ parsed Fragment. Note the use o
|
|
72
134
|
* Each method called must accept a tag parameter.
|
73
135
|
e.g def page_header(tag)
|
74
136
|
|
75
|
-
* Since it's just HTML, syntax highlighting is built-in.
|
137
|
+
* Since it's just HTML, syntax highlighting is built-in.
|
138
|
+
For vim, just add this to your ~/.vimrc:
|
76
139
|
au BufNewFile,BufRead *.ruhl set filetype=html
|
77
140
|
|
78
141
|
|
@@ -80,6 +143,5 @@ Returns the expected result of parsed Layout w/ parsed Fragment. Note the use o
|
|
80
143
|
:: TODO ::
|
81
144
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
82
145
|
|
83
|
-
1) Work on supporting
|
84
|
-
2) Work on supporting partials (shouldn't be hard)
|
146
|
+
1) Work on supporting partials (shouldn't be hard)
|
85
147
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/ruhl/errors.rb
CHANGED
data/lib/ruhl.rb
CHANGED
@@ -43,13 +43,29 @@ module Ruhl
|
|
43
43
|
parts = code.split(';')
|
44
44
|
parts.each do |pair|
|
45
45
|
attribute, value = pair.split(':')
|
46
|
+
|
47
|
+
value.strip!
|
46
48
|
|
47
|
-
|
49
|
+
if attribute == "_partial"
|
50
|
+
tag.inner_html = render_partial(tag, value)
|
51
|
+
else
|
52
|
+
tag[attribute] = execute_ruby(tag, value)
|
53
|
+
end
|
48
54
|
end
|
49
55
|
end
|
50
56
|
|
51
57
|
def render_with_layout
|
52
|
-
|
58
|
+
render_file( File.read(@layout) )
|
59
|
+
end
|
60
|
+
|
61
|
+
def render_partial(tag, code)
|
62
|
+
file = execute_ruby(tag, code)
|
63
|
+
raise PartialNotFoundError.new(file) unless File.exists?(file)
|
64
|
+
render_file( File.read(file) )
|
65
|
+
end
|
66
|
+
|
67
|
+
def render_file(contents)
|
68
|
+
doc = Nokogiri::HTML( contents )
|
53
69
|
parse_doc(doc)
|
54
70
|
doc.to_s
|
55
71
|
end
|
data/ruhl.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ruhl}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andrew Stone"]
|
@@ -27,8 +27,10 @@ Gem::Specification.new do |s|
|
|
27
27
|
"spec/html/basic.html",
|
28
28
|
"spec/html/fragment.html",
|
29
29
|
"spec/html/layout.html",
|
30
|
+
"spec/html/main_with_sidebar.html",
|
30
31
|
"spec/html/medium.html",
|
31
32
|
"spec/html/seo.html",
|
33
|
+
"spec/html/sidebar.html",
|
32
34
|
"spec/rcov.opts",
|
33
35
|
"spec/ruhl_spec.rb",
|
34
36
|
"spec/spec.opts",
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>This is a title template</title>
|
4
|
+
</head>
|
5
|
+
<body>
|
6
|
+
<div id="wrap">
|
7
|
+
<div id="sidebar" ruby="_partial: sidebar_partial">
|
8
|
+
<h3>Sidebar links</h3>
|
9
|
+
<ul>
|
10
|
+
<li><a href="#">Link 1</a></li>
|
11
|
+
<li><a href="#">Link 2</a></li>
|
12
|
+
<li><a href="#">Link 3</a></li>
|
13
|
+
<li><a href="#">Link 4</a></li>
|
14
|
+
</ul>
|
15
|
+
</div>
|
16
|
+
<div id="main">
|
17
|
+
<h1> My main content</h1>
|
18
|
+
<p>Text designers would put here to test their layout</p>
|
19
|
+
</div>
|
20
|
+
</div>
|
21
|
+
</body>
|
22
|
+
</html>
|
data/spec/ruhl_spec.rb
CHANGED
@@ -24,6 +24,10 @@ def my_content(tag = nil)
|
|
24
24
|
"hello from my content."
|
25
25
|
end
|
26
26
|
|
27
|
+
def sidebar_partial(tag = nil)
|
28
|
+
html(:sidebar)
|
29
|
+
end
|
30
|
+
|
27
31
|
describe Ruhl do
|
28
32
|
|
29
33
|
describe "basic.html" do
|
@@ -74,7 +78,18 @@ describe Ruhl do
|
|
74
78
|
|
75
79
|
it "will be injected into layout.html" do
|
76
80
|
doc = create_doc( html(:layout) )
|
77
|
-
|
81
|
+
doc.xpath('//h1').should_not be_empty
|
82
|
+
doc.xpath('//p').should_not be_empty
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "main_with_sidebar.html" do
|
87
|
+
before do
|
88
|
+
@html = File.read html(:main_with_sidebar)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should replace sidebar with partial contents" do
|
92
|
+
doc = create_doc
|
78
93
|
puts doc.to_s
|
79
94
|
end
|
80
95
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stonean-ruhl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Stone
|
@@ -33,8 +33,10 @@ files:
|
|
33
33
|
- spec/html/basic.html
|
34
34
|
- spec/html/fragment.html
|
35
35
|
- spec/html/layout.html
|
36
|
+
- spec/html/main_with_sidebar.html
|
36
37
|
- spec/html/medium.html
|
37
38
|
- spec/html/seo.html
|
39
|
+
- spec/html/sidebar.html
|
38
40
|
- spec/rcov.opts
|
39
41
|
- spec/ruhl_spec.rb
|
40
42
|
- spec/spec.opts
|