convert_theme 0.1.0 → 0.2.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.
Files changed (35) hide show
  1. data/History.txt +15 -1
  2. data/Manifest.txt +1 -0
  3. data/Rakefile +5 -3
  4. data/lib/convert_theme/cli.rb +5 -0
  5. data/lib/convert_theme/convert_theme_generator.rb +20 -0
  6. data/lib/convert_theme.rb +36 -5
  7. data/spec/convert_theme_cli_spec.rb +10 -9
  8. data/spec/convert_theme_spec.rb +14 -10
  9. data/spec/spec_helper.rb +7 -0
  10. data/spec/tmp/my_app/public/images/Thumbs.db +0 -0
  11. data/spec/tmp/my_app/public/images/add-icon.gif +0 -0
  12. data/spec/tmp/my_app/public/images/arrow.gif +0 -0
  13. data/spec/tmp/my_app/public/images/bg-center-column.jpg +0 -0
  14. data/spec/tmp/my_app/public/images/bg-dotted.gif +0 -0
  15. data/spec/tmp/my_app/public/images/bg-footer.gif +0 -0
  16. data/spec/tmp/my_app/public/images/bg-header.gif +0 -0
  17. data/spec/tmp/my_app/public/images/bg-left-header.gif +0 -0
  18. data/spec/tmp/my_app/public/images/bg-left-link.gif +0 -0
  19. data/spec/tmp/my_app/public/images/bg-middle.gif +0 -0
  20. data/spec/tmp/my_app/public/images/bg-orange-button.gif +0 -0
  21. data/spec/tmp/my_app/public/images/bg-select.gif +0 -0
  22. data/spec/tmp/my_app/public/images/bg-th-left.gif +0 -0
  23. data/spec/tmp/my_app/public/images/bg-th-right.gif +0 -0
  24. data/spec/tmp/my_app/public/images/edit-icon.gif +0 -0
  25. data/spec/tmp/my_app/public/images/hr.gif +0 -0
  26. data/spec/tmp/my_app/public/images/login-icon.gif +0 -0
  27. data/spec/tmp/my_app/public/images/logo.gif +0 -0
  28. data/spec/tmp/my_app/public/images/save-icon.gif +0 -0
  29. data/spec/tmp/my_app/public/images/tab-active-left.gif +0 -0
  30. data/spec/tmp/my_app/public/images/tab-active-right.gif +0 -0
  31. data/spec/tmp/my_app/public/images/tab-active.gif +0 -0
  32. data/spec/tmp/my_app/public/images/tab-left.gif +0 -0
  33. data/spec/tmp/my_app/public/images/tab-right.gif +0 -0
  34. data/spec/tmp/my_app/public/images/tab.gif +0 -0
  35. metadata +12 -1
data/History.txt CHANGED
@@ -1,4 +1,18 @@
1
- === 0.0.1 2009-09-26
1
+ === 0.2.0 / 2009-09-26
2
+
3
+ Major:
4
+ * Using Rubigen to install files, which means you get
5
+ prompted about conflicts.
6
+
7
+ Commits:
8
+ * Running specs no longer spews out the rubigen create/exists logs
9
+ * Better checking for file vs directory?
10
+ * using rubigen run install modified template files into target rails app
11
+ * wired in more options to CLI
12
+ * adding hoe-git plugin
13
+ * Added README content
14
+
15
+ === 0.1.0 2009-09-26
2
16
 
3
17
  * 1 major enhancement:
4
18
  * Initial release
data/Manifest.txt CHANGED
@@ -6,6 +6,7 @@ Rakefile
6
6
  bin/convert_theme
7
7
  lib/convert_theme.rb
8
8
  lib/convert_theme/cli.rb
9
+ lib/convert_theme/convert_theme_generator.rb
9
10
  script/console
10
11
  script/destroy
11
12
  script/generate
data/Rakefile CHANGED
@@ -4,15 +4,17 @@ require 'fileutils'
4
4
  require './lib/convert_theme'
5
5
 
6
6
  Hoe.plugin :newgem
