convert_theme 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +12 -0
- data/Manifest.txt +0 -20
- data/README.rdoc +1 -1
- data/lib/convert_theme.rb +41 -13
- data/lib/convert_theme/cli.rb +3 -3
- data/spec/convert_theme_cli_spec.rb +2 -1
- data/spec/convert_theme_spec.rb +30 -26
- data/spec/expected/rails/bloganje/app/views/layouts/application.html.erb +1 -34
- metadata +1 -21
- data/spec/expected/rails/bloganje/script/about +0 -4
- data/spec/expected/rails/bloganje/script/console +0 -3
- data/spec/expected/rails/bloganje/script/dbconsole +0 -3
- data/spec/expected/rails/bloganje/script/destroy +0 -3
- data/spec/expected/rails/bloganje/script/generate +0 -3
- data/spec/expected/rails/bloganje/script/performance/benchmarker +0 -3
- data/spec/expected/rails/bloganje/script/performance/profiler +0 -3
- data/spec/expected/rails/bloganje/script/plugin +0 -3
- data/spec/expected/rails/bloganje/script/runner +0 -3
- data/spec/expected/rails/bloganje/script/server +0 -3
- data/spec/expected/rails/webresourcedepot/script/about +0 -4
- data/spec/expected/rails/webresourcedepot/script/console +0 -3
- data/spec/expected/rails/webresourcedepot/script/dbconsole +0 -3
- data/spec/expected/rails/webresourcedepot/script/destroy +0 -3
- data/spec/expected/rails/webresourcedepot/script/generate +0 -3
- data/spec/expected/rails/webresourcedepot/script/performance/benchmarker +0 -3
- data/spec/expected/rails/webresourcedepot/script/performance/profiler +0 -3
- data/spec/expected/rails/webresourcedepot/script/plugin +0 -3
- data/spec/expected/rails/webresourcedepot/script/runner +0 -3
- data/spec/expected/rails/webresourcedepot/script/server +0 -3
data/History.txt
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
=== 0.3.1 / 2009-09-27
|
2
|
+
|
3
|
+
Major:
|
4
|
+
* Display sample Ruby for how to use the named yields inserted into the layout.
|
5
|
+
|
6
|
+
Minor:
|
7
|
+
* Include sample for the automatically included <%= yield(:head) %>
|
8
|
+
* passing target rails path into #new instead of #apply_to; which is renamed to #apply_to_target
|
9
|
+
* More spec cleanup
|
10
|
+
* remove script folder from expected rails apps; not required
|
11
|
+
* minor refactoring of specs
|
12
|
+
|
1
13
|
=== 0.3.0 / 2009-09-27
|
2
14
|
|
3
15
|
Major:
|
data/Manifest.txt
CHANGED
@@ -154,16 +154,6 @@ spec/expected/rails/bloganje/public/stylesheets/theme1.css
|
|
154
154
|
spec/expected/rails/bloganje/public/stylesheets/theme2.css
|
155
155
|
spec/expected/rails/bloganje/public/stylesheets/theme3.css
|
156
156
|
spec/expected/rails/bloganje/public/stylesheets/theme4.css
|
157
|
-
spec/expected/rails/bloganje/script/about
|
158
|
-
spec/expected/rails/bloganje/script/console
|
159
|
-
spec/expected/rails/bloganje/script/dbconsole
|
160
|
-
spec/expected/rails/bloganje/script/destroy
|
161
|
-
spec/expected/rails/bloganje/script/generate
|
162
|
-
spec/expected/rails/bloganje/script/performance/benchmarker
|
163
|
-
spec/expected/rails/bloganje/script/performance/profiler
|
164
|
-
spec/expected/rails/bloganje/script/plugin
|
165
|
-
spec/expected/rails/bloganje/script/runner
|
166
|
-
spec/expected/rails/bloganje/script/server
|
167
157
|
spec/expected/rails/bloganje/test/performance/browsing_test.rb
|
168
158
|
spec/expected/rails/bloganje/test/test_helper.rb
|
169
159
|
spec/expected/rails/webresourcedepot/README
|
@@ -224,16 +214,6 @@ spec/expected/rails/webresourcedepot/public/javascripts/effects.js
|
|
224
214
|
spec/expected/rails/webresourcedepot/public/javascripts/prototype.js
|
225
215
|
spec/expected/rails/webresourcedepot/public/robots.txt
|
226
216
|
spec/expected/rails/webresourcedepot/public/stylesheets/all.css
|
227
|
-
spec/expected/rails/webresourcedepot/script/about
|
228
|
-
spec/expected/rails/webresourcedepot/script/console
|
229
|
-
spec/expected/rails/webresourcedepot/script/dbconsole
|
230
|
-
spec/expected/rails/webresourcedepot/script/destroy
|
231
|
-
spec/expected/rails/webresourcedepot/script/generate
|
232
|
-
spec/expected/rails/webresourcedepot/script/performance/benchmarker
|
233
|
-
spec/expected/rails/webresourcedepot/script/performance/profiler
|
234
|
-
spec/expected/rails/webresourcedepot/script/plugin
|
235
|
-
spec/expected/rails/webresourcedepot/script/runner
|
236
|
-
spec/expected/rails/webresourcedepot/script/server
|
237
217
|
spec/expected/rails/webresourcedepot/test/performance/browsing_test.rb
|
238
218
|
spec/expected/rails/webresourcedepot/test/test_helper.rb
|
239
219
|
spec/fixtures/bloganje/README.md
|
data/README.rdoc
CHANGED
@@ -23,7 +23,7 @@ Replace some DOM content with <%= yield :some_label %> with --inside_yields:
|
|
23
23
|
|
24
24
|
convert_theme path/to/app path/to/rails_app content_box \
|
25
25
|
"--inside_yield=header=>#header h2" \
|
26
|
-
--inside_yield=sidebar=>#sidebar
|
26
|
+
"--inside_yield=sidebar=>#sidebar"
|
27
27
|
|
28
28
|
== INSTALL:
|
29
29
|
|
data/lib/convert_theme.rb
CHANGED
@@ -1,19 +1,23 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require 'hpricot'
|
5
|
+
require 'rubigen'
|
6
6
|
require 'rubigen/scripts/generate'
|
7
7
|
|
8
8
|
class ConvertTheme
|
9
|
-
VERSION = "0.3.
|
9
|
+
VERSION = "0.3.1"
|
10
10
|
|
11
|
-
attr_reader :template_root, :
|
11
|
+
attr_reader :template_root, :rails_root, :index_path, :template_type
|
12
12
|
attr_reader :stylesheet_dir, :javascript_dir, :image_dir
|
13
13
|
attr_reader :content_id, :inside_yields
|
14
|
+
attr_reader :stdout
|
15
|
+
attr_reader :inside_yields_originals
|
14
16
|
|
15
17
|
def initialize(options = {})
|
16
18
|
@template_root = File.expand_path(options[:template_root] || File.dirname('.'))
|
19
|
+
@rails_root = File.expand_path(options[:rails_root] || File.dirname('.'))
|
20
|
+
@template_type = (options[:template_type] || detect_template).to_s
|
17
21
|
@index_path = options[:index_path] || "index.html"
|
18
22
|
@content_id = options[:content_id] || "content"
|
19
23
|
@inside_yields = options[:inside_yields] || {}
|
@@ -25,13 +29,13 @@ class ConvertTheme
|
|
25
29
|
setup_template_temp_path
|
26
30
|
end
|
27
31
|
|
28
|
-
def
|
29
|
-
@
|
30
|
-
@
|
31
|
-
|
32
|
+
def apply_to_target(options = {})
|
33
|
+
@stdout = options[:stdout] || @stdout || $stdout
|
34
|
+
@inside_yields_originals = {}
|
32
35
|
convert_file_to_layout(index_path, 'app/views/layouts/application.html.erb')
|
33
36
|
prepare_assets
|
34
37
|
run_generator(options)
|
38
|
+
show_readme
|
35
39
|
end
|
36
40
|
|
37
41
|
# This generator's templates folder is temporary
|
@@ -67,7 +71,10 @@ class ConvertTheme
|
|
67
71
|
doc = Hpricot(index_file)
|
68
72
|
doc.search("##{content_id}").each { |elm| elm.inner_html = "<%= yield %>" }
|
69
73
|
inside_yields.to_a.each do |name, css_path|
|
70
|
-
doc.search(css_path).each
|
74
|
+
doc.search(css_path).each do |elm|
|
75
|
+
inside_yields_originals[name] = elm.inner_html.strip
|
76
|
+
elm.inner_html = "<%= yield(:#{name}) %>"
|
77
|
+
end
|
71
78
|
end
|
72
79
|
contents = doc.to_html
|
73
80
|
contents.gsub!(%r{(["'])/?#{image_dir}}, '\1/images')
|
@@ -101,7 +108,7 @@ class ConvertTheme
|
|
101
108
|
RubiGen::Base.prepend_sources(RubiGen::PathSource.new(:internal, File.dirname(__FILE__)))
|
102
109
|
generator_options = options[:generator] || {}
|
103
110
|
generator_options.merge!(:stdout => @stdout, :no_exit => true,
|
104
|
-
:source => template_temp_path, :destination =>
|
111
|
+
:source => template_temp_path, :destination => rails_root)
|
105
112
|
RubiGen::Scripts::Generate.new.run(["convert_theme"], generator_options)
|
106
113
|
end
|
107
114
|
|
@@ -109,8 +116,8 @@ class ConvertTheme
|
|
109
116
|
FileUtils.chdir(template_root, &block)
|
110
117
|
end
|
111
118
|
|
112
|
-
def
|
113
|
-
FileUtils.chdir(
|
119
|
+
def in_rails_root(&block)
|
120
|
+
FileUtils.chdir(rails_root, &block)
|
114
121
|
end
|
115
122
|
|
116
123
|
def detect_template
|
@@ -122,7 +129,7 @@ class ConvertTheme
|
|
122
129
|
end
|
123
130
|
|
124
131
|
def detect_template_haml
|
125
|
-
|
132
|
+
in_rails_root do
|
126
133
|
return true if File.exist?('vendor/plugins/haml')
|
127
134
|
return true if File.exist?('config/environment.rb') && File.read('config/environment.rb') =~ /haml/
|
128
135
|
end
|
@@ -163,4 +170,25 @@ class ConvertTheme
|
|
163
170
|
def template_images
|
164
171
|
Dir[File.join(template_root, image_dir, '*')]
|
165
172
|
end
|
173
|
+
|
174
|
+
def show_readme
|
175
|
+
stdout.puts <<-README
|
176
|
+
|
177
|
+
Your theme has been installed into your app.
|
178
|
+
|
179
|
+
README
|
180
|
+
stdout.puts "You are using named yields. Here are examples how to use them: "
|
181
|
+
stdout.puts <<-EOS.gsub(/^ /, '')
|
182
|
+
<% content_for :head do -%>
|
183
|
+
<script>...</script>
|
184
|
+
<% end -%>
|
185
|
+
EOS
|
186
|
+
inside_yields_originals.to_a.each do |key, original_contents|
|
187
|
+
stdout.puts <<-EOS.gsub(/^ /, '')
|
188
|
+
<% content_for :#{key} do -%>
|
189
|
+
#{original_contents}
|
190
|
+
<% end -%>
|
191
|
+
EOS
|
192
|
+
end
|
193
|
+
end
|
166
194
|
end
|
data/lib/convert_theme/cli.rb
CHANGED
@@ -5,7 +5,7 @@ class ConvertTheme
|
|
5
5
|
def self.execute(stdout, arguments=[])
|
6
6
|
options = {}
|
7
7
|
options[:template_root] = arguments.shift
|
8
|
-
|
8
|
+
options[:rails_root] = arguments.shift
|
9
9
|
options[:content_id] = arguments.shift
|
10
10
|
parser = OptionParser.new do |opts|
|
11
11
|
opts.banner = <<-BANNER.gsub(/^ /,'')
|
@@ -32,10 +32,10 @@ class ConvertTheme
|
|
32
32
|
"Show this help message.") { stdout.puts opts; exit }
|
33
33
|
opts.parse!(arguments)
|
34
34
|
end
|
35
|
-
unless options[:template_root] &&
|
35
|
+
unless options[:template_root] && options[:rails_root]
|
36
36
|
stdout.puts parser; exit
|
37
37
|
end
|
38
|
-
ConvertTheme.new(options).
|
38
|
+
ConvertTheme.new(options).apply_to_target
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -6,13 +6,14 @@ describe ConvertTheme::CLI, "execute" do
|
|
6
6
|
theme = stub
|
7
7
|
ConvertTheme.should_receive(:new).
|
8
8
|
with(:template_root => "path/to/app",
|
9
|
+
:rails_root => "path/to/rails_app",
|
9
10
|
:content_id => "content_box",
|
10
11
|
:index_path => "root.html",
|
11
12
|
:template_type => "haml",
|
12
13
|
:inside_yields => { :header => '#header h2', :sidebar => '#sidebar' }
|
13
14
|
).
|
14
15
|
and_return(theme)
|
15
|
-
theme.should_receive(:
|
16
|
+
theme.should_receive(:apply_to_target)
|
16
17
|
@stdout = stdout do |stdout_io|
|
17
18
|
ConvertTheme::CLI.execute(stdout_io, %w[path/to/app path/to/rails_app content_box
|
18
19
|
--index_path=root.html
|
data/spec/convert_theme_spec.rb
CHANGED
@@ -6,28 +6,31 @@ describe ConvertTheme do
|
|
6
6
|
setup_base_rails
|
7
7
|
stdout do |stdout|
|
8
8
|
@theme = ConvertTheme.new(:template_root => File.dirname(__FILE__) + "/fixtures/bloganje",
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
12
|
-
|
9
|
+
:rails_root => @target_application,
|
10
|
+
:content_id => "content",
|
11
|
+
:inside_yields => { :header => '#header h2', :sidebar => '#sidebar' },
|
12
|
+
:stdout => stdout)
|
13
13
|
end
|
14
14
|
@expected_application = File.dirname(__FILE__) + "/expected/rails/bloganje"
|
15
15
|
end
|
16
|
-
it { @theme.should be_erb }
|
17
16
|
it { @theme.stylesheet_dir.should == "css" }
|
18
17
|
it { @theme.image_dir.should == "img" }
|
18
|
+
it { @theme.should be_erb }
|
19
19
|
describe "becomes a Rails app with html templates" do
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
it do
|
24
|
-
expected = clean_file(File.join(@expected_application, matching_file))
|
25
|
-
actual = File.join(@target_application, matching_file)
|
26
|
-
diff = `diff #{expected} #{actual} 2> /dev/null`
|
27
|
-
rputs diff unless diff.strip.empty?
|
28
|
-
diff.strip.should == ""
|
20
|
+
before do
|
21
|
+
@stdout = stdout do |stdout|
|
22
|
+
@theme.apply_to_target(:stdout => stdout, :generator => {:collision => :force, :quiet => true})
|
29
23
|
end
|
30
24
|
end
|
25
|
+
it { File.should be_exist(File.join(@target_application, "app/views/layouts/application.html.erb")) }
|
26
|
+
it { File.should be_exist(File.join(@expected_application, "app/views/layouts/application.html.erb")) }
|
27
|
+
it "should create app/views/layouts/application.html.erb as a layout file" do
|
28
|
+
expected = clean_file(File.join(@expected_application, "app/views/layouts/application.html.erb"))
|
29
|
+
actual = File.join(@target_application, "app/views/layouts/application.html.erb")
|
30
|
+
diff = `diff #{expected} #{actual} 2> /dev/null`
|
31
|
+
rputs diff unless diff.strip.empty?
|
32
|
+
diff.strip.should == ""
|
33
|
+
end
|
31
34
|
|
32
35
|
%w[public/stylesheets/style.css
|
33
36
|
public/stylesheets/theme.css].each do |matching_file|
|
@@ -41,30 +44,30 @@ describe ConvertTheme do
|
|
41
44
|
diff.strip.should == ""
|
42
45
|
end
|
43
46
|
end
|
47
|
+
it { @stdout.should include("<% content_for :head do -%>\n <script>...</script>\n<% end -%>") }
|
48
|
+
it { @stdout.should include("<% content_for :header do -%>\n My eCommerce Admin area\n<% end -%>") }
|
44
49
|
end
|
45
50
|
end
|
46
51
|
|
47
52
|
context "webresourcedepot theme to ERb" do
|
48
53
|
before do
|
49
54
|
setup_base_rails
|
50
|
-
stdout do |stdout|
|
55
|
+
@stdout = stdout do |stdout|
|
51
56
|
@theme = ConvertTheme.new(
|
52
57
|
:template_root => File.dirname(__FILE__) + "/fixtures/webresourcedepot",
|
53
|
-
:
|
54
|
-
|
58
|
+
:rails_root => @target_application,
|
59
|
+
:content_id => "center-column", :stdout => stdout)
|
60
|
+
@theme.apply_to_target(:generator => {:collision => :force, :quiet => true})
|
55
61
|
end
|
56
62
|
@expected_application = File.dirname(__FILE__) + "/expected/rails/webresourcedepot"
|
57
63
|
end
|
58
|
-
it { @theme.should be_erb }
|
59
64
|
describe "becomes a Rails app" do
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
diff.strip.should == ""
|
67
|
-
end
|
65
|
+
it "should create app/views/layouts/application.html.erb as a layout file" do
|
66
|
+
expected = clean_file(File.join(@expected_application, "app/views/layouts/application.html.erb"))
|
67
|
+
actual = File.join(@target_application, "app/views/layouts/application.html.erb")
|
68
|
+
diff = `diff #{expected} #{actual} 2> /dev/null`
|
69
|
+
rputs diff unless diff.strip.empty?
|
70
|
+
diff.strip.should == ""
|
68
71
|
end
|
69
72
|
|
70
73
|
%w[public/stylesheets/all.css].each do |matching_file|
|
@@ -81,3 +84,4 @@ describe ConvertTheme do
|
|
81
84
|
end
|
82
85
|
end
|
83
86
|
end
|
87
|
+
|
@@ -43,40 +43,7 @@
|
|
43
43
|
</div>
|
44
44
|
<div id="wrapper">
|
45
45
|
<div id="content"><%= yield %></div>
|
46
|
-
<div id="sidebar">
|
47
|
-
<ul>
|
48
|
-
<li><h3><a href="#" class="house">Dashboard</a></h3>
|
49
|
-
<ul>
|
50
|
-
<li><a href="#" class="report">Sales Report</a></li>
|
51
|
-
<li><a href="#" class="report_seo">SEO Report</a></li>
|
52
|
-
<li><a href="#" class="search">Search</a></li>
|
53
|
-
</ul>
|
54
|
-
</li>
|
55
|
-
<li><h3><a href="#" class="folder_table">Orders</a></h3>
|
56
|
-
<ul>
|
57
|
-
<li><a href="#" class="addorder">New order</a></li>
|
58
|
-
<li><a href="#" class="shipping">Shipments</a></li>
|
59
|
-
<li><a href="#" class="invoices">Invoices</a></li>
|
60
|
-
</ul>
|
61
|
-
</li>
|
62
|
-
<li><h3><a href="#" class="manage">Manage</a></h3>
|
63
|
-
<ul>
|
64
|
-
<li><a href="#" class="manage_page">Pages</a></li>
|
65
|
-
<li><a href="#" class="cart">Products</a></li>
|
66
|
-
<li><a href="#" class="folder">Product categories</a></li>
|
67
|
-
<li><a href="#" class="promotions">Promotions</a></li>
|
68
|
-
</ul>
|
69
|
-
</li>
|
70
|
-
<li><h3><a href="#" class="user">Users</a></h3>
|
71
|
-
<ul>
|
72
|
-
<li><a href="#" class="useradd">Add user</a></li>
|
73
|
-
<li><a href="#" class="group">User groups</a></li>
|
74
|
-
<li><a href="#" class="search">Find user</a></li>
|
75
|
-
<li><a href="#" class="online">Users online</a></li>
|
76
|
-
</ul>
|
77
|
-
</li>
|
78
|
-
</ul>
|
79
|
-
</div>
|
46
|
+
<div id="sidebar"><%= yield(:sidebar) %></div>
|
80
47
|
</div>
|
81
48
|
<div id="footer">
|
82
49
|
<div id="credits">
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: convert_theme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dr Nic Williams
|
@@ -237,16 +237,6 @@ files:
|
|
237
237
|
- spec/expected/rails/bloganje/public/stylesheets/theme2.css
|
238
238
|
- spec/expected/rails/bloganje/public/stylesheets/theme3.css
|
239
239
|
- spec/expected/rails/bloganje/public/stylesheets/theme4.css
|
240
|
-
- spec/expected/rails/bloganje/script/about
|
241
|
-
- spec/expected/rails/bloganje/script/console
|
242
|
-
- spec/expected/rails/bloganje/script/dbconsole
|
243
|
-
- spec/expected/rails/bloganje/script/destroy
|
244
|
-
- spec/expected/rails/bloganje/script/generate
|
245
|
-
- spec/expected/rails/bloganje/script/performance/benchmarker
|
246
|
-
- spec/expected/rails/bloganje/script/performance/profiler
|
247
|
-
- spec/expected/rails/bloganje/script/plugin
|
248
|
-
- spec/expected/rails/bloganje/script/runner
|
249
|
-
- spec/expected/rails/bloganje/script/server
|
250
240
|
- spec/expected/rails/bloganje/test/performance/browsing_test.rb
|
251
241
|
- spec/expected/rails/bloganje/test/test_helper.rb
|
252
242
|
- spec/expected/rails/webresourcedepot/README
|
@@ -307,16 +297,6 @@ files:
|
|
307
297
|
- spec/expected/rails/webresourcedepot/public/javascripts/prototype.js
|
308
298
|
- spec/expected/rails/webresourcedepot/public/robots.txt
|
309
299
|
- spec/expected/rails/webresourcedepot/public/stylesheets/all.css
|
310
|
-
- spec/expected/rails/webresourcedepot/script/about
|
311
|
-
- spec/expected/rails/webresourcedepot/script/console
|
312
|
-
- spec/expected/rails/webresourcedepot/script/dbconsole
|
313
|
-
- spec/expected/rails/webresourcedepot/script/destroy
|
314
|
-
- spec/expected/rails/webresourcedepot/script/generate
|
315
|
-
- spec/expected/rails/webresourcedepot/script/performance/benchmarker
|
316
|
-
- spec/expected/rails/webresourcedepot/script/performance/profiler
|
317
|
-
- spec/expected/rails/webresourcedepot/script/plugin
|
318
|
-
- spec/expected/rails/webresourcedepot/script/runner
|
319
|
-
- spec/expected/rails/webresourcedepot/script/server
|
320
300
|
- spec/expected/rails/webresourcedepot/test/performance/browsing_test.rb
|
321
301
|
- spec/expected/rails/webresourcedepot/test/test_helper.rb
|
322
302
|
- spec/fixtures/bloganje/README.md
|