install_theme 0.4.0 → 0.4.1
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.
- data/History.txt +9 -0
- data/lib/install_theme.rb +25 -11
- data/spec/install_theme_spec.rb +80 -2
- data/spec/spec_helper.rb +11 -2
- metadata +1 -1
data/History.txt
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
=== 0.4.1 / 2009-09-27
|
2
|
+
|
3
|
+
Major:
|
4
|
+
* Allow a class name instead of a DOM element id for the content path
|
5
|
+
* Templates can have assets in the root of the template folder
|
6
|
+
|
7
|
+
Minor:
|
8
|
+
* cleaning actual/expected files so EOL characters aren't the cause of diff mismatches
|
9
|
+
|
1
10
|
=== 0.4.0 / 2009-09-27
|
2
11
|
|
3
12
|
* rename gem to install_theme from convert_theme
|
data/lib/install_theme.rb
CHANGED
@@ -6,7 +6,7 @@ require 'rubigen'
|
|
6
6
|
require 'rubigen/scripts/generate'
|
7
7
|
|
8
8
|
class InstallTheme
|
9
|
-
VERSION = "0.4.
|
9
|
+
VERSION = "0.4.1"
|
10
10
|
|
11
11
|
attr_reader :template_root, :rails_root, :index_path, :template_type
|
12
12
|
attr_reader :stylesheet_dir, :javascript_dir, :image_dir
|
@@ -66,10 +66,10 @@ class InstallTheme
|
|
66
66
|
protected
|
67
67
|
|
68
68
|
def convert_file_to_layout(html_path, layout_path)
|
69
|
-
File.open(File.join(template_temp_path, layout_path), "w") do |
|
69
|
+
File.open(File.join(template_temp_path, layout_path), "w") do |f|
|
70
70
|
index_file = File.read(File.join(template_root, html_path)).gsub(/\r/, '')
|
71
71
|
doc = Hpricot(index_file)
|
72
|
-
doc.search("##{content_id}").each { |elm| elm.inner_html = "<%= yield %>" }
|
72
|
+
doc.search("##{content_id},.#{content_id}").each { |elm| elm.inner_html = "<%= yield %>" }
|
73
73
|
inside_yields.to_a.each do |name, css_path|
|
74
74
|
doc.search(css_path).each do |elm|
|
75
75
|
inside_yields_originals[name] = elm.inner_html.strip
|
@@ -77,11 +77,25 @@ class InstallTheme
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
contents = doc.to_html
|
80
|
-
|
81
|
-
|
82
|
-
|
80
|
+
template_images.each do |file|
|
81
|
+
image = File.basename(file)
|
82
|
+
contents.gsub!(%r{(["'])/?[\w_\-\/]*#{image}}, '\1/images/' + image)
|
83
|
+
end
|
84
|
+
template_stylesheets.each do |file|
|
85
|
+
stylesheet = File.basename(file)
|
86
|
+
contents.gsub!(%r{(["'])/?[\w_\-\/]*#{stylesheet}}, '\1/stylesheets/' + stylesheet)
|
87
|
+
end
|
88
|
+
template_javascripts.each do |file|
|
89
|
+
javascript = File.basename(file)
|
90
|
+
contents.gsub!(%r{(["'])/?[\w_\-\/]*#{javascript}}, '\1/javascripts/' + javascript)
|
91
|
+
end
|
92
|
+
|
93
|
+
contents.gsub!(%r{(["'])/?#{image_dir}}, '\1/images') unless image_dir.blank?
|
94
|
+
contents.gsub!(%r{(["'])/?#{stylesheet_dir}}, '\1/stylesheets') unless stylesheet_dir.blank?
|
95
|
+
contents.gsub!(%r{(["'])/?#{javascript_dir}}, '\1/javascripts') unless javascript_dir.blank?
|
96
|
+
|
83
97
|
contents.sub!(%r{\s*</head>}, "\n <%= yield(:head) %>\n</head>")
|
84
|
-
|
98
|
+
f << contents
|
85
99
|
end
|
86
100
|
end
|
87
101
|
|
@@ -139,7 +153,7 @@ class InstallTheme
|
|
139
153
|
if path = Dir[File.join(template_root, '**/*.css')].first
|
140
154
|
File.dirname(path).gsub(template_root, '').gsub(%r{^/}, '')
|
141
155
|
else
|
142
|
-
'
|
156
|
+
'stylesheets'
|
143
157
|
end
|
144
158
|
end
|
145
159
|
|
@@ -160,15 +174,15 @@ class InstallTheme
|
|
160
174
|
end
|
161
175
|
|
162
176
|
def template_stylesheets
|
163
|
-
Dir[File.join(template_root, stylesheet_dir, '
|
177
|
+
Dir[File.join(template_root, stylesheet_dir, '*.css')]
|
164
178
|
end
|
165
179
|
|
166
180
|
def template_javascripts
|
167
|
-
Dir[File.join(template_root, javascript_dir, '
|
181
|
+
Dir[File.join(template_root, javascript_dir, '*.js')]
|
168
182
|
end
|
169
183
|
|
170
184
|
def template_images
|
171
|
-
Dir[File.join(template_root, image_dir, '
|
185
|
+
Dir[File.join(template_root, image_dir, '*.{jpg,png,gif}')]
|
172
186
|
end
|
173
187
|
|
174
188
|
def show_readme
|
data/spec/install_theme_spec.rb
CHANGED
@@ -25,7 +25,7 @@ describe InstallTheme do
|
|
25
25
|
it { File.should be_exist(File.join(@target_application, "app/views/layouts/application.html.erb")) }
|
26
26
|
it { File.should be_exist(File.join(@expected_application, "app/views/layouts/application.html.erb")) }
|
27
27
|
it "should create app/views/layouts/application.html.erb as a layout file" do
|
28
|
-
expected =
|
28
|
+
expected = clean_html(File.join(@expected_application, "app/views/layouts/application.html.erb"))
|
29
29
|
actual = File.join(@target_application, "app/views/layouts/application.html.erb")
|
30
30
|
diff = `diff #{expected} #{actual} 2> /dev/null`
|
31
31
|
rputs diff unless diff.strip.empty?
|
@@ -63,7 +63,7 @@ describe InstallTheme do
|
|
63
63
|
end
|
64
64
|
describe "becomes a Rails app" do
|
65
65
|
it "should create app/views/layouts/application.html.erb as a layout file" do
|
66
|
-
expected =
|
66
|
+
expected = clean_html(File.join(@expected_application, "app/views/layouts/application.html.erb"))
|
67
67
|
actual = File.join(@target_application, "app/views/layouts/application.html.erb")
|
68
68
|
diff = `diff #{expected} #{actual} 2> /dev/null`
|
69
69
|
rputs diff unless diff.strip.empty?
|
@@ -83,5 +83,83 @@ describe InstallTheme do
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
86
|
+
|
87
|
+
context "djclub theme to ERb" do
|
88
|
+
before do
|
89
|
+
setup_base_rails
|
90
|
+
@stdout = stdout do |stdout|
|
91
|
+
@theme = InstallTheme.new(
|
92
|
+
:template_root => File.dirname(__FILE__) + "/fixtures/djclub",
|
93
|
+
:rails_root => @target_application,
|
94
|
+
:inside_yields => { :menu => '#header ul' },
|
95
|
+
:content_id => "content", :stdout => stdout)
|
96
|
+
@theme.apply_to_target(:generator => {:collision => :force, :quiet => true})
|
97
|
+
end
|
98
|
+
@expected_application = File.dirname(__FILE__) + "/expected/rails/djclub"
|
99
|
+
end
|
100
|
+
it { @theme.stylesheet_dir.should == "" }
|
101
|
+
it { @theme.image_dir.should == "images" }
|
102
|
+
describe "becomes a Rails app" do
|
103
|
+
it { File.should be_exist(File.join(@target_application, "app/views/layouts/application.html.erb")) }
|
104
|
+
it "should create app/views/layouts/application.html.erb as a layout file" do
|
105
|
+
expected = clean_html(File.join(@expected_application, "app/views/layouts/application.html.erb"))
|
106
|
+
actual = File.join(@target_application, "app/views/layouts/application.html.erb")
|
107
|
+
diff = `diff #{expected} #{actual} 2> /dev/null`
|
108
|
+
rputs diff unless diff.strip.empty?
|
109
|
+
diff.strip.should == ""
|
110
|
+
end
|
111
|
+
|
112
|
+
%w[public/stylesheets/style.css].each do |matching_file|
|
113
|
+
it { File.should be_exist(File.join(@target_application, matching_file)) }
|
114
|
+
it { File.should be_exist(File.join(@expected_application, matching_file)) }
|
115
|
+
it do
|
116
|
+
expected = clean_file File.join(@expected_application, matching_file)
|
117
|
+
actual = clean_file File.join(@target_application, matching_file)
|
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
|
+
end
|
125
|
+
|
126
|
+
context "the-hobbit-website-template theme to ERb" do
|
127
|
+
before do
|
128
|
+
setup_base_rails
|
129
|
+
@stdout = stdout do |stdout|
|
130
|
+
@theme = InstallTheme.new(
|
131
|
+
:template_root => File.dirname(__FILE__) + "/fixtures/the-hobbit-website-template",
|
132
|
+
:rails_root => @target_application,
|
133
|
+
:inside_yields => { :menu => '.navigation', :subtitle => '.header p' },
|
134
|
+
:content_id => "content", :stdout => stdout)
|
135
|
+
@theme.apply_to_target(:generator => {:collision => :force, :quiet => true})
|
136
|
+
end
|
137
|
+
@expected_application = File.dirname(__FILE__) + "/expected/rails/the-hobbit-website-template"
|
138
|
+
end
|
139
|
+
it { @theme.stylesheet_dir.should == "" }
|
140
|
+
it { @theme.image_dir.should == "img" }
|
141
|
+
describe "becomes a Rails app" do
|
142
|
+
it { File.should be_exist(File.join(@target_application, "app/views/layouts/application.html.erb")) }
|
143
|
+
it "should create app/views/layouts/application.html.erb as a layout file" do
|
144
|
+
expected = clean_html(File.join(@expected_application, "app/views/layouts/application.html.erb"))
|
145
|
+
actual = File.join(@target_application, "app/views/layouts/application.html.erb")
|
146
|
+
diff = `diff #{expected} #{actual} 2> /dev/null`
|
147
|
+
rputs diff unless diff.strip.empty?
|
148
|
+
diff.strip.should == ""
|
149
|
+
end
|
150
|
+
|
151
|
+
%w[public/stylesheets/default.css].each do |matching_file|
|
152
|
+
it { File.should be_exist(File.join(@target_application, matching_file)) }
|
153
|
+
it { File.should be_exist(File.join(@expected_application, matching_file)) }
|
154
|
+
it do
|
155
|
+
expected = clean_file File.join(@expected_application, matching_file)
|
156
|
+
actual = clean_file File.join(@target_application, matching_file)
|
157
|
+
diff = `diff #{expected} #{actual} 2> /dev/null`
|
158
|
+
rputs diff unless diff.strip.empty?
|
159
|
+
diff.strip.should == ""
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
86
164
|
end
|
87
165
|
|
data/spec/spec_helper.rb
CHANGED
@@ -18,15 +18,24 @@ module Kernel
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
21
|
+
def clean_html(orig_file)
|
22
22
|
tmp_dir = ENV['TMPDIR'] || '/tmp'
|
23
|
-
file = File.join(tmp_dir, '
|
23
|
+
file = File.join(tmp_dir, 'clean_html.html')
|
24
24
|
File.open(file, "w") do |f|
|
25
25
|
f << Hpricot(open(orig_file)).to_html
|
26
26
|
end
|
27
27
|
file
|
28
28
|
end
|
29
29
|
|
30
|
+
def clean_file(orig_file)
|
31
|
+
tmp_dir = ENV['TMPDIR'] || '/tmp'
|
32
|
+
file = File.join(tmp_dir, 'clean_html.html')
|
33
|
+
File.open(file, "w") do |f|
|
34
|
+
f << File.open(orig_file).readlines.join("\n")
|
35
|
+
end
|
36
|
+
file
|
37
|
+
end
|
38
|
+
|
30
39
|
def setup_base_rails(options = {})
|
31
40
|
tmp_path = File.dirname(__FILE__) + "/tmp"
|
32
41
|
FileUtils.rm_rf(tmp_path)
|