7
+ Hoe.plugin :git
7
8
 
8
9
  # Generate all the Rake tasks
9
10
  # Run 'rake -T' to see list of generated tasks (from gem root directory)
10
11
  $hoe = Hoe.spec 'convert_theme' do
11
12
  developer 'Dr Nic Williams', 'drnicwilliams@gmail.com'
12
13
  self.rubyforge_name = "drnicutilities"
13
- self.extra_deps << ['hpricot','>= 0.8.1']
14
- self.extra_dev_deps << ['rails', '2.3.4']
15
- self.extra_dev_deps << ['haml']
14
+ extra_deps << ['hpricot','>= 0.8.1']
15
+ extra_deps << ['rubigen','>= 1.5.2']
16
+ extra_dev_deps << ['rails', '2.3.4']
17
+ extra_dev_deps << ['haml']
16
18
  end
17
19
 
18
20
  require 'newgem/tasks'
@@ -18,6 +18,11 @@ class ConvertTheme
18
18
  opts.on("--content_id=CONTENT_ID", String,
19
19
  "DOM id for the main DOM element for the <%= yield %>.",
20
20
  "Default: content") { |arg| options[:content_id] = arg }
21
+ opts.on("--haml",
22
+ "Generate HAML templates.") { |arg| options[:template_type] = 'haml' }
23
+ opts.on("--index_path=index.html", String,
24
+ "HTML page to use for application layout.",
25
+ "Default: index.html") { |arg| options[:index_path] = arg }
21
26
  opts.on("-h", "--help",
22
27
  "Show this help message.") { stdout.puts opts; exit }
23
28
  opts.parse!(arguments)
@@ -0,0 +1,20 @@
1
+ class ConvertTheme::ConvertThemeGenerator < RubiGen::Base
2
+ # NOTE: runtime_options[:source] needs to be passed in to #new
3
+
4
+ def manifest
5
+ record do |m|
6
+ files = Dir[File.join(source_root, "**/*")].map do |f|
7
+ f.gsub(source_root, "").gsub(%r{^/}, '')
8
+ end
9
+ directories = files.map { |f| File.dirname(f) }.uniq.sort
10
+ directories.each do |dir|
11
+ m.directory dir
12
+ end
13
+ files.sort.each do |f|
14
+ next if File.directory?(File.join(source_root, f))
15
+ m.file f, f
16
+ end
17
+ end
18
+ end
19
+
20
+ end
data/lib/convert_theme.rb CHANGED
@@ -2,9 +2,11 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  require "hpricot"
5
+ require "rubigen"
6
+ require 'rubigen/scripts/generate'
5
7
 
6
8
  class ConvertTheme
7
- VERSION = "0.1.0"
9
+ VERSION = "0.2.0"
8
10
 
9
11
  attr_reader :template_root, :index_path, :rails_path, :template_type
10
12
  attr_reader :stylesheet_dir, :javascript_dir, :image_dir
@@ -17,13 +19,16 @@ class ConvertTheme
17
19
  @stylesheet_dir = options[:stylesheet_dir] || detect_stylesheet_dir
18
20
  @javascript_dir = options[:javascript_dir] || detect_javascript_dir
19
21
  @image_dir = options[:image_dir] || detect_image_dir
22
+ @stdout = options[:stdout] || $stdout
23
+
24
+ setup_template_temp_path
20
25
  end
21
26
 
22
27
  def apply_to(rails_path, options = {})
23
28
  @rails_path = rails_path
24
29
  @template_type = (options[:template_type] || detect_template).to_s
25
30
 
26
- File.open(File.join(rails_path, 'app/views/layouts/application.html.erb'), "w") do |file|
31
+ File.open(File.join(template_temp_path, 'app/views/layouts/application.html.erb'), "w") do |file|
27
32
  index_file = File.read(File.join(template_root, index_path)).gsub(/\r/, '')
28
33
  doc = Hpricot(index_file)
29
34
  doc.search("##{content_id}").each do |div|
