erector 0.9.0 → 0.10.0
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/Gemfile +2 -1
- data/README.txt +1 -1
- data/Rakefile +30 -18
- data/VERSION.yml +1 -1
- data/lib/erector/abstract_widget.rb +10 -0
- data/lib/erector/html_widget.rb +20 -20
- data/lib/erector/needs.rb +10 -2
- data/lib/erector/promise.rb +4 -0
- data/lib/erector/rails3.rb +10 -0
- data/lib/erector/sass.rb +5 -1
- data/lib/erector/widgets/table.rb +5 -12
- data/spec/erect/erect_rails_spec.rb +3 -3
- data/spec/erector/convenience_spec.rb +1 -1
- data/spec/erector/hello_from_readme_spec.rb +2 -2
- data/spec/erector/html_spec.rb +35 -1
- data/spec/erector/indentation_spec.rb +1 -1
- data/spec/erector/needs_spec.rb +10 -1
- data/spec/erector/sass_spec.rb +36 -12
- data/spec/rails2/rails_app/log/test.log +1134 -0
- data/spec/rails_root/app/views/layouts/erb_as_layout.html.erb +2 -0
- data/spec/rails_root/app/views/layouts/widget_as_layout.rb +2 -2
- data/spec/rails_root/app/views/test/render_default_erb_with_layout.html.erb +1 -0
- data/spec/rails_root/app/views/test/render_default_widget_with_layout.html.rb +5 -0
- data/spec/rails_root/config/environments/test.rb +1 -1
- data/spec/rails_root/log/test.log +1164 -0
- data/spec/rails_root/spec/rails_helpers_spec.rb +23 -15
- data/spec/rails_root/spec/rails_widget_spec.rb +3 -3
- data/spec/rails_root/spec/render_spec.rb +90 -47
- metadata +58 -69
- data/spec/rails_root/app/views/layouts/application.html.erb +0 -14
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b29fc352efeac52d0d2dfbf8b1be475a80b1e62b
|
4
|
+
data.tar.gz: 16d464024312c7186a63ae9d965891f3493e89bb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c1981c778c0f399282a0cab3ad6fdd3d5dd1de0aeb4f9890db0125049d4ffebaba1dd5608b4e4c334d73dbdde382c7651a2eae41bec730444fb1798cf2a6dc64
|
7
|
+
data.tar.gz: 5919bae5734c2284d59e96eb194ac10115cc86323fd8249fd4e64ba4d5809ec01db83635d4c890b83b8775d76200fce8262136aeef721681e46672a6b05f9e65
|
data/Gemfile
CHANGED
@@ -3,6 +3,7 @@ source "http://rubygems.org"
|
|
3
3
|
gem "treetop", ">= 1.2.3"
|
4
4
|
|
5
5
|
group :development do
|
6
|
+
gem "rake", "~>10.0.1"
|
6
7
|
gem "activesupport", "~>3"
|
7
8
|
gem "rspec", "~>2"
|
8
9
|
gem "rubyforge"
|
@@ -13,7 +14,7 @@ group :development do
|
|
13
14
|
gem "sass"
|
14
15
|
gem "erubis"
|
15
16
|
gem "rdoc", "~> 3.4"
|
16
|
-
gem "wrong", ">=0.
|
17
|
+
gem "wrong", ">=0.6.3"
|
17
18
|
end
|
18
19
|
|
19
20
|
group :rails do
|
data/README.txt
CHANGED
data/Rakefile
CHANGED
@@ -102,11 +102,13 @@ task :publish => [:web, :docs] do
|
|
102
102
|
rdoc_dir = "rdoc"
|
103
103
|
rsync_args = '--archive --verbose --delete'
|
104
104
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
105
|
+
# TODO: publish site to gh-pages
|
106
|
+
# puts "== Publishing web site to RubyForge"
|
107
|
+
# sh %{rsync #{rsync_args} --exclude=#{rdoc_dir} #{local_dir}/ #{host}:#{remote_dir}}
|
108
|
+
#
|
109
|
+
# TODO: publish docs to gh-pages
|
110
|
+
# puts "== Publishing rdoc to RubyForge"
|
111
|
+
# sh %{rsync #{rsync_args} #{rdoc_dir}/ #{host}:#{remote_dir}/rdoc}
|
110
112
|
end
|
111
113
|
|
112
114
|
|
@@ -158,27 +160,37 @@ namespace :spec do
|
|
158
160
|
spec.pattern = 'spec/erect/*_spec.rb'
|
159
161
|
end
|
160
162
|
|
161
|
-
|
162
|
-
|
163
|
-
RSpec::Core::RakeTask.new(:rails) do |spec|
|
163
|
+
desc "Run specs for erector's Rails 3 integration."
|
164
|
+
RSpec::Core::RakeTask.new(:integration_rails3) do |spec|
|
164
165
|
spec.pattern = 'spec/rails_root/spec/*_spec.rb'
|
165
166
|
end
|
166
167
|
|
167
|
-
desc "Run specs for erector's Rails integration
|
168
|
+
desc "Run specs for erector's Rails 2 integration."
|
169
|
+
RSpec::Core::RakeTask.new(:integration_rails2) do |spec|
|
170
|
+
spec.pattern = 'spec/rails2/rails_app/spec/*_spec.rb'
|
171
|
+
end
|
172
|
+
|
173
|
+
def prepare_gemfile gemfile
|
174
|
+
Bundler.with_clean_env { sh "bundle check --gemfile #{gemfile} || bundle install --gemfile #{gemfile}" }
|
175
|
+
end
|
176
|
+
|
177
|
+
desc "Run specs for erector's Rails integration under Rails 2. - prepare with 'bundle install --gemfile Gemfile-rails2"
|
168
178
|
task :rails2 do
|
169
|
-
|
170
|
-
|
171
|
-
Dir.chdir(rails_app) do
|
172
|
-
# Bundler.with_clean_env do
|
173
|
-
sh "BUNDLE_GEMFILE='#{gemfile}' bundle exec rake rails2"
|
174
|
-
# end
|
175
|
-
end
|
179
|
+
gemfile = "#{here}/Gemfile-rails2"
|
180
|
+
sh "BUNDLE_GEMFILE='#{gemfile}' bundle exec rake spec:core spec:integration_rails2"
|
176
181
|
end
|
177
182
|
|
178
183
|
desc "Run all specs under Rails 3.1 - prepare with 'bundle install --gemfile Gemfile-rails31'"
|
179
184
|
task :rails31 do
|
180
185
|
gemfile = "#{here}/Gemfile-rails31"
|
181
|
-
sh "BUNDLE_GEMFILE='#{gemfile}' bundle exec rake spec:core spec:erect spec:
|
186
|
+
sh "BUNDLE_GEMFILE='#{gemfile}' bundle exec rake spec:core spec:erect spec:integration_rails3"
|
187
|
+
end
|
188
|
+
|
189
|
+
desc "Run all specs under latest Rails - prepare with 'bundle install --gemfile Gemfile-rails'"
|
190
|
+
task :rails do
|
191
|
+
gemfile = "#{here}/Gemfile-rails"
|
192
|
+
prepare_gemfile gemfile
|
193
|
+
sh "BUNDLE_GEMFILE='#{gemfile}' bundle exec rake spec:core spec:erect spec:integration_rails3"
|
182
194
|
end
|
183
195
|
|
184
196
|
desc "Run specs for the Erector web site."
|
@@ -189,4 +201,4 @@ namespace :spec do
|
|
189
201
|
end
|
190
202
|
|
191
203
|
desc "Run most specs"
|
192
|
-
task :spec => ['spec:
|
204
|
+
task :spec => ['spec:rails', 'spec:rails2', 'spec:web']
|
data/VERSION.yml
CHANGED
@@ -33,6 +33,16 @@ module Erector
|
|
33
33
|
@@prettyprint_default = enabled
|
34
34
|
end
|
35
35
|
|
36
|
+
@@hyphenize_underscores = false
|
37
|
+
|
38
|
+
def self.hyphenize_underscores
|
39
|
+
@@hyphenize_underscores
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.hyphenize_underscores=(enabled)
|
43
|
+
@@hyphenize_underscores = enabled
|
44
|
+
end
|
45
|
+
|
36
46
|
def self.inline(*args, &block)
|
37
47
|
Class.new(self) do
|
38
48
|
include Erector::Inline
|
data/lib/erector/html_widget.rb
CHANGED
@@ -77,25 +77,25 @@ module Erector
|
|
77
77
|
tag 'param', :self_closing
|
78
78
|
|
79
79
|
tag 'a', :inline
|
80
|
-
tag 'abbr'
|
81
|
-
tag 'acronym'
|
80
|
+
tag 'abbr', :inline
|
81
|
+
tag 'acronym', :inline
|
82
82
|
tag 'address'
|
83
83
|
tag 'article'
|
84
84
|
tag 'aside'
|
85
85
|
tag 'audio'
|
86
86
|
|
87
87
|
tag 'b', :inline
|
88
|
-
tag 'bdo'
|
89
|
-
tag 'big'
|
88
|
+
tag 'bdo', :inline
|
89
|
+
tag 'big', :inline
|
90
90
|
tag 'blockquote'
|
91
91
|
tag 'body'
|
92
92
|
tag 'button', :inline
|
93
93
|
|
94
94
|
tag 'canvas'
|
95
|
-
tag 'caption'
|
95
|
+
tag 'caption', :inline
|
96
96
|
tag 'center'
|
97
|
-
tag 'cite'
|
98
|
-
tag 'code'
|
97
|
+
tag 'cite', :inline
|
98
|
+
tag 'code', :inline
|
99
99
|
tag 'colgroup'
|
100
100
|
tag 'command'
|
101
101
|
|
@@ -103,13 +103,13 @@ module Erector
|
|
103
103
|
tag 'dd'
|
104
104
|
tag 'del'
|
105
105
|
tag 'details'
|
106
|
-
tag 'dfn'
|
106
|
+
tag 'dfn', :inline
|
107
107
|
tag 'dialog'
|
108
108
|
tag 'div'
|
109
109
|
tag 'dl'
|
110
|
-
tag 'dt'
|
110
|
+
tag 'dt', :inline
|
111
111
|
|
112
|
-
tag 'em'
|
112
|
+
tag 'em', :inline
|
113
113
|
|
114
114
|
tag 'fieldset'
|
115
115
|
tag 'figure'
|
@@ -132,9 +132,9 @@ module Erector
|
|
132
132
|
tag 'iframe'
|
133
133
|
tag 'ins'
|
134
134
|
tag 'keygen'
|
135
|
-
tag 'kbd'
|
136
|
-
tag 'label'
|
137
|
-
tag 'legend'
|
135
|
+
tag 'kbd', :inline
|
136
|
+
tag 'label', :inline
|
137
|
+
tag 'legend', :inline
|
138
138
|
tag 'li'
|
139
139
|
|
140
140
|
tag 'map'
|
@@ -154,13 +154,13 @@ module Erector
|
|
154
154
|
tag 'pre'
|
155
155
|
tag 'progress'
|
156
156
|
|
157
|
-
tag 'q'
|
157
|
+
tag 'q', :inline
|
158
158
|
tag 'ruby'
|
159
159
|
tag 'rt'
|
160
160
|
tag 'rp'
|
161
161
|
tag 's'
|
162
162
|
|
163
|
-
tag 'samp'
|
163
|
+
tag 'samp', :inline
|
164
164
|
tag 'script'
|
165
165
|
tag 'section'
|
166
166
|
tag 'select', :inline
|
@@ -169,10 +169,10 @@ module Erector
|
|
169
169
|
tag 'span', :inline
|
170
170
|
tag 'strike'
|
171
171
|
|
172
|
-
tag 'strong'
|
172
|
+
tag 'strong', :inline
|
173
173
|
tag 'style'
|
174
|
-
tag 'sub'
|
175
|
-
tag 'sup'
|
174
|
+
tag 'sub', :inline
|
175
|
+
tag 'sup', :inline
|
176
176
|
|
177
177
|
tag 'table'
|
178
178
|
tag 'tbody'
|
@@ -185,12 +185,12 @@ module Erector
|
|
185
185
|
tag 'time'
|
186
186
|
tag 'title'
|
187
187
|
tag 'tr'
|
188
|
-
tag 'tt'
|
188
|
+
tag 'tt', :inline
|
189
189
|
|
190
190
|
tag 'u'
|
191
191
|
tag 'ul'
|
192
192
|
|
193
|
-
tag 'var'
|
193
|
+
tag 'var', :inline
|
194
194
|
tag 'video'
|
195
195
|
|
196
196
|
|
data/lib/erector/needs.rb
CHANGED
@@ -65,6 +65,14 @@ module Erector
|
|
65
65
|
def needs?(name)
|
66
66
|
needed_variables.empty? || needed_variables.include?(name)
|
67
67
|
end
|
68
|
+
|
69
|
+
def ignore_extra_assigns
|
70
|
+
@ignore_extra_assigns ||= false
|
71
|
+
end
|
72
|
+
|
73
|
+
def ignore_extra_assigns=(new_value)
|
74
|
+
@ignore_extra_assigns = (new_value ? :true : :false)
|
75
|
+
end
|
68
76
|
end
|
69
77
|
|
70
78
|
def initialize(assigns = {})
|
@@ -75,7 +83,7 @@ module Erector
|
|
75
83
|
# set variables with default values
|
76
84
|
self.class.needed_defaults.each do |name, value|
|
77
85
|
unless assigned.include?(name)
|
78
|
-
value = [NilClass, FalseClass, TrueClass, Fixnum, Float].include?(value.class) ? value : value.dup
|
86
|
+
value = [NilClass, FalseClass, TrueClass, Fixnum, Float, Symbol].include?(value.class) ? value : value.dup
|
79
87
|
instance_variable_set("@#{name}", value)
|
80
88
|
assigned << name
|
81
89
|
end
|
@@ -87,7 +95,7 @@ module Erector
|
|
87
95
|
end
|
88
96
|
|
89
97
|
excess = assigned - self.class.needed_variables
|
90
|
-
unless self.class.needed_variables.empty? || excess.empty?
|
98
|
+
unless self.class.needed_variables.empty? || excess.empty? || self.class.ignore_extra_assigns
|
91
99
|
raise ArgumentError, "Excess parameter#{excess.size == 1 ? '' : 's'} for #{self.class.name}: #{excess.join(', ')}"
|
92
100
|
end
|
93
101
|
end
|
data/lib/erector/promise.rb
CHANGED
@@ -84,6 +84,10 @@ module Erector
|
|
84
84
|
|
85
85
|
def method_missing(method_name, *args, &block)
|
86
86
|
method_name = method_name.to_s
|
87
|
+
if Erector::Widget.hyphenize_underscores
|
88
|
+
method_name = method_name.gsub(/_/, "-")
|
89
|
+
end
|
90
|
+
|
87
91
|
if method_name =~ /\!$/
|
88
92
|
id_str = method_name[0...-1]
|
89
93
|
raise ArgumentError, "setting id #{id_str} but id #{@attributes["id"]} already present" if @attributes["id"]
|
data/lib/erector/rails3.rb
CHANGED
@@ -120,6 +120,16 @@ module Erector
|
|
120
120
|
rawtext(captured)
|
121
121
|
end
|
122
122
|
|
123
|
+
# Rails content_for is output if and only if no block given
|
124
|
+
def content_for(*args,&block)
|
125
|
+
if block
|
126
|
+
helpers.content_for(*args,&block)
|
127
|
+
else
|
128
|
+
rawtext(helpers.content_for(*args))
|
129
|
+
''
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
123
133
|
# Delegate to non-markup producing helpers via method_missing,
|
124
134
|
# returning their result directly.
|
125
135
|
def method_missing(name, *args, &block)
|
data/lib/erector/sass.rb
CHANGED
@@ -8,6 +8,10 @@ module Erector
|
|
8
8
|
# Current support is barebones. Please offer suggestions (or better
|
9
9
|
# yet, patches) for whether and how to support, e.g., caching,
|
10
10
|
# loading from files, precompilation, etc.
|
11
|
+
#
|
12
|
+
# It seems to me that SASS/SCSS should be part of the Page widget, which
|
13
|
+
# would allow all the little style snippets to be compiled together
|
14
|
+
# and appear in the document HEAD.
|
11
15
|
module Sass
|
12
16
|
def sass(arg, options = {})
|
13
17
|
require "sass"
|
@@ -20,7 +24,7 @@ module Erector
|
|
20
24
|
end
|
21
25
|
style raw(::Sass.compile(sass_text, options))
|
22
26
|
end
|
23
|
-
|
27
|
+
|
24
28
|
def scss(arg, options = {})
|
25
29
|
sass arg, {:syntax => :scss}.merge(options)
|
26
30
|
end
|
@@ -1,15 +1,11 @@
|
|
1
|
-
|
2
|
-
require "active_support/inflector"
|
3
|
-
|
4
|
-
module Erector
|
1
|
+
module Erector
|
5
2
|
module Widgets #:nodoc:
|
6
|
-
|
7
|
-
|
8
|
-
# The Table widget provides the ability to render a table from a
|
3
|
+
# The Table widget provides the ability to render a table from a
|
9
4
|
# list of objects (one for each row).
|
10
5
|
#
|
11
6
|
# Because the default for the column titles utilizes the ActiveSupport
|
12
|
-
# Inflector#titleize method, this widget requires active_support to be loaded
|
7
|
+
# Inflector#titleize method, this widget requires active_support to be loaded
|
8
|
+
# (or some other gem that adds `titleize` to String).
|
13
9
|
#
|
14
10
|
# class UsersTable < Erector::Widgets::Table
|
15
11
|
# column :first_name
|
@@ -26,7 +22,7 @@ begin
|
|
26
22
|
# that the user sees) and a block which renders the cell given
|
27
23
|
# a row object. If the block is not specified, the cell contains
|
28
24
|
# the result of calling a method whose name is id.
|
29
|
-
#
|
25
|
+
#
|
30
26
|
# The name can be a string or a proc.
|
31
27
|
def column(id, name=id.to_s.titleize, &cell_proc)
|
32
28
|
cell_proc ||= proc {|object| text object.__send__(id)}
|
@@ -98,7 +94,4 @@ begin
|
|
98
94
|
end
|
99
95
|
end
|
100
96
|
end
|
101
|
-
end
|
102
|
-
rescue LoadError => e
|
103
|
-
$stderr.puts "Erector::Widgets::Table requires active_support"
|
104
97
|
end
|
@@ -42,9 +42,9 @@ unless Dir.respond_to?(:mktmpdir)
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
# Note: this is *not* inside the rails_root since we're not testing
|
45
|
+
# Note: this is *not* inside the rails_root since we're not testing
|
46
46
|
# Erector inside a rails app. We're testing that we can use the command-line
|
47
|
-
# converter tool on a newly generated scaffold app (like we brag about in the
|
47
|
+
# converter tool on a newly generated scaffold app (like we brag about in the
|
48
48
|
# user guide).
|
49
49
|
#
|
50
50
|
describe "the 'erector' command" do
|
@@ -87,7 +87,7 @@ describe "the 'erector' command" do
|
|
87
87
|
run "BUNDLE_GEMFILE=./Gemfile bundle exec #{erector_dir}/bin/erector ./app/views/posts"
|
88
88
|
|
89
89
|
FileUtils.rm_f("app/views/posts/*.erb")
|
90
|
-
run "BUNDLE_GEMFILE=./Gemfile bundle exec rake
|
90
|
+
run "BUNDLE_GEMFILE=./Gemfile bundle exec rake db:migrate"
|
91
91
|
|
92
92
|
# run "script/server" # todo: launch in background; use mechanize or something to crawl it; then kill it
|
93
93
|
# perhaps use open4?
|
@@ -212,7 +212,7 @@ describe Erector::Convenience do
|
|
212
212
|
it "accepts extra attributes" do
|
213
213
|
erector do
|
214
214
|
url "http://example.com", :onclick=>"alert('foo')"
|
215
|
-
end.should == "<a href=\"http://example.com\" onclick=\"alert(
|
215
|
+
end.should == "<a href=\"http://example.com\" onclick=\"alert('foo')\">http://example.com</a>"
|
216
216
|
end
|
217
217
|
|
218
218
|
end
|
@@ -3,9 +3,9 @@ require File.expand_path("#{here}/../spec_helper")
|
|
3
3
|
|
4
4
|
describe "Hello World example from README" do
|
5
5
|
it "works" do
|
6
|
-
Dir.chdir(
|
6
|
+
Dir.chdir('/tmp') do
|
7
7
|
clear_bundler_env
|
8
|
-
html =
|
8
|
+
html = `ruby #{File.join(here,'hello_from_readme.rb')} 2>&1`
|
9
9
|
html.should == "<html><head><title>Welcome page</title></head><body><p>Hello, world</p></body></html>\n"
|
10
10
|
end
|
11
11
|
end
|
data/spec/erector/html_spec.rb
CHANGED
@@ -77,6 +77,40 @@ describe Erector::HTML do
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
+
context "with underscored attributes" do
|
81
|
+
context "without hyphenize_underscores" do
|
82
|
+
it "keeps class names as underscored" do
|
83
|
+
erector do
|
84
|
+
empty_element('foo').max_thingie
|
85
|
+
end.should == '<foo class="max_thingie" />'
|
86
|
+
end
|
87
|
+
|
88
|
+
it "also keeps classes specified as attributes as underscored" do
|
89
|
+
erector do
|
90
|
+
empty_element('foo', :class => "max_thingie")
|
91
|
+
end.should == '<foo class="max_thingie" />'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context "with hyphenize_underscores" do
|
96
|
+
before do
|
97
|
+
Erector::Widget.hyphenize_underscores = true
|
98
|
+
end
|
99
|
+
|
100
|
+
it "turns underscores in class names into hyphens" do
|
101
|
+
erector do
|
102
|
+
empty_element('foo').max_thingie
|
103
|
+
end.should == '<foo class="max-thingie" />'
|
104
|
+
end
|
105
|
+
|
106
|
+
it "lets you pick underscores or hyphens when specifying a class as an attribute" do
|
107
|
+
erector do
|
108
|
+
empty_element('foo', :class => "max_thingie")
|
109
|
+
end.should == '<foo class="max_thingie" />'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
80
114
|
context "with inner tags" do
|
81
115
|
it "returns nested tags" do
|
82
116
|
erector do
|
@@ -394,7 +428,7 @@ describe Erector::HTML do
|
|
394
428
|
|
395
429
|
describe 'escaping' do
|
396
430
|
plain = 'if (x < y && x > z) alert("don\'t stop");'
|
397
|
-
escaped = "if (x < y && x > z) alert("don
|
431
|
+
escaped = "if (x < y && x > z) alert("don't stop");"
|
398
432
|
|
399
433
|
describe "#text" do
|
400
434
|
it "does HTML escape its param" do
|