install_theme 0.6.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,15 @@
1
+ === 0.7.0 / 2009-10-07
2
+
3
+ Major:
4
+ * Reversed the order of the first two CLI arguments (in preparation for path/to/template to be optional)
5
+ * content_path and --partial flags are optional after a template is installed once
6
+
7
+ Minor:
8
+ * README describes how Theme Reuse works
9
+ * CLI shows help/error message if content_path isn't passed as argument or available from defaults file
10
+ * improved the clean_stylesheet helper and fixed the corresponding test
11
+ * if stylesheet path is root of template folder, then use image path for path substitutions
12
+
1
13
  === 0.6.2 / 2009-10-06
2
14
 
3
15
  Major:
data/README.rdoc CHANGED
@@ -18,14 +18,20 @@ in action.
18
18
 
19
19
  Simple case:
20
20
 
21
- install_theme path/to/template path/to/rails_app content_path
21
+ install_theme path/to/rails_app path/to/template content_path
22
22
 
23
23
  Replace some DOM content with <%= yield :some_label %> with --partial:
24
24
 
25
- install_theme path/to/app path/to/rails_app #content_box \
25
+ install_theme path/to/rails_app path/to/template #content_box \
26
26
  --partial "header:#header h2" \
27
27
  --partial sidebar:#sidebar"
28
28
 
29
+ NOTE: The order of the first two arguments has been reversed since the original
30
+ public release. This is in preparation for path/to/template to be optional.
31
+
32
+ Similarly, in 0.7.0 the content_path argument is optional after the first time
33
+ you install a specific theme (see 'Theme Reuse' section).
34
+
29
35
  === Haml Support:
30
36
 
31
37
  If your application has Haml installed, the template/theme is automatically converted
@@ -35,6 +41,18 @@ Alternately, you can pass the flag --haml to force it.
35
41
 
36
42
  Or pass the flag --erb to force erb template generation.
37
43
 
44
+ === Theme Reuse:
45
+
46
+ Once you have installed a theme into an application once, that theme remembers the content path
47
+ and partials you selected. You won't have to type them again.
48
+
49
+ That is, after running the `install_theme` command above, you could apply the same theme
50
+ to another Rails app using just:
51
+
52
+ install_theme path/to/app path/to/another_rails_app
53
+
54
+ The defaults for each theme are stored in a file `install_theme.yml`.
55
+
38
56
  == INSTALL:
39
57
 
40
58
  install_theme is distributed as a RubyGem, which installs the command line app automatically:
data/Rakefile CHANGED
@@ -14,7 +14,6 @@ $hoe = Hoe.spec 'install_theme' do
14
14
  extra_deps << ['hpricot','>= 0.8.1']
15
15
  extra_deps << ['rubigen','>= 1.5.2']
16
16
  extra_dev_deps << ['drnic-haml', '>= 2.3.0']
17
- extra_dev_deps << ['rails', '2.3.4']
18
17
  end
19
18
 
20
19
  require 'newgem/tasks'
data/lib/install_theme.rb CHANGED
@@ -10,10 +10,11 @@ require 'sass/css'
10
10
  require 'haml/exec'
11
11
 
12
12
  class InstallTheme
13
- VERSION = "0.6.2"
13
+ VERSION = "0.7.0"
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 :defaults_file
17
18
  attr_reader :content_path, :partials
18
19
  attr_reader :stdout
19
20
  attr_reader :original_named_yields, :original_body_content
@@ -22,14 +23,19 @@ class InstallTheme
22
23
  @template_root = File.expand_path(options[:template_root] || File.dirname('.'))
23
24
  @rails_root = File.expand_path(options[:rails_root] || File.dirname('.'))
24
25
  @template_type = (options[:template_type] || detect_template).to_s
25
- @index_path = options[:index_path] || "index.html"
26
- @content_path = options[:content_path] || "content"
27
- @partials = options[:partials] || {}
26
+ @defaults_file = options[:defaults_file] || "install_theme.yml"
28
27
  @stylesheet_dir = options[:stylesheet_dir] || detect_stylesheet_dir
29
28
  @javascript_dir = options[:javascript_dir] || detect_javascript_dir
30
29
  @image_dir = options[:image_dir] || detect_image_dir
31
30
  @stdout = options[:stdout] || $stdout
31
+
32
+ load_template_defaults unless options[:ignore_defaults]
33
+ @index_path = options[:index_path] || @index_path || "index.html"
34
+ @content_path = options[:content_path] || @content_path
35
+ @partials ||= {}
36
+ @partials.merge!(options[:partials]) if options[:partials]
32
37
 
38
+ create_install_theme_yml
33
39
  setup_template_temp_path
34
40
  end
35
41
 
@@ -70,8 +76,23 @@ class InstallTheme
70
76
  template_type == 'erb'
71
77
  end
72
78
 
79
+ def valid?
80
+ template_root && File.exist?(template_root) &&
81
+ rails_root && File.exist?(rails_root) &&
82
+ content_path
83
+ end
84
+
73
85
  protected
74
86
 
87
+ def load_template_defaults
88
+ return unless File.exist?(File.join(template_root, defaults_file))
89
+ require "yaml"
90
+ defaults = YAML.load_file(File.join(template_root, defaults_file))
91
+ @content_path = defaults["content_path"]
92
+ @partials = defaults["partials"]
93
+ @index_path = defaults["index_path"]
94
+ end
95
+
75
96
  def convert_file_to_layout(html_path, layout_path)
76
97
  File.open(File.join(template_temp_path, layout_path), "w") do |f|
77
98
  contents = File.read(File.join(template_root, html_path)).gsub(/\r/, '')
@@ -249,6 +270,12 @@ class InstallTheme
249
270
  def in_rails_root(&block)
250
271
  FileUtils.chdir(rails_root, &block)
251
272
  end
273
+
274
+ def create_install_theme_yml
275
+ config = { "content_path" => content_path, "partials" => partials }
276
+ install_theme_yml = File.join(template_root, 'install_theme.yml')
277
+ File.open(install_theme_yml, 'w') {|f| f << config.to_yaml}
278
+ end
252
279
 
253
280
  def detect_template
254
281
  if detect_template_haml
@@ -302,7 +329,10 @@ class InstallTheme
302
329
  end
303
330
 
304
331
  def clean_stylesheet(contents)
305
- contents.gsub(%r{url\((["']?)[\./]*(?:#{image_dir}|#{stylesheet_dir}|)\/?}, 'url(\1/images/')
332
+ contents.gsub(%r{url\((["']?)[\./]*(#{image_dir}|#{stylesheet_dir}|)\/?}) do |match|
333
+ target_path = (!stylesheet_dir.blank? && $2 == stylesheet_dir) ? "stylesheets" : "images"
334
+ "url(#{$1}/#{target_path}/"
335
+ end
306
336
  end
307
337
 
308
338
  def show_readme
@@ -28,7 +28,7 @@ class InstallTheme
28
28
  "Example using XPath: --partial \"header://div[@id='header']\"") do |arg|
29
29
  options[:partials] ||= {}
30
30
  key, css_path = arg.split(/\s*:\s*/)[0..1]
31
- options[:partials][key.strip.to_sym] = css_path.strip
31
+ options[:partials][key.strip] = css_path.strip
32
32
  end
33
33
  opts.on("-h", "--help",
34
34
  "Show this help message.") { |arg| stdout.puts opts; exit }
@@ -37,14 +37,14 @@ class InstallTheme
37
37
  ) { |arg| stdout.puts InstallTheme::VERSION; exit }
38
38
  opts.parse!(arguments)
39
39
  end
40
- options[:template_root] = arguments.shift
41
40
  options[:rails_root] = arguments.shift
41
+ options[:template_root] = arguments.shift
42
42
  options[:content_path] = arguments.shift
43
- unless options[:template_root] && options[:rails_root]
44
- stdout.puts "trying"
43
+ theme = InstallTheme.new(options)
44
+ unless theme.valid?
45
45
  stdout.puts parser; exit
46
46
  end
47
- InstallTheme.new(options).apply_to_target
47
+ theme.apply_to_target
48
48
  end
49
49
  end
50
50
  end
@@ -4,7 +4,7 @@
4
4
 
5
5
 
6
6
  img, div, a
7
- behavior: url(css/iepngfix.htc)
7
+ behavior: url(/stylesheets/iepngfix.htc)
8
8
 
9
9
 
10
10
  body
@@ -260,7 +260,7 @@ td, th
260
260
  thead
261
261
 
262
262
  #infowrap li
263
- display: inline:
263
+ display: inline:
264
264
 
265
265
 
266
266
 
@@ -294,7 +294,7 @@ thead
294
294
  text-align: left
295
295
  float: left
296
296
  padding: 0 2px
297
- font-size: 14px
297
+ font-size: 14px
298
298
 
299
299
 
300
300
  a
@@ -5,7 +5,7 @@
5
5
  margin:0;
6
6
  padding:0;
7
7
  }
8
- img, div,a { behavior: url(css/iepngfix.htc) }
8
+ img, div,a { behavior: url(/stylesheets/iepngfix.htc) }
9
9
  body{
10
10
  font-size: 12px;
11
11
  font-family: Arial, Tahoma, Verdana;
@@ -2,20 +2,21 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
  require 'install_theme/cli'
3
3
 
4
4
  describe InstallTheme::CLI, "execute" do
5
- before(:each) do
5
+ it("parses arguments and run generator") do
6
6
  theme = stub
7
7
  InstallTheme.should_receive(:new).
8
- with(:template_root => "path/to/app",
8
+ with(:template_root => "path/to/template",
9
9
  :rails_root => "path/to/rails_app",
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
14
  ).
15
15
  and_return(theme)
16
+ theme.should_receive(:valid?).and_return(true)
16
17
  theme.should_receive(:apply_to_target)
17
18
  @stdout = stdout do |stdout_io|
18
- InstallTheme::CLI.execute(stdout_io, %w[path/to/app path/to/rails_app #content_box
19
+ InstallTheme::CLI.execute(stdout_io, %w[path/to/rails_app path/to/template #content_box
19
20
  --index_path=root.html
20
21
  --haml
21
22
  --partial header:#header\ h2
@@ -23,6 +24,19 @@ describe InstallTheme::CLI, "execute" do
23
24
  ])
24
25
  end
25
26
  end
26
-
27
- it("parses arguments and run generator") { }
27
+
28
+ it("allows for content_path and partials to be derived from defaults file") do
29
+ theme = stub
30
+ InstallTheme.should_receive(:new).
31
+ with(:template_root => "path/to/template",
32
+ :rails_root => "path/to/rails_app",
33
+ :content_path => nil
34
+ ).
35
+ and_return(theme)
36
+ theme.should_receive(:valid?).and_return(true)
37
+ theme.should_receive(:apply_to_target)
38
+ @stdout = stdout do |stdout_io|
39
+ InstallTheme::CLI.execute(stdout_io, %w[path/to/rails_app path/to/template])
40
+ end
41
+ end
28
42
  end
@@ -4,17 +4,20 @@ describe InstallTheme do
4
4
  context "bloganje theme to haml" do
5
5
  before(:all) do
6
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"))
7
9
  @stdout = stdout do |stdout|
8
- @theme = InstallTheme.new(:template_root => File.dirname(__FILE__) + "/fixtures/bloganje",
9
- :rails_root => @target_application,
10
- :content_path => "content",
11
- :partials => { :header => '#header h2', :sidebar => '#sidebar' },
12
- :stdout => 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)
13
15
  @theme.apply_to_target(:stdout => stdout, :generator => {:collision => :force, :quiet => true})
14
16
  end
15
17
  @expected_application = File.dirname(__FILE__) + "/expected/rails/bloganje"
16
18
  end
17
19
  it { @theme.should be_haml }
20
+ it { @theme.should be_valid }
18
21
 
19
22
  %w[app/views/layouts/application.html.haml
20
23
  app/views/layouts/_header.html.haml
@@ -4,11 +4,13 @@ describe InstallTheme do
4
4
  context "bloganje theme to ERb using CSS path" do
5
5
  before(:all) do
6
6
  setup_base_rails
7
+ @template_root = File.dirname(__FILE__) + "/fixtures/bloganje"
8
+ FileUtils.rm_rf(File.join(@template_root, "install_theme.yml"))
7
9
  @stdout = stdout do |stdout|
8
- @theme = InstallTheme.new(:template_root => File.dirname(__FILE__) + "/fixtures/bloganje",
10
+ @theme = InstallTheme.new(:template_root => @template_root,
9
11
  :rails_root => @target_application,
10
12
  :content_path => "#content",
11
- :partials => { :header => '#header h2', :sidebar => '#sidebar' },
13
+ :partials => { "header" => '#header h2', "sidebar" => '#sidebar' },
12
14
  :stdout => stdout)
13
15
  @theme.apply_to_target(:stdout => stdout, :generator => {:collision => :force, :quiet => true})
14
16
  end
@@ -17,6 +19,7 @@ describe InstallTheme do
17
19
  it { @theme.stylesheet_dir.should == "css" }
18
20
  it { @theme.image_dir.should == "img" }
19
21
  it { @theme.should be_erb }
22
+ it { @theme.should be_valid }
20
23
 
21
24
  %w[app/views/layouts/application.html.erb
22
25
  app/views/layouts/_header.html.erb
@@ -24,7 +27,7 @@ describe InstallTheme do
24
27
  app/helpers/template_helper.rb
25
28
  public/stylesheets/style.css
26
29
  public/stylesheets/theme.css].each do |matching_file|
27
- it do
30
+ it "should having matching file #{matching_file}" do
28
31
  expected = clean_file File.join(@expected_application, matching_file), 'expected'
29
32
  actual = clean_file File.join(@target_application, matching_file), 'actual'
30
33
  diff = `diff #{expected} #{actual} 2> /dev/null`
@@ -40,16 +43,24 @@ describe InstallTheme do
40
43
  it { should include("<% content_for :header do -%>\n My eCommerce Admin area\n<% end -%>") }
41
44
  it { should include('<div id="rightnow">') }
42
45
  end
46
+ it "should create install_theme.yml containing the partial information" do
47
+ expected = clean_file File.join(@template_root, "expected_install_theme.yml"), 'expected'
48
+ actual = clean_file File.join(@template_root, "install_theme.yml"), 'actual'
49
+ diff = `diff #{expected} #{actual} 2> /dev/null`
50
+ rputs diff unless diff.strip.empty?
51
+ diff.strip.should == ""
52
+ end
43
53
  end
44
54
 
45
55
  context "the-hobbit-website-template theme to ERb using xpath" do
46
56
  before(:all) do
47
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"))
48
60
  @stdout = stdout do |stdout|
49
- @theme = InstallTheme.new(
50
- :template_root => File.dirname(__FILE__) + "/fixtures/the-hobbit-website-template",
61
+ @theme = InstallTheme.new(:template_root => @template_root,
51
62
  :rails_root => @target_application,
52
- :partials => { :menu => "//div[@class='navigation']", :subtitle => "//div[@class='header']/p" },
63
+ :partials => { "menu" => "//div[@class='navigation']", "subtitle" => "//div[@class='header']/p" },
53
64
  :content_path => "//div[@class='content']",
54
65
  :stdout => stdout)
55
66
  @theme.apply_to_target(:generator => {:collision => :force, :quiet => true})
@@ -58,6 +69,7 @@ describe InstallTheme do
58
69
  end
59
70
  it { @theme.stylesheet_dir.should == "" }
60
71
  it { @theme.image_dir.should == "img" }
72
+ it { @theme.should be_valid }
61
73
 
62
74
  %w[app/views/layouts/application.html.erb
63
75
  app/helpers/template_helper.rb
@@ -72,6 +84,64 @@ describe InstallTheme do
72
84
  diff.strip.should == ""
73
85
  end
74
86
  end
87
+ it "should create install_theme.yml containing the partial information" do
88
+ expected = clean_file File.join(@template_root, "expected_install_theme.yml"), 'expected'
89
+ actual = clean_file File.join(@template_root, "install_theme.yml"), 'actual'
90
+ diff = `diff #{expected} #{actual} 2> /dev/null`
91
+ rputs diff unless diff.strip.empty?
92
+ diff.strip.should == ""
93
+ end
94
+ end
95
+
96
+ context "use install_theme.yml for defaults" do
97
+ 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"
110
+ end
111
+ it { File.should be_exist(File.join(@template_root, "install_theme.yml")) }
112
+ it { @theme.content_path.should == "#content" }
113
+ it { @theme.should be_valid }
114
+ %w[app/views/layouts/application.html.erb
115
+ app/views/layouts/_header.html.erb
116
+ app/views/layouts/_sidebar.html.erb
117
+ app/helpers/template_helper.rb
118
+ public/stylesheets/style.css
119
+ public/stylesheets/theme.css].each do |matching_file|
120
+ it "should having matching file #{matching_file}" do
121
+ expected = clean_file File.join(@expected_application, matching_file), 'expected'
122
+ actual = clean_file File.join(@target_application, matching_file), 'actual'
123
+ diff = `diff #{expected} #{actual} 2> /dev/null`
124
+ rputs diff unless diff.strip.empty?
125
+ diff.strip.should == ""
126
+ end
127
+ end
128
+ end
129
+
130
+ context "invalid if no content_path explicitly or via defaults file" do
131
+ before(:all) do
132
+ setup_base_rails
133
+ @template_root = File.dirname(__FILE__) + "/fixtures/bloganje"
134
+ FileUtils.rm_rf(File.join(@template_root, "install_theme.yml"))
135
+ @stdout = stdout do |stdout|
136
+ @theme = InstallTheme.new(:template_root => @template_root,
137
+ :rails_root => @target_application,
138
+ :stdout => stdout)
139
+ @theme.apply_to_target(:stdout => stdout, :generator => {:collision => :force, :quiet => true})
140
+ end
141
+ @expected_application = File.dirname(__FILE__) + "/expected/rails/bloganje"
142
+ end
143
+ it { @theme.content_path.should be_nil }
144
+ it { @theme.should_not be_valid }
75
145
  end
76
146
  end
77
147
 
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.2
4
+ version: 0.7.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-06 00:00:00 +10:00
12
+ date: 2009-10-07 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -42,16 +42,6 @@ dependencies:
42
42
  - !ruby/object:Gem::Version
43
43
  version: 2.3.0
44
44
  version:
45
- - !ruby/object:Gem::Dependency
46
- name: rails
47
- type: :development
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "="
52
- - !ruby/object:Gem::Version
53
- version: 2.3.4
54
- version:
55
45
  - !ruby/object:Gem::Dependency
56
46
  name: hoe
57
47
  type: :development