@@ -37,17 +42,43 @@ class ConvertTheme
37
42
  end
38
43
 
39
44
  template_stylesheets.each do |file|
40
- File.open(File.join(rails_path, 'public/stylesheets', File.basename(file)), "w") do |f|
45
+ File.open(File.join(template_temp_path, 'public/stylesheets', File.basename(file)), "w") do |f|
41
46
  contents = File.read(file)
42
47
  contents.gsub!(%r{url\((["']?)[./]*#{image_dir}}, 'url(\1/images')
43
48
  f << contents
44
49
  end
45
50
  end
46
51
  template_javascripts.each do |file|
47
- FileUtils.cp_r(file, File.join(rails_path, 'public/javascripts'))
52
+ FileUtils.cp_r(file, File.join(template_temp_path, 'public/javascripts'))
48
53
  end
49
54
  template_images.each do |file|
50
- FileUtils.cp_r(file, File.join(rails_path, 'public/images'))
55
+ FileUtils.cp_r(file, File.join(template_temp_path, 'public/images'))
56
+ end
57
+
58
+ # now use rubigen to install the files into the rails app
59
+ # so users can get conflict resolution options from command line
60
+ RubiGen::Base.reset_sources
61
+ RubiGen::Base.prepend_sources(RubiGen::PathSource.new(:internal, File.dirname(__FILE__)))
62
+ generator_options = options[:generator] || {}
63
+ generator_options.merge!(:stdout => @stdout, :no_exit => true,
64
+ :source => template_temp_path, :destination => rails_path)
65
+ RubiGen::Scripts::Generate.new.run(["convert_theme"], generator_options)
66
+ end
67
+
68
+ # This generator's templates folder is temporary
69
+ # and is accessed via source_root within the generator.
70
+ def template_temp_path
71
+ @template_temp_path ||= begin
72
+ tmp_dir = ENV['TMPDIR'] || '/tmp'
73
+ template_path = File.join(tmp_dir, "convert_theme", "templates")
74
+ end
75
+ end
76
+
77
+ def setup_template_temp_path
78
+ FileUtils.rm_rf(template_temp_path)
79
+ FileUtils.mkdir_p(template_temp_path)
80
+ %w[app/views/layouts public/images public/javascripts public/stylesheets].each do |app_path|
81
+ FileUtils.mkdir_p(File.join(template_temp_path, app_path))
51
82
  end
52
83
  end
53
84
 
@@ -1,22 +1,23 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
  require 'convert_theme/cli'
3
3
 
4
- def stdout(&block)
5
- stdout_io = StringIO.new
6
- yield stdout_io
7
- stdout_io.rewind
8
- stdout_io.read
9
- end
10
-
11
4
  describe ConvertTheme::CLI, "execute" do
12
5
  before(:each) do
13
6
  theme = stub
14
7
  ConvertTheme.should_receive(:new).
15
- with(:template_root => "path/to/app", :content_id => "content_box").
8
+ with(:template_root => "path/to/app",
9
+ :content_id => "content_box",
10
+ :index_path => "root.html",
11
+ :template_type => "haml"
12
+ ).
16
13
  and_return(theme)
17
14
  theme.should_receive(:apply_to).with(".")
18
15
  @stdout = stdout do |stdout_io|
19
- ConvertTheme::CLI.execute(stdout_io, ["path/to/app", ".", "--content_id=content_box"])
16
+ ConvertTheme::CLI.execute(stdout_io, %w[path/to/app .
17
+ --content_id=content_box
18
+ --index_path=root.html
19
+ --haml
20
+ ])
20
21
  end
21
22
  end
22
23
 
@@ -4,8 +4,10 @@ describe ConvertTheme do
4
4
  context "bloganje theme to ERb" do
5
5
  before do
6
6
  setup_base_rails
7
- @theme = ConvertTheme.new(:template_root => File.dirname(__FILE__) + "/fixtures/bloganje")
8
- @theme.apply_to(@target_application)
7
+ stdout do |stdout|
8
+ @theme = ConvertTheme.new(:template_root => File.dirname(__FILE__) + "/fixtures/bloganje", :stdout => stdout)
9
+ @theme.apply_to(@target_application, :generator => {:collision => :force, :quiet => true})
10
+ end
9
11
  @expected_application = File.dirname(__FILE__) + "/expected/rails/bloganje"
10
12
  end
11
13
  it { @theme.should be_erb }
@@ -18,7 +20,7 @@ describe ConvertTheme do
18
20
  it do
19
21
  expected = clean_file(File.join(@expected_application, matching_file))
20
22
  actual = File.join(@target_application, matching_file)
21
- diff = `diff #{expected} #{actual}`
23
+ diff = `diff #{expected} #{actual} 2> /dev/null`
22
24
  rputs diff unless diff.strip.empty?
23
25
  diff.strip.should == ""
24
26
  end
@@ -31,7 +33,7 @@ describe ConvertTheme do
31
33
  it do
32
34
  expected = File.join(@expected_application, matching_file)
33
35
  actual = File.join(@target_application, matching_file)
34
- diff = `diff #{expected} #{actual}`
36
+ diff = `diff #{expected} #{actual} 2> /dev/null`
35
37
  rputs diff unless diff.strip.empty?
36
38
  diff.strip.should == ""
37
39
  end
@@ -42,10 +44,12 @@ describe ConvertTheme do
42
44
  context "webresourcedepot theme to ERb" do
43
45
  before do
44
46
  setup_base_rails
45
- @theme = ConvertTheme.new(
46
- :template_root => File.dirname(__FILE__) + "/fixtures/webresourcedepot",
47
- :content_id => "center-column")
48
- @theme.apply_to(@target_application)
47
+ stdout do |stdout|
48
+ @theme = ConvertTheme.new(
49
+ :template_root => File.dirname(__FILE__) + "/fixtures/webresourcedepot",
50
+ :content_id => "center-column", :stdout => $stdout)
51
+ @theme.apply_to(@target_application, :generator => {:collision => :force, :quiet => true})
52
+ end
49
53
  @expected_application = File.dirname(__FILE__) + "/expected/rails/webresourcedepot"
50
54
  end
51
55
  it { @theme.should be_erb }
@@ -54,7 +58,7 @@ describe ConvertTheme do
54
58
  it do
55
59
  expected = clean_file(File.join(@expected_application, matching_file))
56
60
  actual = File.join(@target_application, matching_file)
57
- diff = `diff #{expected} #{actual}`
61
+ diff = `diff #{expected} #{actual} 2> /dev/null`
58
62
  rputs diff unless diff.strip.empty?
59
63
  diff.strip.should == ""
60
64
  end
@@ -66,7 +70,7 @@ describe ConvertTheme do
66
70
  it do
67
71
  expected = File.join(@expected_application, matching_file)
68
72
  actual = File.join(@target_application, matching_file)
69
- diff = `diff #{expected} #{actual}`
73
+ diff = `diff #{expected} #{actual} 2> /dev/null`
70
74
  rputs diff unless diff.strip.empty?
71
75
  diff.strip.should == ""
72
76
  end
data/spec/spec_helper.rb CHANGED
@@ -37,3 +37,10 @@ def setup_base_rails(options = {})
37
37
  @target_application
38
38
  end
39
39
 
40
+ def stdout(&block)
41
+ stdout_io = StringIO.new
42
+ yield stdout_io
43
+ stdout_io.rewind
44
+ stdout_io.read
45
+ end
46
+
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dr Nic Williams
@@ -22,6 +22,16 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 0.8.1
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rubigen
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.5.2
34
+ version:
25
35
  - !ruby/object:Gem::Dependency
26
36
  name: rails
27
37
  type: :development
@@ -80,6 +90,7 @@ files:
80
90
  - bin/convert_theme
81
91
  - lib/convert_theme.rb
82
92
  - lib/convert_theme/cli.rb
93
+ - lib/convert_theme/convert_theme_generator.rb
83
94
  - script/console
84
95
  - script/destroy
85
96
  - script/generate