install_theme 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,12 @@
1
+ === 0.6.1 / 2009-10-06
2
+
3
+ Major:
4
+
5
+ * much better algorithm for cleaning up stylesheets
6
+ * The content_id argument is now content_path - it is either a CSSpath or XPath expression.
7
+ The --inside_yields flag is renamed to --partial (-p)
8
+ Testing for using xpath and csspath in the content_path and --partials arguments.
9
+
1
10
  === 0.6.0 / 2009-10-02
2
11
 
3
12
  Major:
@@ -17,9 +17,9 @@ in action.
17
17
 
18
18
  Simple case:
19
19
 
20
- install_theme path/to/template path/to/rails_app content_id
20
+ install_theme path/to/template path/to/rails_app content_path
21
21
 
22
- Replace some DOM content with <%= yield :some_label %> with --inside_yields:
22
+ Replace some DOM content with <%= yield :some_label %> with --partials:
23
23
 
24
24
  install_theme path/to/app path/to/rails_app content_box \
25
25
  --inside_yield "header:#header h2" \
@@ -10,11 +10,11 @@ require 'sass/css'
10
10
  require 'haml/exec'
11
11
 
12
12
  class InstallTheme
13
- VERSION = "0.6.0"
13
+ VERSION = "0.6.1"
14
14
 
15
15
  attr_reader :template_root, :rails_root, :index_path, :template_type
16
16
  attr_reader :stylesheet_dir, :javascript_dir, :image_dir
17
- attr_reader :content_id, :inside_yields
17
+ attr_reader :content_path, :partials
18
18
  attr_reader :stdout
19
19
  attr_reader :original_named_yields, :original_body_content
20
20
 
@@ -23,8 +23,8 @@ class InstallTheme
23
23
  @rails_root = File.expand_path(options[:rails_root] || File.dirname('.'))
24
24
  @template_type = (options[:template_type] || detect_template).to_s
25
25
  @index_path = options[:index_path] || "index.html"
26
- @content_id = options[:content_id] || "content"
27
- @inside_yields = options[:inside_yields] || {}
26
+ @content_path = options[:content_path] || "content"
27
+ @partials = options[:partials] || {}
28
28
  @stylesheet_dir = options[:stylesheet_dir] || detect_stylesheet_dir
29
29
  @javascript_dir = options[:javascript_dir] || detect_javascript_dir
30
30
  @image_dir = options[:image_dir] || detect_image_dir
@@ -95,11 +95,11 @@ class InstallTheme
95
95
  contents.sub!(%r{\s*</head>}, "\n <%= yield(:head) %>\n</head>")
96
96
 
97
97
  doc = Hpricot(contents)
98
- doc.search("##{content_id},.#{content_id}").each do |elm|
98
+ doc.search(content_path).each do |elm|
99
99
  @original_body_content = elm.inner_html.strip
100
100
  elm.inner_html = "<%= yield %>"
101
101
  end
102
- inside_yields.to_a.each do |name, css_path|
102
+ partials.to_a.each do |name, css_path|
103
103
  doc.search(css_path).each do |elm|
104
104
  original_named_yields[name] = elm.inner_html.strip
105
105
  elm.inner_html = "<%= yield(:#{name}) || render_or_default('#{name}') %>"
@@ -181,9 +181,7 @@ class InstallTheme
181
181
  template_stylesheets.each do |file|
182
182
  target_path = File.join(template_temp_path, 'public/stylesheets', File.basename(file))
183
183
  File.open(target_path, "w") do |f|
184
- contents = File.read(file)
185
- contents.gsub!(%r{url\((["']?)[./]*#{image_dir}}, 'url(\1/images')
186
- f << contents
184
+ f << clean_stylesheet(File.read(file))
187
185
  end
188
186
  convert_to_sass(target_path) if haml?
189
187
  end
@@ -303,6 +301,10 @@ class InstallTheme
303
301
  Dir[File.join(template_root, image_dir, '**/*.{jpg,png,gif}')]
304
302
  end
305
303
 
304
+ def clean_stylesheet(contents)
305
+ contents.gsub(%r{url\((["']?)[\./]*(?:#{image_dir}|#{stylesheet_dir}|)\/?}, 'url(\1/images/')
306
+ end
307
+
306
308
  def show_readme
307
309
  stdout.puts <<-README
308
310
 
@@ -8,7 +8,7 @@ class InstallTheme
8
8
  opts.banner = <<-BANNER.gsub(/^ /,'')
9
9
  Use any HTML template as a theme generator for your Rails app.
10
10
 
11
- Usage: #{File.basename($0)} path/to/template path/to/rails_app content_id [options]
11
+ Usage: #{File.basename($0)} path/to/template path/to/rails_app content_path [options]
12
12
 
13
13
  Options are:
14
14
  BANNER
@@ -22,13 +22,13 @@ class InstallTheme
22
22
  opts.on("--index_path index.html", String,
23
23
  "HTML page to use for application layout.",
24
24
  "Default: index.html") { |arg| options[:index_path] = arg }
25
- opts.on("--inside_yield KEY_AND_CSS_PATH", String,
25
+ opts.on("-p", "--partial KEY_AND_PATH", String,
26
26
  "Replace the inner HTML of an element with <%= yield :key %>",
27
- "Example: --inside_yield header:#header",
28
- "Default: nil") do |arg|
29
- options[:inside_yields] ||= {}
27
+ "Example using CSS path: --partial header:#header",
28
+ "Example using XPath: --partial \"header://div[@id='header']\"") do |arg|
29
+ options[:partials] ||= {}
30
30
  key, css_path = arg.split(/\s*:\s*/)[0..1]
31
- options[:inside_yields][key.strip.to_sym] = css_path.strip
31
+ options[:partials][key.strip.to_sym] = css_path.strip
32
32
  end
33
33
  opts.on("-h", "--help",
34
34
  "Show this help message.") { |arg| stdout.puts opts; exit }
@@ -39,7 +39,7 @@ class InstallTheme
39
39
  end
40
40
  options[:template_root] = arguments.shift
41
41
  options[:rails_root] = arguments.shift
42
- options[:content_id] = arguments.shift
42
+ options[:content_path] = arguments.shift
43
43
  unless options[:template_root] && options[:rails_root]
44
44
  stdout.puts "trying"
45
45
  stdout.puts parser; exit
@@ -47,4 +47,4 @@ class InstallTheme
47
47
  InstallTheme.new(options).apply_to_target
48
48
  end
49
49
  end
50
- end
50
+ end
@@ -6,23 +6,23 @@ describe InstallTheme::CLI, "execute" do
6
6
  theme = stub
7
7
  InstallTheme.should_receive(:new).
8
8
  with(:template_root => "path/to/app",
9
- :rails_root => "path/to/rails_app",
10
- :content_id => "content_box",
11
- :index_path => "root.html",
12
- :template_type => "haml",
13
- :inside_yields => { :header => '#header h2', :sidebar => '#sidebar' }
9
+ :rails_root => "path/to/rails_app",
10
+ :content_path => "#content_box",
11
+ :index_path => "root.html",
12
+ :template_type => "haml",
13
+ :partials => { :header => '#header h2', :sidebar => '#sidebar' }
14
14
  ).
15
15
  and_return(theme)
16
16
  theme.should_receive(:apply_to_target)
17
17
  @stdout = stdout do |stdout_io|
18
- InstallTheme::CLI.execute(stdout_io, %w[path/to/app path/to/rails_app content_box
18
+ InstallTheme::CLI.execute(stdout_io, %w[path/to/app path/to/rails_app #content_box
19
19
  --index_path=root.html
20
20
  --haml
21
- --inside_yield header:#header\ h2
22
- --inside_yield sidebar:#sidebar
21
+ --partial header:#header\ h2
22
+ -p sidebar:#sidebar
23
23
  ])
24
24
  end
25
25
  end
26
26
 
27
27
  it("parses arguments and run generator") { }
28
- end
28
+ end
@@ -7,8 +7,8 @@ describe InstallTheme do
7
7
  @stdout = stdout do |stdout|
8
8
  @theme = InstallTheme.new(:template_root => File.dirname(__FILE__) + "/fixtures/bloganje",
9
9
  :rails_root => @target_application,
10
- :content_id => "content",
11
- :inside_yields => { :header => '#header h2', :sidebar => '#sidebar' },
10
+ :content_path => "content",
11
+ :partials => { :header => '#header h2', :sidebar => '#sidebar' },
12
12
  :stdout => stdout)
13
13
  @theme.apply_to_target(:stdout => stdout, :generator => {:collision => :force, :quiet => true})
14
14
  end
@@ -1,15 +1,15 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
3
  describe InstallTheme do
4
- context "bloganje theme to ERb" do
4
+ context "bloganje theme to ERb using CSS path" do
5
5
  before(:all) do
6
6
  setup_base_rails
7
7
  @stdout = stdout do |stdout|
8
8
  @theme = InstallTheme.new(:template_root => File.dirname(__FILE__) + "/fixtures/bloganje",
9
- :rails_root => @target_application,
10
- :content_id => "content",
11
- :inside_yields => { :header => '#header h2', :sidebar => '#sidebar' },
12
- :stdout => stdout)
9
+ :rails_root => @target_application,
10
+ :content_path => "#content",
11
+ :partials => { :header => '#header h2', :sidebar => '#sidebar' },
12
+ :stdout => stdout)
13
13
  @theme.apply_to_target(:stdout => stdout, :generator => {:collision => :force, :quiet => true})
14
14
  end
15
15
  @expected_application = File.dirname(__FILE__) + "/expected/rails/bloganje"
@@ -42,15 +42,16 @@ describe InstallTheme do
42
42
  end
43
43
  end
44
44
 
45
- context "the-hobbit-website-template theme to ERb" do
45
+ context "the-hobbit-website-template theme to ERb using xpath" do
46
46
  before(:all) do
47
47
  setup_base_rails
48
48
  @stdout = stdout do |stdout|
49
49
  @theme = InstallTheme.new(
50
50
  :template_root => File.dirname(__FILE__) + "/fixtures/the-hobbit-website-template",
51
51
  :rails_root => @target_application,
52
- :inside_yields => { :menu => '.navigation', :subtitle => '.header p' },
53
- :content_id => "content", :stdout => stdout)
52
+ :partials => { :menu => "//div[@class='navigation']", :subtitle => "//div[@class='header']/p" },
53
+ :content_path => "//div[@class='content']",
54
+ :stdout => stdout)
54
55
  @theme.apply_to_target(:generator => {:collision => :force, :quiet => true})
55
56
  end
56
57
  @expected_application = File.dirname(__FILE__) + "/expected/rails/the-hobbit-website-template"
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.6.0
4
+ version: 0.6.1
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-02 00:00:00 +10:00
12
+ date: 2009-10-06 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency