install_theme 0.7.2 → 0.8.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.
@@ -1,3 +1,16 @@
1
+ === 0.8.0 / 2009-10-12
2
+
3
+ Major:
4
+ * Paths (xpath/css path) can specify to replace the internals of a DOM (as it did before) or the entire DOM node itself. Previously --partial "header:#header h2" would have replace the inner HTML of the DOM, but now it replaces the DOM node itself. To replace the inner HTML, use --partial "header:#header h2:text" (css path) or --partial "header://div[@id='header']/h2/text()"
5
+ * CLI option --action/-a added - the extracted content_path contents can be stored in a Rails action template file
6
+
7
+ Minor:
8
+ * convert layouts to haml regardless of their name
9
+ * Updated CLI Usage help
10
+
11
+ Internal:
12
+ * Minimized spec suite by extracting a common file diff test into macro method
13
+
1
14
  === 0.7.2 / 2009-10-10
2
15
 
3
16
  * CLI shows a useful error message when --partial argument is incorrectly formatted
@@ -24,12 +24,29 @@ Simple case:
24
24
  Replace some DOM content with <%= yield :some_label %> with --partial:
25
25
 
26
26
  install_theme path/to/rails_app path/to/template #content_box \
27
- --partial "header:#header h2" \
27
+ --partial "header:#header h2 text()" \
28
28
  --partial sidebar:#sidebar"
29
29
 
30
30
  NOTE: The order of the first two arguments has been reversed since the original
31
31
  public release. This is in preparation for path/to/template to be optional.
32
32
 
33
+ NOTE: The default behaviour of the css/xpath selectors has/is changing. Originally it
34
+ replaced the internal content of the selected DOM node. Now, the default is to
35
+ replace the entire DOM node. To replace the internal content of the DOM node use
36
+ `/text()` (for xpath) or `:text` (for CSS paths) at the end of the selector.
37
+
38
+ For example, for CSS paths:
39
+
40
+ --partial ".header h2:text" # replaces contents of the h2 element
41
+ --partial ".header h2" # replaces the h2 element itself
42
+
43
+ For Xpaths:
44
+
45
+ --partial "//div[@id='header']/h2/text()" # replaces contents of the h2 element
46
+ --partial "//div[@id='header']/h2" # replaces the h2 element itself
47
+
48
+ The same goes for the content_path argument of the executable.
49
+
33
50
  Similarly, in 0.7.0 the content_path argument is optional after the first time
34
51
  you install a specific theme (see 'Theme Reuse' section).
35
52
 
@@ -3,17 +3,13 @@ $:.unshift(File.dirname(__FILE__)) unless
3
3
 
4
4
  require 'rubigen'
5
5
  require 'rubigen/scripts/generate'
6
- require 'haml'
7
- require 'haml/html'
8
- require 'sass'
9
- require 'sass/css'
10
- require 'haml/exec'
6
+ require 'nokogiri'
11
7
 
12
8
  class InstallTheme
13
- VERSION = "0.7.2"
9
+ VERSION = "0.8.0"
14
10
 
15
11
  attr_reader :template_root, :rails_root, :index_path, :template_type
16
- attr_reader :layout_name
12
+ attr_reader :layout_name, :action
17
13
  attr_reader :stylesheet_dir, :javascript_dir, :image_dir
18
14
  attr_reader :defaults_file
19
15
  attr_reader :content_path, :partials
@@ -30,6 +26,7 @@ class InstallTheme
30
26
  @image_dir = options[:image_dir] || detect_image_dir
31
27
  @layout_name = options[:layout] || "application"
32
28
  @layout_name.gsub!(/\..*/, '') # allow application.html.erb to be passed in, but clean it up to 'application'
29
+ @action = options[:action]
33
30
 
34
31
  @stdout = options[:stdout] || $stdout
35
32
 
@@ -44,10 +41,12 @@ class InstallTheme
44
41
  end
45
42
 
46
43
  def apply_to_target(options = {})
44
+ require_haml if haml?
47
45
  @stdout = options[:stdout] || @stdout || $stdout
48
46
  @original_named_yields = {}
49
47
  convert_file_to_layout(index_path, "app/views/layouts/#{layout_name}.html.erb")
50
- convert_to_haml('app/views/layouts/application.html.erb') if haml?
48
+ convert_to_haml("app/views/layouts/#{layout_name}.html.erb") if haml?
49
+ prepare_action
51
50
  prepare_sample_controller_and_view
52
51
  prepare_layout_partials
53
52
  prepare_assets
@@ -125,22 +124,33 @@ class InstallTheme
125
124
  EOS
126
125
 
127
126
  doc = Hpricot(contents)
128
- doc.search(content_path).each do |elm|
129
- @original_body_content = elm.inner_html.strip
130
- elm.inner_html = "<%= yield %>"
131
- end
127
+ @original_body_content = replace_by_path(doc, content_path, "<%= yield %>")
132
128
  partials.to_a.each do |name, css_path|
133
- doc.search(css_path).each do |elm|
134
- original_named_yields[name] = elm.inner_html.strip
135
- elm.inner_html = "<%= yield(:#{name}) || render_or_default('#{name}') %>"
136
- end
129
+ original_named_yields[name] =
130
+ replace_by_path(doc, css_path, "<%= yield(:#{name}) || render_or_default('#{name}') %>")
137
131
  end
138
132
  contents = doc.to_html
139
-
140
133
  f << contents
141
134
  end
142
135
  end
143
136
 
137
+ # see replace_by_path_spec.rb for examples
138
+ def replace_by_path(doc, path, replacement)
139
+ result = ""
140
+ return "" unless path && path.strip.match(/^(.*?)(|\s*:text|\s*\/?text\(\))$/)
141
+ outer_path, is_text = $1, !$2.blank?
142
+ if node = doc.search(outer_path).first
143
+ if is_text
144
+ result = node.inner_html
145
+ node.inner_html = replacement
146
+ else
147
+ result = node.to_html
148
+ node.parent.replace_child(node, Hpricot::Text.new(replacement))
149
+ end
150
+ end
151
+ result
152
+ end
153
+
144
154
  def convert_to_haml(path)
145
155
  from_path = File.join(template_temp_path, path)
146
156
  haml_path = from_path.gsub(/erb$/, "haml")
@@ -197,6 +207,17 @@ class InstallTheme
197
207
  convert_to_haml('app/views/original_template/index.html.erb') if haml?
198
208
  end
199
209
 
210
+ def prepare_action
211
+ return unless action
212
+ action_path = "app/views/#{action}.html.erb"
213
+ target_path = File.join(template_temp_path, action_path)
214
+ FileUtils.mkdir_p(File.dirname(target_path))
215
+ File.open(target_path, "w") do |f|
216
+ f << original_body_content
217
+ end
218
+ convert_to_haml(action_path) if haml?
219
+ end
220
+
200
221
  def prepare_layout_partials
201
222
  original_named_yields.to_a.each do |key, original_contents|
202
223
  partial_file = "app/views/layouts/_#{key}.html.erb"
@@ -243,20 +264,22 @@ class InstallTheme
243
264
  end
244
265
 
245
266
  # converts +from+ HTML into +to+ HAML
246
- # +from+ can either be file name, HTML content (String) or an Hpricot::Node
267
+ # +from+ can either be file name, HTML content (String) or an Nokogiri::XML::Node
247
268
  # +to+ can either be a file name or an IO object with a #write method
248
269
  def html2haml(from, to)
249
- converter = Haml::Exec::HTML2Haml.new([])
250
- from = File.read(from) if File.exist?(from)
251
- to = File.open(to, "w") unless to.respond_to?(:write)
252
- converter.instance_variable_set("@options", { :input => from, :output => to })
253
- converter.instance_variable_set("@module_opts", { :rhtml => true })
254
- begin
255
- converter.send(:process_result)
256
- rescue Exception => e
257
- stdout.puts "Failed to convert #{File.basename(from)} to haml"
258
- end
259
- to.close if to.respond_to?(:close)
270
+ Open3.popen3("html2haml #{from} #{to}") { |stdin, stdout, stderr| stdout.read }
271
+ # TODO - the following is failing for some reason
272
+ # converter = Haml::Exec::HTML2Haml.new([])
273
+ # from = File.read(from) if File.exist?(from)
274
+ # to = File.open(to, "w") unless to.respond_to?(:write)
275
+ # converter.instance_variable_set("@options", { :input => from, :output => to })
276
+ # converter.instance_variable_set("@module_opts", { :rhtml => true })
277
+ # begin
278
+ # converter.send(:process_result)
279
+ # rescue Exception => e
280
+ # stdout.puts "Failed to convert #{File.basename(from)} to haml"
281
+ # end
282
+ # to.close if to.respond_to?(:close)
260
283
  end
261
284
 
262
285
  def css2sass(from, to)
@@ -363,4 +386,13 @@ class InstallTheme
363
386
  def tmp_dir
364
387
  ENV['TMPDIR'] || '/tmp'
365
388
  end
389
+
390
+ def require_haml
391
+ require 'haml'
392
+ require 'haml/html'
393
+ require 'sass'
394
+ require 'sass/css'
395
+ require 'haml/exec'
396
+ require 'open3'
397
+ end
366
398
  end
@@ -10,13 +10,18 @@ class InstallTheme
10
10
 
11
11
  Usage: #{File.basename($0)} path/to/rails_app path/to/template content_path [options]
12
12
 
13
+ Examples of paths (CSS or XPath):
14
+ * #header h2 - replaces the entire h2 element
15
+ * #header h2:text - replaces the inner HTML of the h2 element
16
+ * //div[@class='header']/h2 - replaces the entire h2 element
17
+ * //div[@class='header']/h2/text() - replaces the inner HTML of the h2 element
18
+
13
19
  Options are:
14
20
  BANNER
15
21
  opts.separator ""
16
22
  opts.on("-p", "--partial KEY_AND_PATH", String,
17
23
  "Replace the inner HTML of an element with <%= yield :key %>",
18
- "Example using CSS path: --partial header:#header",
19
- "Example using XPath: --partial \"header://div[@id='header']\"") do |arg|
24
+ "See path examples above.") do |arg|
20
25
  options[:partials] ||= {}
21
26
  key, path = arg.split(/\s*:\s*/)[0..1]
22
27
  if key && path
@@ -30,12 +35,14 @@ class InstallTheme
30
35
  "Set the layout file name.",
31
36
  "Layout files are stored in app/views/layouts and will be suffixed by .html.erb or .html.haml",
32
37
  "Default: application") { |arg| options[:layout] = arg }
38
+ opts.on("-a", "--action posts/show", String,
39
+ "Store content extracted from content_path into Rails action.",
40
+ "Example, '-a posts/show' will create app/views/posts/show.html.erb file.",
41
+ "Default: none") { |arg| options[:action] = arg }
33
42
  opts.on("--erb",
34
- "Generate ERb templates.",
35
- "Default: auto-detect") { |arg| options[:template_type] = 'erb' }
43
+ "Generate ERb templates. Default: Yes, unless it's not.") { |arg| options[:template_type] = 'erb' }
36
44
  opts.on("--haml",
37
- "Generate HAML templates.",
38
- "Default: auto-detect") { |arg| options[:template_type] = 'haml' }
45
+ "Generate HAML templates. Default: Auto-detect") { |arg| options[:template_type] = 'haml' }
39
46
  opts.on("--index_path index.html", String,
40
47
  "HTML page to use for application layout.",
41
48
  "Default: index.html") { |arg| options[:index_path] = arg }
@@ -1,4 +1,5 @@
1
- <ul>
1
+ <div id="sidebar">
2
+ <ul>
2
3
  <li><h3><a href="#" class="house">Dashboard</a></h3>
3
4
  <ul>
4
5
  <li><a href="#" class="report">Sales Report</a></li>
@@ -29,4 +30,5 @@
29
30
  <li><a href="#" class="online">Users online</a></li>
30
31
  </ul>
31
32
  </li>
32
- </ul>
33
+ </ul>
34
+ </div>
@@ -1,63 +1,64 @@
1
- %ul
2
- %li
3
- %h3
4
- %a.house{ :href => "#" }
5
- Dashboard
6
- %ul
7
- %li
8
- %a.report{ :href => "#" }
9
- Sales Report
10
- %li
11
- %a.report_seo{ :href => "#" }
12
- SEO Report
13
- %li
14
- %a.search{ :href => "#" }
15
- Search
16
- %li
17
- %h3
18
- %a.folder_table{ :href => "#" }
19
- Orders
20
- %ul
21
- %li
22
- %a.addorder{ :href => "#" }
23
- New order
24
- %li
25
- %a.shipping{ :href => "#" }
26
- Shipments
27
- %li
28
- %a.invoices{ :href => "#" }
29
- Invoices
30
- %li
31
- %h3
32
- %a.manage{ :href => "#" }
33
- Manage
34
- %ul
35
- %li
36
- %a.manage_page{ :href => "#" }
37
- Pages
38
- %li
39
- %a.cart{ :href => "#" }
40
- Products
41
- %li
42
- %a.folder{ :href => "#" }
43
- Product categories
44
- %li
45
- %a.promotions{ :href => "#" }
46
- Promotions
47
- %li
48
- %h3
49
- %a.user{ :href => "#" }
50
- Users
51
- %ul
52
- %li
53
- %a.useradd{ :href => "#" }
54
- Add user
55
- %li
56
- %a.group{ :href => "#" }
57
- User groups
58
- %li
59
- %a.search{ :href => "#" }
60
- Find user
61
- %li
62
- %a.online{ :href => "#" }
63
- Users online
1
+ #sidebar
2
+ %ul
3
+ %li
4
+ %h3
5
+ %a.house{ :href => "#" }
6
+ Dashboard
7
+ %ul
8
+ %li
9
+ %a.report{ :href => "#" }
10
+ Sales Report
11
+ %li
12
+ %a.report_seo{ :href => "#" }
13
+ SEO Report
14
+ %li
15
+ %a.search{ :href => "#" }
16
+ Search
17
+ %li
18
+ %h3
19
+ %a.folder_table{ :href => "#" }
20
+ Orders
21
+ %ul
22
+ %li
23
+ %a.addorder{ :href => "#" }
24
+ New order
25
+ %li
26
+ %a.shipping{ :href => "#" }
27
+ Shipments
28
+ %li
29
+ %a.invoices{ :href => "#" }
30
+ Invoices
31
+ %li
32
+ %h3
33
+ %a.manage{ :href => "#" }
34
+ Manage
35
+ %ul
36
+ %li
37
+ %a.manage_page{ :href => "#" }
38
+ Pages
39
+ %li
40
+ %a.cart{ :href => "#" }
41
+ Products
42
+ %li
43
+ %a.folder{ :href => "#" }
44
+ Product categories
45
+ %li
46
+ %a.promotions{ :href => "#" }
47
+ Promotions
48
+ %li
49
+ %h3
50
+ %a.user{ :href => "#" }
51
+ Users
52
+ %ul
53
+ %li
54
+ %a.useradd{ :href => "#" }
55
+ Add user
56
+ %li
57
+ %a.group{ :href => "#" }
58
+ User groups
59
+ %li
60
+ %a.search{ :href => "#" }
61
+ Find user
62
+ %li
63
+ %a.online{ :href => "#" }
64
+ Users online
@@ -44,7 +44,7 @@
44
44
  </div>
45
45
  <div id="wrapper">
46
46
  <div id="content"><%= yield %></div>
47
- <div id="sidebar"><%= yield(:sidebar) || render_or_default('sidebar') %></div>
47
+ <%= yield(:sidebar) || render_or_default('sidebar') %>
48
48
  </div>
49
49
  <div id="footer">
50
50
  <div id="credits">
@@ -61,8 +61,7 @@
61
61
  #wrapper
62
62
  #content
63
63
  = yield
64
- #sidebar
65
- = yield(:sidebar) || render_or_default('sidebar')
64
+ = yield(:sidebar) || render_or_default('sidebar')
66
65
  #footer
67
66
  #credits
68
67
  Template by
@@ -26,7 +26,7 @@
26
26
 
27
27
  <div class="header">
28
28
  <h1>The Hobbit</h1>
29
- <p><%= yield(:subtitle) || render_or_default('subtitle') %></p>
29
+ <%= yield(:subtitle) || render_or_default('subtitle') %>
30
30
  </div>
31
31
 
32
32
  <div class="pattern"><span></span></div>
@@ -12,6 +12,7 @@ describe InstallTheme::CLI, "execute" do
12
12
  :template_type => "haml",
13
13
  :partials => { "header" => '#header h2', "sidebar" => '#sidebar' },
14
14
  :defaults_file => "install_theme.yml",
15
+ :action => "posts/show",
15
16
  :layout => "iphone"
16
17
  ).
17
18
  and_return(theme)
@@ -25,6 +26,7 @@ describe InstallTheme::CLI, "execute" do
25
26
  -p sidebar:#sidebar
26
27
  --defaults_file install_theme.yml
27
28
  --layout iphone
29
+ --action posts/show
28
30
  ])
29
31
  end
30
32
  end
@@ -1,38 +1,19 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
3
  describe InstallTheme do
4
+ include SetupThemeHelpers
5
+ extend FileDiffMatcher
6
+
4
7
  context "bloganje theme to haml" do
5
- before(:all) do
6
- setup_base_rails :haml => true
7
- @template_root = File.dirname(__FILE__) + "/fixtures/bloganje"
8
- FileUtils.rm_rf(File.join(@template_root, "install_theme.yml"))
9
- @stdout = stdout do |stdout|
10
- @theme = InstallTheme.new(:template_root => @template_root,
11
- :rails_root => @target_application,
12
- :content_path => "#content",
13
- :partials => { "header" => '#header h2', "sidebar" => '#sidebar' },
14
- :stdout => stdout)
15
- @theme.apply_to_target(:stdout => stdout, :generator => {:collision => :force, :quiet => true})
16
- end
17
- @expected_application = File.dirname(__FILE__) + "/expected/rails/bloganje"
18
- end
8
+ before(:all) { setup_bloganje :rails => {:haml => true} }
19
9
  it { @theme.should be_haml }
20
10
  it { @theme.should be_valid }
21
11
 
22
- %w[app/views/layouts/application.html.haml
23
- app/views/layouts/_header.html.haml
24
- app/views/layouts/_sidebar.html.haml
25
- app/helpers/template_helper.rb
26
- public/stylesheets/sass/style.sass].each do |matching_file|
27
- it do
28
- expected = clean_file File.join(@expected_application, matching_file), 'expected'
29
- actual = clean_file File.join(@target_application, matching_file), 'actual'
30
- diff = `diff #{expected} #{actual} 2> /dev/null`
31
- rputs diff unless diff.strip.empty?
32
- diff.strip.should == ""
33
- end
34
- end
35
-
12
+ it_should_have_matching_file "app/views/layouts/application.html.haml"
13
+ it_should_have_matching_file "app/views/layouts/_header.html.haml"
14
+ it_should_have_matching_file "app/views/layouts/_sidebar.html.haml"
15
+ it_should_have_matching_file "app/helpers/template_helper.rb"
16
+ it_should_have_matching_file "public/stylesheets/sass/style.sass"
36
17
 
37
18
  it { File.should be_exist(File.join(@target_application, "app/views/original_template/index.html.haml")) }
38
19
  context "sample template /original_template/index.html.haml" do
@@ -2,6 +2,7 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
3
  describe InstallTheme do
4
4
  include SetupThemeHelpers
5
+ extend FileDiffMatcher
5
6
 
6
7
  context "bloganje theme to ERb using CSS path" do
7
8
  before(:all) { setup_bloganje }
@@ -10,20 +11,14 @@ describe InstallTheme do
10
11
  it { @theme.should be_erb }
11
12
  it { @theme.should be_valid }
12
13
 
13
- %w[app/views/layouts/application.html.erb
14
- app/views/layouts/_header.html.erb
15
- app/views/layouts/_sidebar.html.erb
16
- app/helpers/template_helper.rb
17
- public/stylesheets/style.css
18
- public/stylesheets/theme.css].each do |matching_file|
19
- it "should having matching file #{matching_file}" do
20
- expected = clean_file File.join(@expected_application, matching_file), 'expected'
21
- actual = clean_file File.join(@target_application, matching_file), 'actual'
22
- diff = `diff #{expected} #{actual} 2> /dev/null`
23
- rputs diff unless diff.strip.empty?
24
- diff.strip.should == ""
25
- end
26
- end
14
+ it_should_have_matching_file "app/views/layouts/application.html.erb"
15
+ it_should_have_matching_file "app/views/layouts/_header.html.erb"
16
+ it_should_have_matching_file "app/views/layouts/_sidebar.html.erb"
17
+ it_should_have_matching_file "app/views/posts/show.html.erb"
18
+ it_should_have_matching_file "app/helpers/template_helper.rb"
19
+ it_should_have_matching_file "public/stylesheets/style.css"
20
+ it_should_have_matching_file "public/stylesheets/theme.css"
21
+
27
22
  context "sample template /templates/index.html.erb" do
28
23
  subject do
29
24
  File.read(File.join(@target_application, 'app/views/original_template/index.html.erb'))
@@ -47,19 +42,10 @@ describe InstallTheme do
47
42
  it { @theme.image_dir.should == "img" }
48
43
  it { @theme.should be_valid }
49
44
 
50
- %w[app/views/layouts/application.html.erb
51
- app/helpers/template_helper.rb
52
- public/stylesheets/default.css].each do |matching_file|
53
- it { File.should be_exist(File.join(@target_application, matching_file)) }
54
- it { File.should be_exist(File.join(@expected_application, matching_file)) }
55
- it do
56
- expected = clean_file File.join(@expected_application, matching_file), 'expected'
57
- actual = clean_file File.join(@target_application, matching_file), 'actual'
58
- diff = `diff #{expected} #{actual} 2> /dev/null`
59
- rputs diff unless diff.strip.empty?
60
- diff.strip.should == ""
61
- end
62
- end
45
+ it_should_have_matching_file "app/views/layouts/application.html.erb"
46
+ it_should_have_matching_file "app/helpers/template_helper.rb"
47
+ it_should_have_matching_file "public/stylesheets/default.css"
48
+
63
49
  it "should create install_theme.yml containing the partial information" do
64
50
  expected = clean_file File.join(@template_root, "expected_install_theme.yml"), 'expected'
65
51
  actual = clean_file File.join(@template_root, "install_theme.yml"), 'actual'
@@ -74,52 +60,25 @@ describe InstallTheme do
74
60
  setup_app_with_theme('bloganje', :setup_defaults => true)
75
61
  end
76
62
  it { File.should be_exist(File.join(@template_root, "install_theme.yml")) }
77
- it { @theme.content_path.should == "#content" }
63
+ it { @theme.content_path.should == "#content:text" }
78
64
  it { @theme.should be_valid }
79
- %w[app/views/layouts/application.html.erb
80
- app/views/layouts/_header.html.erb
81
- app/views/layouts/_sidebar.html.erb
82
- app/helpers/template_helper.rb
83
- public/stylesheets/style.css
84
- public/stylesheets/theme.css].each do |matching_file|
85
- it "should having matching file #{matching_file}" do
86
- expected = clean_file File.join(@expected_application, matching_file), 'expected'
87
- actual = clean_file File.join(@target_application, matching_file), 'actual'
88
- diff = `diff #{expected} #{actual} 2> /dev/null`
89
- rputs diff unless diff.strip.empty?
90
- diff.strip.should == ""
91
- end
92
- end
65
+ it_should_have_matching_file "app/views/layouts/application.html.erb"
66
+ it_should_have_matching_file "app/views/layouts/_header.html.erb"
67
+ it_should_have_matching_file "app/views/layouts/_sidebar.html.erb"
68
+ it_should_have_matching_file "app/helpers/template_helper.rb"
69
+ it_should_have_matching_file "public/stylesheets/style.css"
70
+ it_should_have_matching_file "public/stylesheets/theme.css"
93
71
  end
94
72
 
95
- context "alternate layout file name" do
96
- before(:all) do
97
- setup_base_rails
98
- @template_root = File.dirname(__FILE__) + "/fixtures/bloganje"
99
- FileUtils.rm_rf(File.join(@template_root, "install_theme.yml"))
100
- @stdout = stdout do |stdout|
101
- @theme = InstallTheme.new(:template_root => @template_root,
102
- :rails_root => @target_application,
103
- :stdout => stdout)
104
- @theme.apply_to_target(:stdout => stdout, :generator => {:collision => :force, :quiet => true})
105
- end
106
- @expected_application = File.dirname(__FILE__) + "/expected/rails/bloganje"
107
- end
73
+ context "invalid if no content_path explicitly or via defaults file" do
74
+ before(:all) { setup_bloganje(:content_path => nil) }
108
75
  it { @theme.content_path.should be_nil }
