install_theme 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,16 @@
1
+ === 0.7.1 / 2009-10-08
2
+
3
+ Major:
4
+ * CLI has a --layout/-l flag to set the layout file name (still defaults to application[.html.erb])
5
+ * CLI has a --defaults_file flag to select an alternate YAML file containing defaults for the theme.
6
+ * Layout files have 'javascript_include_tag :all' added to the <head> section
7
+
8
+ Minor:
9
+ * refactor before(:all) blocks into common helper setup_app_with_theme
10
+ * reorder the CLI help Usage message to show new order of arguments
11
+ * reordering the CLI flags in the help display
12
+ * removed the unfinished sentence about Dr Nic
13
+
1
14
  === 0.7.0 / 2009-10-07
2
15
 
3
16
  Major:
@@ -62,7 +62,7 @@ install_theme is distributed as a RubyGem, which installs the command line app a
62
62
 
63
63
  == AUTHOR:
64
64
 
65
- Dr Nic Williams (http://drnicwilliams.com) wrote install_theme because he wanted a very
65
+ Dr Nic Williams (http://drnicwilliams.com)
66
66
 
67
67
  == LICENSE:
68
68
 
@@ -10,9 +10,10 @@ require 'sass/css'
10
10
  require 'haml/exec'
11
11
 
12
12
  class InstallTheme
13
- VERSION = "0.7.0"
13
+ VERSION = "0.7.1"
14
14
 
15
15
  attr_reader :template_root, :rails_root, :index_path, :template_type
16
+ attr_reader :layout_name
16
17
  attr_reader :stylesheet_dir, :javascript_dir, :image_dir
17
18
  attr_reader :defaults_file
18
19
  attr_reader :content_path, :partials
@@ -27,6 +28,9 @@ class InstallTheme
27
28
  @stylesheet_dir = options[:stylesheet_dir] || detect_stylesheet_dir
28
29
  @javascript_dir = options[:javascript_dir] || detect_javascript_dir
29
30
  @image_dir = options[:image_dir] || detect_image_dir
31
+ @layout_name = options[:layout] || "application"
32
+ @layout_name.gsub!(/\..*/, '') # allow application.html.erb to be passed in, but clean it up to 'application'
33
+
30
34
  @stdout = options[:stdout] || $stdout
31
35
 
32
36
  load_template_defaults unless options[:ignore_defaults]
@@ -42,7 +46,7 @@ class InstallTheme
42
46
  def apply_to_target(options = {})
43
47
  @stdout = options[:stdout] || @stdout || $stdout
44
48
  @original_named_yields = {}
45
- convert_file_to_layout(index_path, 'app/views/layouts/application.html.erb')
49
+ convert_file_to_layout(index_path, "app/views/layouts/#{layout_name}.html.erb")
46
50
  convert_to_haml('app/views/layouts/application.html.erb') if haml?
47
51
  prepare_sample_controller_and_view
48
52
  prepare_layout_partials
@@ -113,7 +117,12 @@ class InstallTheme
113
117
  contents.gsub!(%r{(["'])/?#{stylesheet_dir}}, '\1/stylesheets') unless stylesheet_dir.blank?
114
118
  contents.gsub!(%r{(["'])/?#{javascript_dir}}, '\1/javascripts') unless javascript_dir.blank?
115
119
 
116
- contents.sub!(%r{\s*</head>}, "\n <%= yield(:head) %>\n</head>")
120
+ contents.sub!(%r{\s*</head>}, <<-EOS.gsub(/^ /, '').gsub(/\n$/, ''))
121
+
122
+ <%= javascript_include_tag :all %>
123
+ <%= yield(:head) %>
124
+ </head>
125
+ EOS
117
126
 
118
127
  doc = Hpricot(contents)
119
128
  doc.search(content_path).each do |elm|
@@ -8,11 +8,23 @@ 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_path [options]
11
+ Usage: #{File.basename($0)} path/to/rails_app path/to/template content_path [options]
12
12
 
13
13
  Options are:
14
14
  BANNER
15
15
  opts.separator ""
16
+ opts.on("-p", "--partial KEY_AND_PATH", String,
17
+ "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|
20
+ options[:partials] ||= {}
21
+ key, css_path = arg.split(/\s*:\s*/)[0..1]
22
+ options[:partials][key.strip] = css_path.strip
23
+ end
24
+ opts.on("-l", "--layout application", String,
25
+ "Set the layout file name.",
26
+ "Layout files are stored in app/views/layouts and will be suffixed by .html.erb or .html.haml",
27
+ "Default: application") { |arg| options[:layout] = arg }
16
28
  opts.on("--erb",
17
29
  "Generate ERb templates.",
18
30
  "Default: auto-detect") { |arg| options[:template_type] = 'erb' }
@@ -22,14 +34,9 @@ class InstallTheme
22
34
  opts.on("--index_path index.html", String,
23
35
  "HTML page to use for application layout.",
24
36
  "Default: index.html") { |arg| options[:index_path] = arg }
25
- opts.on("-p", "--partial KEY_AND_PATH", String,
26
- "Replace the inner HTML of an element with <%= yield :key %>",
27
- "Example using CSS path: --partial header:#header",
28
- "Example using XPath: --partial \"header://div[@id='header']\"") do |arg|
29
- options[:partials] ||= {}
30
- key, css_path = arg.split(/\s*:\s*/)[0..1]
31
- options[:partials][key.strip] = css_path.strip
32
- end
37
+ opts.on("--defaults_file install_theme.yml", String,
38
+ "Select an alternate YAML file containing defaults for the theme.",
39
+ "Default: install_theme.yml") { |arg| options[:defaults_file] = arg }
33
40
  opts.on("-h", "--help",
34
41
  "Show this help message.") { |arg| stdout.puts opts; exit }
35
42
  opts.on("-v", "--version",
@@ -12,6 +12,7 @@
12
12
  <!--[if IE]>
13
13
  <link rel="stylesheet" type="text/css" href="/stylesheets/ie-sucks.css" />
14
14
  <![endif]-->
15
+ <%= javascript_include_tag :all %>
15
16
  <%= yield(:head) %>
16
17
  </head>
17
18
 
@@ -13,6 +13,7 @@
13
13
  [if IE]>
14
14
  <link rel="stylesheet" type="text/css" href="/stylesheets/ie-sucks.css" />
15
15
  <![endif]
16
+ = javascript_include_tag :all
16
17
  = yield(:head)
17
18
  %body
18
19
  #container
@@ -8,6 +8,7 @@
8
8
  <meta name="author" content="author" />
9
9
  <link href="/stylesheets/default.css" rel="stylesheet" type="text/css" />
10
10
  <title>The Hobbit</title>
11
+ <%= javascript_include_tag :all %>
11
12
  <%= yield(:head) %>
12
13
  </head>
13
14
 
@@ -10,7 +10,9 @@ describe InstallTheme::CLI, "execute" do
10
10
  :content_path => "#content_box",
11
11
  :index_path => "root.html",
12
12
  :template_type => "haml",
13
- :partials => { "header" => '#header h2', "sidebar" => '#sidebar' }
13
+ :partials => { "header" => '#header h2', "sidebar" => '#sidebar' },
14
+ :defaults_file => "install_theme.yml",
15
+ :layout => "iphone"
14
16
  ).
15
17
  and_return(theme)
16
18
  theme.should_receive(:valid?).and_return(true)
@@ -21,6 +23,8 @@ describe InstallTheme::CLI, "execute" do
21
23
  --haml
22
24
  --partial header:#header\ h2
23
25
  -p sidebar:#sidebar
26
+ --defaults_file install_theme.yml
27
+ --layout iphone
24
28
  ])
25
29
  end
26
30
  end
@@ -1,21 +1,10 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
3
  describe InstallTheme do
4
+ include SetupThemeHelpers
5
+
4
6
  context "bloganje theme to ERb using CSS path" do
5
- before(:all) do
6
- setup_base_rails
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
7
+ before(:all) { setup_bloganje }
19
8
  it { @theme.stylesheet_dir.should == "css" }
20
9
  it { @theme.image_dir.should == "img" }
21
10
  it { @theme.should be_erb }
@@ -53,20 +42,7 @@ describe InstallTheme do
53
42
  end
54
43
 
55
44
  context "the-hobbit-website-template theme to ERb using xpath" do
56
- before(:all) do
57
- setup_base_rails
58
- @template_root = File.dirname(__FILE__) + "/fixtures/the-hobbit-website-template"
59
- FileUtils.rm_rf(File.join(@template_root, "install_theme.yml"))
60
- @stdout = stdout do |stdout|
61
- @theme = InstallTheme.new(:template_root => @template_root,
62
- :rails_root => @target_application,
63
- :partials => { "menu" => "//div[@class='navigation']", "subtitle" => "//div[@class='header']/p" },
64
- :content_path => "//div[@class='content']",
65
- :stdout => stdout)
66
- @theme.apply_to_target(:generator => {:collision => :force, :quiet => true})
67
- end
68
- @expected_application = File.dirname(__FILE__) + "/expected/rails/the-hobbit-website-template"
69
- end
45
+ before(:all) { setup_hobbit }
70
46
  it { @theme.stylesheet_dir.should == "" }
71
47
  it { @theme.image_dir.should == "img" }
72
48
  it { @theme.should be_valid }
@@ -95,18 +71,7 @@ describe InstallTheme do
95
71
 
96
72
  context "use install_theme.yml for defaults" do
97
73
  before(:all) do
98
- setup_base_rails
99
- @template_root = File.dirname(__FILE__) + "/fixtures/bloganje"
100
- FileUtils.chdir(@template_root) do
101
- FileUtils.cp_r("expected_install_theme.yml", "install_theme.yml")
102
- end
103
- @stdout = stdout do |stdout|
104
- @theme = InstallTheme.new(:template_root => @template_root,
105
- :rails_root => @target_application,
106
- :stdout => stdout)
107
- @theme.apply_to_target(:stdout => stdout, :generator => {:collision => :force, :quiet => true})
108
- end
109
- @expected_application = File.dirname(__FILE__) + "/expected/rails/bloganje"
74
+ setup_app_with_theme('bloganje', :setup_defaults => true)
110
75
  end
111
76
  it { File.should be_exist(File.join(@template_root, "install_theme.yml")) }
112
77
  it { @theme.content_path.should == "#content" }
@@ -127,7 +92,7 @@ describe InstallTheme do
127
92
  end
128
93
  end
129
94
 
130
- context "invalid if no content_path explicitly or via defaults file" do
95
+ context "alternate layout file name" do
131
96
  before(:all) do
132
97
  setup_base_rails
133
98
  @template_root = File.dirname(__FILE__) + "/fixtures/bloganje"
@@ -143,5 +108,19 @@ describe InstallTheme do
143
108
  it { @theme.content_path.should be_nil }
144
109
  it { @theme.should_not be_valid }
145
110
  end
111
+
112
+ context "invalid if no content_path explicitly or via defaults file" do
113
+ 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
123
+ end
124
+
146
125
  end
147
126
 
@@ -37,16 +37,6 @@ def clean_file(orig_file, scope)
37
37
  file
38
38
  end
39
39
 
40
- def setup_base_rails(options = {})
41
- tmp_path = File.dirname(__FILE__) + "/tmp"
42
- FileUtils.rm_rf(tmp_path)
43
- FileUtils.mkdir_p(tmp_path )
44
- @target_application = File.join(tmp_path, "my_app")
45
- FileUtils.cp_r(File.dirname(__FILE__) + "/expected/rails/base_app", @target_application)
46
- `haml --rails #{@target_application}` if options[:haml]
47
- @target_application
48
- end
49
-
50
40
  def stdout(&block)
51
41
  stdout_io = StringIO.new
52
42
  yield stdout_io
@@ -54,3 +44,47 @@ def stdout(&block)
54
44
  stdout_io.read
55
45
  end
56
46
 
47
+ module SetupThemeHelpers
48
+ def setup_app_with_theme(theme, theme_options = {})
49
+ setup_base_rails
50
+ @template_root = File.join(File.dirname(__FILE__), "fixtures", theme)
51
+ FileUtils.chdir(@template_root) do
52
+ if theme_options.delete(:setup_defaults)
53
+ FileUtils.cp_r("expected_install_theme.yml", "install_theme.yml")
54
+ else
55
+ FileUtils.rm_rf("install_theme.yml")
56
+ end
57
+ end
58
+ @stdout = stdout do |stdout|
59
+ @theme = InstallTheme.new({:template_root => @template_root,
60
+ :rails_root => @target_application,
61
+ :stdout => stdout}.merge(theme_options))
62
+ @theme.apply_to_target(:stdout => stdout, :generator => {:collision => :force, :quiet => true})
63
+ end
64
+ @expected_application = File.join(File.dirname(__FILE__), "expected/rails", theme)
65
+ end
66
+
67
+ 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))
71
+ end
72
+
73
+ 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))
78
+ end
79
+
80
+ def setup_base_rails(options = {})
81
+ tmp_path = File.dirname(__FILE__) + "/tmp"
82
+ FileUtils.rm_rf(tmp_path)
83
+ FileUtils.mkdir_p(tmp_path )
84
+ @target_application = File.join(tmp_path, "my_app")
85
+ FileUtils.cp_r(File.dirname(__FILE__) + "/expected/rails/base_app", @target_application)
86
+ `haml --rails #{@target_application}` if options[:haml]
87
+ @target_application
88
+ end
89
+ end
90
+
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.0
4
+ version: 0.7.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-07 00:00:00 +10:00
12
+ date: 2009-10-08 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency