pivotal-erector 0.6.3 → 0.6.4
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.
- data/README.txt +10 -5
- data/VERSION.yml +1 -1
- data/bin/erector +3 -1
- data/lib/erector/erect.rb +4 -2
- data/lib/erector/erected.rb +14 -4
- data/lib/erector/mixin.rb +7 -0
- data/lib/erector/rhtml.treetop +48 -11
- data/lib/erector/widget.rb +146 -113
- data/lib/erector.rb +1 -0
- data/spec/erect/erect_rails_spec.rb +62 -0
- data/spec/erect/erect_spec.rb +165 -0
- data/spec/erect/erected_spec.rb +93 -0
- data/spec/erect/rhtml_parser_spec.rb +351 -0
- data/spec/erector/mixin_spec.rb +54 -0
- data/spec/erector/widget_spec.rb +38 -0
- metadata +14 -2
data/README.txt
CHANGED
@@ -25,20 +25,25 @@ project site at http://erector.rubyforge.org for more documentation.
|
|
25
25
|
end
|
26
26
|
body do
|
27
27
|
text "Hello, "
|
28
|
-
b
|
28
|
+
b target, :class => 'big'
|
29
|
+
text "!"
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
34
35
|
Hello.new(:target => 'world').to_s
|
35
|
-
=> "<html><head><title>Hello</title></head><body>Hello, <b class=\"big\">world
|
36
|
+
=> "<html><head><title>Hello</title></head><body>Hello, <b class=\"big\">world</b>!</body></html>"
|
37
|
+
|
38
|
+
include Erector::Mixin
|
39
|
+
erector { div "love", :class => "big" }
|
40
|
+
=> "<div class=\"big\">love</div>"
|
36
41
|
|
37
42
|
== REQUIREMENTS
|
38
43
|
|
39
|
-
The gem depends on rake and treetop, although this is just for using the
|
40
|
-
so deployed applications won't need these.
|
41
|
-
|
44
|
+
The gem depends on rake and treetop, although this is just for using the command-line tool,
|
45
|
+
so deployed applications won't need these. The Rails-dependent code is now separated so
|
46
|
+
you can use Erector cleanly in a non-Rails app.
|
42
47
|
|
43
48
|
== INSTALL
|
44
49
|
|
data/VERSION.yml
CHANGED
data/bin/erector
CHANGED
data/lib/erector/erect.rb
CHANGED
@@ -78,7 +78,9 @@ module Erector
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def run
|
81
|
+
@success = true
|
81
82
|
self.send(mode)
|
83
|
+
@success
|
82
84
|
end
|
83
85
|
|
84
86
|
def to_erector
|
@@ -91,7 +93,7 @@ module Erector
|
|
91
93
|
rescue => e
|
92
94
|
puts e
|
93
95
|
puts e.backtrace.join("\n\t")
|
94
|
-
|
96
|
+
@success = false
|
95
97
|
end
|
96
98
|
end
|
97
99
|
end
|
@@ -103,7 +105,6 @@ module Erector
|
|
103
105
|
begin
|
104
106
|
#todo: fail if file isn't a .rb file
|
105
107
|
require file
|
106
|
-
#todo: understand modulized widgets (e.g. class Foo::Bar::Baz < Erector::Widget in baz.rb)
|
107
108
|
filename = file.split('/').last.gsub(/\.rb$/, '')
|
108
109
|
widget_name = camelize(filename)
|
109
110
|
widget_class = constantize(widget_name)
|
@@ -124,6 +125,7 @@ module Erector
|
|
124
125
|
rescue => e
|
125
126
|
puts e
|
126
127
|
puts e.backtrace.join("\n\t")
|
128
|
+
@success = false
|
127
129
|
end
|
128
130
|
end
|
129
131
|
end
|
data/lib/erector/erected.rb
CHANGED
@@ -6,6 +6,7 @@ Treetop.load("#{dir}/rhtml.treetop")
|
|
6
6
|
|
7
7
|
module Erector
|
8
8
|
class Erected
|
9
|
+
|
9
10
|
def initialize(in_file)
|
10
11
|
@in_file = in_file
|
11
12
|
end
|
@@ -14,14 +15,23 @@ module Erector
|
|
14
15
|
dir + basename + ".rb"
|
15
16
|
end
|
16
17
|
|
17
|
-
def
|
18
|
+
def classnames
|
18
19
|
base = classize(basename)
|
19
20
|
parent = File.dirname(@in_file)
|
20
21
|
grandparent = File.dirname(parent)
|
21
22
|
if File.basename(grandparent) == "views"
|
22
|
-
|
23
|
+
["Views::" + classize(File.basename(parent)) + "::" + base, "Erector::RailsWidget"]
|
24
|
+
else
|
25
|
+
[base, "Erector::Widget"]
|
23
26
|
end
|
24
|
-
|
27
|
+
end
|
28
|
+
|
29
|
+
def classname
|
30
|
+
classnames[0]
|
31
|
+
end
|
32
|
+
|
33
|
+
def parent_class
|
34
|
+
classnames[1]
|
25
35
|
end
|
26
36
|
|
27
37
|
def text
|
@@ -36,7 +46,7 @@ module Erector
|
|
36
46
|
parser.failure_reason
|
37
47
|
else
|
38
48
|
File.open(filename, "w") do |f|
|
39
|
-
f.puts("class #{classname} <
|
49
|
+
f.puts("class #{classname} < #{parent_class}")
|
40
50
|
f.puts(" def content")
|
41
51
|
f.puts(parsed.set_indent(2).convert)
|
42
52
|
f.puts(" end")
|
data/lib/erector/rhtml.treetop
CHANGED
@@ -13,7 +13,35 @@ grammar Rhtml
|
|
13
13
|
end
|
14
14
|
|
15
15
|
rule node
|
16
|
-
hprintlet / printlet / scriptlet / doctype / self_closing_tag / imgtag / closetag / opentag / text
|
16
|
+
yield_with_name / yield / hprintlet / printlet / scriptlet / doctype / directive / self_closing_tag / imgtag / closetag / opentag / text
|
17
|
+
end
|
18
|
+
|
19
|
+
# Argh. For some reason I can't get this to work, so I split it into two rules
|
20
|
+
# rule yield
|
21
|
+
# '<%=' space 'yield' space (':' varname space)? '%>' <Erector::Indenting> {
|
22
|
+
# def convert
|
23
|
+
# var = "@content_for_" + varname.nil? ? "layout" : varname.text_value
|
24
|
+
# line "rawtext #{var} # Note: you must define #{var} elsewhere"
|
25
|
+
# end
|
26
|
+
# }
|
27
|
+
# end
|
28
|
+
|
29
|
+
rule yield_with_name
|
30
|
+
'<%=' space 'yield' space ':' varname space '%>' <Erector::Indenting> {
|
31
|
+
def convert
|
32
|
+
var = "@content_for_" + varname.text_value
|
33
|
+
line "rawtext #{var} # Note: you must define #{var} elsewhere"
|
34
|
+
end
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
rule yield
|
39
|
+
'<%=' space 'yield' space '%>' <Erector::Indenting> {
|
40
|
+
def convert
|
41
|
+
var = "@content_for_layout"
|
42
|
+
line "rawtext #{var} # Note: you must define #{var} elsewhere"
|
43
|
+
end
|
44
|
+
}
|
17
45
|
end
|
18
46
|
|
19
47
|
rule scriptlet
|
@@ -53,10 +81,6 @@ grammar Rhtml
|
|
53
81
|
code = text_value.strip
|
54
82
|
# matches a word, followed by either a word, a string, or a symbol
|
55
83
|
result = code.gsub(/^(\w+) ([\w:"'].*)$/, '\1(\2)')
|
56
|
-
|
57
|
-
# Convert yield, for layouts
|
58
|
-
#result.gsub!(/^yield$/, '@content')
|
59
|
-
|
60
84
|
result
|
61
85
|
end
|
62
86
|
}
|
@@ -69,15 +93,27 @@ grammar Rhtml
|
|
69
93
|
end
|
70
94
|
}
|
71
95
|
end
|
96
|
+
|
97
|
+
rule directive
|
98
|
+
'<!' [^>]* '>' <Erector::Indenting> {
|
99
|
+
def convert
|
100
|
+
line "rawtext '#{text_value}'"
|
101
|
+
end
|
102
|
+
}
|
103
|
+
end
|
72
104
|
|
73
105
|
rule tagname
|
74
106
|
[A-Za-z0-9_:-]+
|
75
107
|
end
|
108
|
+
|
109
|
+
rule varname
|
110
|
+
[A-Za-z0-9_]+
|
111
|
+
end
|
76
112
|
|
77
113
|
rule self_closing_tag
|
78
114
|
'<' tag_name:tagname attrs:attributes? space '/>' <Erector::Indenting> {
|
79
115
|
def convert
|
80
|
-
line "#{tag_name.text_value}#{attrs.
|
116
|
+
line "#{tag_name.text_value}#{attrs.empty? ? "" : attrs.convert}"
|
81
117
|
end
|
82
118
|
}
|
83
119
|
end
|
@@ -85,7 +121,7 @@ grammar Rhtml
|
|
85
121
|
rule opentag
|
86
122
|
'<' tag_name:tagname attrs:attributes? space '>' <Erector::Indenting> {
|
87
123
|
def convert
|
88
|
-
line_in "#{tag_name.text_value}#{attrs.
|
124
|
+
line_in "#{tag_name.text_value}#{attrs.empty? ? "" : attrs.convert} do"
|
89
125
|
end
|
90
126
|
}
|
91
127
|
end
|
@@ -93,7 +129,7 @@ grammar Rhtml
|
|
93
129
|
rule imgtag
|
94
130
|
'<' tag_name:'img' attrs:attributes? space '>' <Erector::Indenting> {
|
95
131
|
def convert
|
96
|
-
line "#{tag_name.text_value}#{attrs.
|
132
|
+
line "#{tag_name.text_value}#{attrs.empty? ? "" : attrs.convert}"
|
97
133
|
end
|
98
134
|
}
|
99
135
|
end
|
@@ -110,10 +146,11 @@ grammar Rhtml
|
|
110
146
|
(([<>] !(tagname / [/%!])) / [^<>])+ <Erector::Indenting> {
|
111
147
|
def convert
|
112
148
|
stripped = text_value.strip
|
113
|
-
if stripped.
|
149
|
+
if stripped.empty?
|
114
150
|
""
|
115
151
|
else
|
116
|
-
line "text '#{
|
152
|
+
line "text '#{stripped.html_unescape.gsub(/\'/, "\\\\'")
|
153
|
+
}'"
|
117
154
|
end
|
118
155
|
end
|
119
156
|
}
|
@@ -123,7 +160,7 @@ grammar Rhtml
|
|
123
160
|
first:attribute rest:attributes* {
|
124
161
|
def convert
|
125
162
|
" " + first.convert +
|
126
|
-
if rest.
|
163
|
+
if rest.empty?
|
127
164
|
""
|
128
165
|
else
|
129
166
|
",#{rest.elements.first.convert}" # this is hacky -- is there a better way?
|