109
76
  it { @theme.should_not be_valid }
110
77
  end
111
78
 
112
- context "invalid if no content_path explicitly or via defaults file" do
79
+ context "alternate layout file name" do
113
80
  before(:all) { setup_bloganje(:layout => "special") }
114
- %w[app/views/layouts/special.html.erb].each do |matching_file|
115
- it "should having matching file #{matching_file}" do
116
- expected = clean_file File.join(@expected_application, matching_file), 'expected'
117
- actual = clean_file File.join(@target_application, matching_file), 'actual'
118
- diff = `diff #{expected} #{actual} 2> /dev/null`
119
- rputs diff unless diff.strip.empty?
120
- diff.strip.should == ""
121
- end
122
- end
81
+ it_should_have_matching_file "app/views/layouts/special.html.erb"
123
82
  end
124
83
 
125
84
  end
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'spec'
3
+ require 'hpricot'
3
4
 
4
5
  $:.unshift(File.dirname(__FILE__) + '/../lib')
5
6
  require 'install_theme'
@@ -44,9 +45,21 @@ def stdout(&block)
44
45
  stdout_io.read
45
46
  end
46
47
 
48
+ module FileDiffMatcher
49
+ def it_should_have_matching_file(matching_file)
50
+ it "should having matching file #{matching_file}" do
51
+ expected = clean_file File.join(@expected_application, matching_file), 'expected'
52
+ actual = clean_file File.join(@target_application, matching_file), 'actual'
53
+ diff = `diff #{expected} #{actual} 2> /dev/null`
54
+ rputs diff unless diff.strip.empty?
55
+ diff.strip.should == ""
56
+ end
57
+ end
58
+ end
59
+
47
60
  module SetupThemeHelpers
48
61
  def setup_app_with_theme(theme, theme_options = {})
49
- setup_base_rails
62
+ setup_base_rails(theme_options.delete(:rails) || {})
50
63
  @template_root = File.join(File.dirname(__FILE__), "fixtures", theme)
51
64
  FileUtils.chdir(@template_root) do
52
65
  if theme_options.delete(:setup_defaults)
@@ -65,19 +78,21 @@ module SetupThemeHelpers
65
78
  end
66
79
 
67
80
  def setup_bloganje(theme_options = {})
68
- setup_app_with_theme('bloganje',
69
- {:content_path => "#content", :partials => { "header" => '#header h2', "sidebar" => '#sidebar' }}.
70
- merge(theme_options))
81
+ setup_app_with_theme('bloganje', {
82
+ :content_path => "#content:text",
83
+ :partials => { "header" => '#header h2 text()', "sidebar" => '#sidebar' },
84
+ :action => "posts/show"
85
+ }.merge(theme_options))
71
86
  end
72
87
 
73
88
  def setup_hobbit(theme_options = {})
74
- setup_app_with_theme('the-hobbit-website-template',
75
- { :content_path => "//div[@class='content']",
76
- :partials => { "menu" => "//div[@class='navigation']", "subtitle" => "//div[@class='header']/p" }}.
77
- merge(theme_options))
89
+ setup_app_with_theme('the-hobbit-website-template', {
90
+ :content_path => "//div[@class='content']/text()",
91
+ :partials => { "menu" => "//div[@class='navigation']/text()", "subtitle" => "//div[@class='header']/p" }
92
+ }.merge(theme_options))
78
93
  end
79
94
 
80
- def setup_base_rails(options = {})
95
+ def setup_base_rails(options)
81
96
  tmp_path = File.dirname(__FILE__) + "/tmp"
82
97
  FileUtils.rm_rf(tmp_path)
83
98
  FileUtils.mkdir_p(tmp_path )
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: install_theme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dr Nic Williams
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-10 00:00:00 +10:00
12
+ date: 2009-10-12 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency