ymdp 0.1.11 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/History.txt +9 -0
- data/Rakefile +4 -1
- data/VERSION +1 -1
- data/features/ymdp.feature +2 -2
- data/lib/ymdp.rb +1 -2
- data/lib/ymdp/compiler/git_helper.rb +1 -1
- data/lib/ymdp/compiler/template.rb +8 -4
- data/lib/ymdp/configuration/constants.rb +4 -1
- data/lib/ymdp/tasks/ymdp.rake +6 -22
- data/lib/ymdp/view/application_view.rb +12 -9
- data/spec/application_view_spec.rb +42 -29
- data/spec/compiler_spec.rb +1 -1
- data/spec/compiler_template_spec.rb +9 -5
- data/spec/default_settings.rb +0 -1
- data/ymdp.gemspec +8 -14
- metadata +13 -12
- data/lib/ymdp/compressor/compressor.rb +0 -134
- data/lib/ymdp/compressor/yuicompressor-2.4.2.jar +0 -0
- data/lib/ymdp/support/file.rb +0 -63
- data/lib/ymdp/validator/jslint.js +0 -5072
- data/lib/ymdp/validator/validator.rb +0 -122
- data/spec/compressor_spec.rb +0 -127
- data/spec/validator_spec.rb +0 -195
data/Gemfile
CHANGED
data/History.txt
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
== 0.1.12 2010-01-30
|
2
|
+
* major enhancements
|
3
|
+
* extracted compressor into <tt>epic</tt> gem
|
4
|
+
* extracted validator into <tt>epic</tt> gem
|
5
|
+
* minor enhancements
|
6
|
+
* raise validation errors inside <tt>application_view</tt> rather than in <tt>epic</tt>
|
7
|
+
* bug fixes
|
8
|
+
* config.yml settings for compression and validation work again
|
9
|
+
|
1
10
|
== 0.1.11 2010-01-25
|
2
11
|
* minor enhancements
|
3
12
|
* changed implementation of configuration object
|
data/Rakefile
CHANGED
@@ -11,6 +11,7 @@ begin
|
|
11
11
|
gem.homepage = "http://github.com/progressions/ymdp"
|
12
12
|
gem.authors = ["Jeff Coleman"]
|
13
13
|
gem.add_development_dependency "rspec", ">= 1.2.6"
|
14
|
+
gem.add_development_dependency "cucumber", ">= 0"
|
14
15
|
gem.add_runtime_dependency "haml", ">= 0"
|
15
16
|
gem.add_runtime_dependency "json", ">= 0"
|
16
17
|
gem.add_runtime_dependency "hpricot", ">= 0"
|
@@ -25,7 +26,7 @@ begin
|
|
25
26
|
gem.add_runtime_dependency "ymdp_generator", ">= 0"
|
26
27
|
gem.add_runtime_dependency "ymdt", ">= 0"
|
27
28
|
gem.add_runtime_dependency "yrb", ">= 0"
|
28
|
-
gem.add_runtime_dependency "
|
29
|
+
gem.add_runtime_dependency "epic", ">= 0"
|
29
30
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
30
31
|
end
|
31
32
|
Jeweler::GemcutterTasks.new
|
@@ -58,6 +59,8 @@ task :spec => [:bundle, :check_dependencies]
|
|
58
59
|
|
59
60
|
task :default => :spec
|
60
61
|
|
62
|
+
task :rcov => :bundle
|
63
|
+
|
61
64
|
require 'rake/rdoctask'
|
62
65
|
Rake::RDocTask.new do |rdoc|
|
63
66
|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.12
|
data/features/ymdp.feature
CHANGED
@@ -7,7 +7,7 @@ Feature: Configuration
|
|
7
7
|
Then my "username" setting should be "username"
|
8
8
|
And my "password" setting should be "password"
|
9
9
|
|
10
|
-
|
10
|
+
|
11
11
|
Scenario: Ensure the commit message is in the view
|
12
12
|
Given I compile the application with the message "this is my commit message"
|
13
13
|
Then I should see "this is my commit message" in "servers/production/views/page"
|
@@ -49,7 +49,7 @@ Feature: Configuration
|
|
49
49
|
And I compile the application with the message "this should validate"
|
50
50
|
Then no exceptions should have been raised
|
51
51
|
|
52
|
-
|
52
|
+
@wip
|
53
53
|
Scenario: Build application with invalid JavaScript
|
54
54
|
Given the file "app/javascripts/invalid.js" exists with "A = function() { alert('hello'); }"
|
55
55
|
And the file "app/views/invalid.html.haml" exists with "= render :javascript => 'invalid'"
|
data/lib/ymdp.rb
CHANGED
@@ -275,13 +275,17 @@ module YMDP
|
|
275
275
|
#
|
276
276
|
def write_template(result)
|
277
277
|
result = super(result)
|
278
|
-
|
279
|
-
if
|
278
|
+
|
279
|
+
if configuration.validate["html"]["build"] && !validator.validate(destination_path)
|
280
280
|
raise "HTML Validation Errors"
|
281
281
|
end
|
282
282
|
|
283
283
|
result
|
284
284
|
end
|
285
|
+
|
286
|
+
def validator
|
287
|
+
@validator ||= Epic::Validator::HTML.new
|
288
|
+
end
|
285
289
|
end
|
286
290
|
|
287
291
|
# Process templates for JavaScript files.
|
@@ -297,7 +301,7 @@ module YMDP
|
|
297
301
|
filename = @file.split("/").last
|
298
302
|
tmp_filename = "#{TMP_PATH}/#{filename}"
|
299
303
|
F.save_to_file(result, tmp_filename)
|
300
|
-
result =
|
304
|
+
result = Epic::Compressor.new(tmp_filename).compress if configuration.compress["embedded_js"]
|
301
305
|
write_template_without_layout(result)
|
302
306
|
end
|
303
307
|
end
|
@@ -365,7 +369,7 @@ module YMDP
|
|
365
369
|
# Validate the JSON file.
|
366
370
|
#
|
367
371
|
def validate
|
368
|
-
|
372
|
+
Epic::Validator::JSON.new.validate(destination_path)
|
369
373
|
end
|
370
374
|
|
371
375
|
private
|
@@ -22,7 +22,10 @@ unless defined?(YMDP_TEST)
|
|
22
22
|
config.content_variables = @content_variables
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
Epic::Base.configure do |config|
|
26
|
+
config.base_path = BASE_PATH
|
27
|
+
config.tmp_path = TMP_PATH
|
28
|
+
config.doctype = CONFIG["validate"]["html"]["doctype"]
|
26
29
|
config.jslint_settings = @jslint_settings
|
27
30
|
end
|
28
31
|
end
|
data/lib/ymdp/tasks/ymdp.rake
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'ymdt'
|
2
|
+
require 'epic'
|
2
3
|
|
3
4
|
begin
|
4
5
|
CATEGORIES = YAML.load_file("./config/categories.yml")["categories"] unless defined?(CATEGORIES)
|
@@ -113,8 +114,6 @@ desc "Some more help"
|
|
113
114
|
task :help do
|
114
115
|
docs = <<-DOCS
|
115
116
|
|
116
|
-
#{please_install_rhino}
|
117
|
-
|
118
117
|
FOR HELP:
|
119
118
|
|
120
119
|
To list reference for all tasks:
|
@@ -268,7 +267,7 @@ namespace :validate do
|
|
268
267
|
task :javascripts do
|
269
268
|
puts "\nValidating external JavaScript assets in #{@application}..."
|
270
269
|
Dir["#{BASE_PATH}/servers/#{@application}/assets/javascripts/*.js"].each do |path|
|
271
|
-
|
270
|
+
Epic::Validator::JavaScript.new.validate(path)
|
272
271
|
end
|
273
272
|
end
|
274
273
|
|
@@ -278,7 +277,7 @@ namespace :validate do
|
|
278
277
|
Dir["./servers/#{@application}/assets/yrb/*json"].each do |json|
|
279
278
|
filename = json.split("/").last
|
280
279
|
path = "#{BASE_PATH}/servers/#{@application}/assets/yrb/#{filename}"
|
281
|
-
|
280
|
+
Epic::Validator::JSON.new.validate(path)
|
282
281
|
end
|
283
282
|
end
|
284
283
|
|
@@ -288,7 +287,7 @@ namespace :validate do
|
|
288
287
|
`rm -rf #{TMP_PATH}`
|
289
288
|
Dir.mkdir(TMP_PATH) rescue Errno::EEXIST
|
290
289
|
Dir["./servers/#{@application}/views/*"].each do |filename|
|
291
|
-
|
290
|
+
Epic::Validator::HTML.new.validate(filename) if filename =~ /#{@path}/
|
292
291
|
end
|
293
292
|
end
|
294
293
|
|
@@ -495,7 +494,7 @@ def validated_embedded_js(path)
|
|
495
494
|
(doc / "script").each { |js| f.puts js.inner_html + "\n\n" }
|
496
495
|
end
|
497
496
|
|
498
|
-
|
497
|
+
Epic::Validator::JavaScript.new.validate(js_fragment_path)
|
499
498
|
system "rm #{js_fragment_path}"
|
500
499
|
end
|
501
500
|
|
@@ -657,19 +656,4 @@ def create_directory_from_application(application, path="")
|
|
657
656
|
application_id = SERVERS[application]["application_id"]
|
658
657
|
ymdt.get(:application => application, :path => path, :application_id => application_id)
|
659
658
|
end
|
660
|
-
end
|
661
|
-
|
662
|
-
def please_install_rhino
|
663
|
-
output = <<-DOC
|
664
|
-
NOTE:
|
665
|
-
|
666
|
-
You must have Rhino installed in your classpath to validate javascripts, which is required to deploy. Download Rhino from:
|
667
|
-
|
668
|
-
http://www.mozilla.org/rhino/download.html
|
669
|
-
|
670
|
-
To put Rhino into your Java classpath, run:
|
671
|
-
|
672
|
-
mkdir -p ~/Library/Java/Extensions/
|
673
|
-
cp rhino****/js.jar ~/Library/Java/Extensions/
|
674
|
-
DOC
|
675
|
-
end
|
659
|
+
end
|
@@ -1,12 +1,11 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'rubygems'
|
2
|
+
require 'epic'
|
3
3
|
|
4
4
|
module YMDP
|
5
5
|
# Contains all the functions which are available from inside a view file, whether that view
|
6
6
|
# is HTML, JavaScript or CSS.
|
7
7
|
#
|
8
8
|
module ApplicationView
|
9
|
-
include YMDP::Compressor
|
10
9
|
|
11
10
|
extend self
|
12
11
|
|
@@ -270,13 +269,19 @@ module YMDP
|
|
270
269
|
|
271
270
|
validate = F.save_to_file(output, tmp_filename)
|
272
271
|
|
273
|
-
output =
|
272
|
+
output = Epic::Compressor.new(tmp_filename).compress if configuration.compress["embedded_js"]
|
274
273
|
|
275
|
-
|
274
|
+
if validate && configuration.validate["embedded_js"]["build"] && !js_validator.validate(tmp_filename)
|
275
|
+
raise "JavaScript Errors embedded in #{display_path(tmp_filename)}"
|
276
|
+
end
|
276
277
|
|
277
278
|
output
|
278
279
|
end
|
279
280
|
|
281
|
+
def js_validator
|
282
|
+
@js_validator ||= Epic::Validator::JavaScript.new
|
283
|
+
end
|
284
|
+
|
280
285
|
# Render a CSS partial.
|
281
286
|
#
|
282
287
|
def render_stylesheet_partial(params)
|
@@ -307,9 +312,7 @@ module YMDP
|
|
307
312
|
|
308
313
|
validate = F.save_to_file(output, tmp_filename)
|
309
314
|
|
310
|
-
output =
|
311
|
-
|
312
|
-
# YMDP::Validator::Stylesheet.validate(tmp_filename) if validate && CONFIG.validate_embedded_css?
|
315
|
+
output = Epic::Compressor.new(tmp_filename).compress if configuration.compress["css"]
|
313
316
|
|
314
317
|
output
|
315
318
|
end
|
@@ -344,6 +347,6 @@ module YMDP
|
|
344
347
|
|
345
348
|
def initialize(assets_directory)
|
346
349
|
@assets_directory = assets_directory
|
347
|
-
end
|
350
|
+
end
|
348
351
|
end
|
349
352
|
end
|
@@ -1,9 +1,19 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
+
require 'view/application_view'
|
4
|
+
|
3
5
|
describe "ApplicationView" do
|
4
6
|
before(:each) do
|
5
7
|
@assets_directory = "/om/assets/abcdefg_1"
|
8
|
+
|
9
|
+
@compress = {"obfuscate"=>true, "js_assets"=>true, "css"=>true, "embedded_js"=>true}
|
10
|
+
@validate = {"html"=>{"doctype"=>"HTML 4.0 Transitional", "build"=>true, "deploy"=>true}, "js_assets"=>{"build"=>false, "deploy"=>false}, "json_assets"=>{"build"=>false, "deploy"=>false}, "embedded_js"=>{"build"=>true, "deploy"=>true}}
|
11
|
+
|
6
12
|
@view = YMDP::View.new(@assets_directory)
|
13
|
+
@configuration = mock('configuration')
|
14
|
+
@configuration.stub!(:compress).and_return(@compress)
|
15
|
+
@configuration.stub!(:validate).and_return(@validate)
|
16
|
+
@view.stub!(:configuration).and_return(@configuration)
|
7
17
|
stub_io
|
8
18
|
end
|
9
19
|
|
@@ -180,15 +190,19 @@ describe "ApplicationView" do
|
|
180
190
|
|
181
191
|
describe ":javascript" do
|
182
192
|
before(:each) do
|
183
|
-
|
184
|
-
@config = mock('config', :compress_embedded_js? => false, :validate_embedded_js? => false)
|
185
|
-
reset_constant(:CONFIG, @config)
|
186
|
-
|
187
193
|
@compressed_template = "compressed template"
|
188
194
|
@processed_script = "<script type='text/javascript'>\n#{@processed_template}\n</script>"
|
189
195
|
@compressed_script = "<script type='text/javascript'>\n#{@compressed_template}\n</script>"
|
190
|
-
|
191
|
-
|
196
|
+
|
197
|
+
@compressor = mock('compressor')
|
198
|
+
@compressor.stub!(:compress).and_return(@compressed_template)
|
199
|
+
Epic::Compressor.stub!(:new).and_return(@compressor)
|
200
|
+
|
201
|
+
@js_validator = mock('js_validator', :validate => true)
|
202
|
+
Epic::Validator::JavaScript.stub!(:new).and_return(@js_validator)
|
203
|
+
|
204
|
+
@compress["embedded_js"] = true
|
205
|
+
@validate["embedded_js"]["build"] = true
|
192
206
|
end
|
193
207
|
|
194
208
|
describe "single" do
|
@@ -198,50 +212,45 @@ describe "ApplicationView" do
|
|
198
212
|
end
|
199
213
|
|
200
214
|
it "should render a compressed partial" do
|
201
|
-
@config.stub!(:compress_embedded_js?).and_return(true)
|
202
215
|
@view.render(:javascript => 'application').should == @compressed_script
|
203
216
|
end
|
204
217
|
|
205
218
|
it "should render an uncompressed partial" do
|
206
|
-
@
|
219
|
+
@compress["embedded_js"] = false
|
207
220
|
@view.render(:javascript => 'application').should == @processed_script
|
208
221
|
end
|
209
222
|
|
210
223
|
it "should render compressed without tags" do
|
211
|
-
@config.stub!(:compress_embedded_js?).and_return(true)
|
212
224
|
@view.render(:javascript => 'application', :tags => false).should == @compressed_template
|
213
225
|
end
|
214
226
|
|
215
227
|
it "should render uncompressed without tags" do
|
216
|
-
@
|
228
|
+
@compress["embedded_js"] = false
|
217
229
|
@view.render(:javascript => 'application', :tags => false).should == @processed_template
|
218
230
|
end
|
219
231
|
|
220
232
|
it "should validate with config true" do
|
221
|
-
@config.stub!(:validate_embedded_js?).and_return(true)
|
222
233
|
F.should_receive(:save_to_file).with(anything, /\/tmp\/application.js/).and_return(true)
|
223
|
-
YMDP::Validator::JavaScript.should_receive(:validate)
|
224
234
|
@view.render(:javascript => 'application')
|
225
235
|
end
|
226
236
|
|
227
237
|
it "should not validate with config false" do
|
228
|
-
@config.stub!(:validate_embedded_js?).and_return(true)
|
229
238
|
F.should_receive(:save_to_file).with(anything, /\/tmp\/application.js/).and_return(false)
|
230
|
-
|
239
|
+
Epic::Validator::JavaScript.should_not_receive(:validate)
|
231
240
|
@view.render(:javascript => 'application')
|
232
241
|
end
|
233
242
|
|
234
243
|
it "should not validate if file exists and config true" do
|
235
|
-
@
|
244
|
+
@validate["embedded_js"]["build"] = false
|
236
245
|
F.should_receive(:save_to_file).with(anything, /\/tmp\/application.js/).and_return(true)
|
237
|
-
|
246
|
+
Epic::Validator::JavaScript.should_not_receive(:validate)
|
238
247
|
@view.render(:javascript => 'application')
|
239
248
|
end
|
240
249
|
|
241
250
|
it "should not validate if file exists and config false" do
|
242
|
-
@
|
251
|
+
@validate["embedded_js"]["build"] = false
|
243
252
|
F.should_receive(:save_to_file).with(anything, /\/tmp\/application.js/).and_return(true)
|
244
|
-
|
253
|
+
Epic::Validator::JavaScript.should_not_receive(:validate)
|
245
254
|
@view.render(:javascript => 'application')
|
246
255
|
end
|
247
256
|
end
|
@@ -261,6 +270,7 @@ describe "ApplicationView" do
|
|
261
270
|
File.stub!(:open).with(/sidebar.js$/, anything).and_yield(@sidebar_file)
|
262
271
|
|
263
272
|
@view.stub!(:process_template).and_return("application", "sidebar")
|
273
|
+
@compress["embedded_js"] = false
|
264
274
|
end
|
265
275
|
|
266
276
|
it "should render multiple partials" do
|
@@ -286,6 +296,7 @@ describe "ApplicationView" do
|
|
286
296
|
|
287
297
|
it "should return blank string if partial can't be found" do
|
288
298
|
File.stub!(:exists?).and_return(false)
|
299
|
+
@compressor.should_receive(:compress).and_return("")
|
289
300
|
lambda {
|
290
301
|
@view.render(:javascript => 'application').should == ""
|
291
302
|
}.should_not raise_error
|
@@ -294,14 +305,15 @@ describe "ApplicationView" do
|
|
294
305
|
|
295
306
|
describe ":stylesheet" do
|
296
307
|
before(:each) do
|
297
|
-
@config = mock('config', :compress_css? => false)
|
298
|
-
reset_constant(:CONFIG, @config)
|
299
|
-
|
300
308
|
@compressed_template = "compressed template"
|
301
309
|
@processed_script = "<style type='text/css'>\n#{@processed_template}\n</style>"
|
302
310
|
@compressed_script = "<style type='text/css'>\n#{@compressed_template}\n</style>"
|
303
|
-
|
304
|
-
|
311
|
+
|
312
|
+
Epic::Compressor.stub!(:new).with("").and_return(mock('compressor', :compress => ""))
|
313
|
+
Epic::Compressor.stub!(:new).with(/.css/).and_return(mock('compressor', :compress => @compressed_template))
|
314
|
+
Epic::Validator::Stylesheet.stub!(:validate).and_return(true)
|
315
|
+
|
316
|
+
@compress["css"] = true
|
305
317
|
end
|
306
318
|
|
307
319
|
describe "single" do
|
@@ -311,22 +323,20 @@ describe "ApplicationView" do
|
|
311
323
|
end
|
312
324
|
|
313
325
|
it "should render a compressed partial" do
|
314
|
-
@config.stub!(:compress_css?).and_return(true)
|
315
326
|
@view.render(:stylesheet => 'application').should == @compressed_script
|
316
327
|
end
|
317
328
|
|
318
329
|
it "should render an uncompressed partial" do
|
319
|
-
@
|
330
|
+
@view.send(:configuration).compress["css"] = false
|
320
331
|
@view.render(:stylesheet => 'application').should == @processed_script
|
321
332
|
end
|
322
333
|
|
323
334
|
it "should render compressed without tags" do
|
324
|
-
@config.stub!(:compress_css?).and_return(true)
|
325
335
|
@view.render(:stylesheet => 'application', :tags => false).should == @compressed_template
|
326
336
|
end
|
327
337
|
|
328
338
|
it "should render uncompressed without tags" do
|
329
|
-
@
|
339
|
+
@compress["css"] = false
|
330
340
|
@view.render(:stylesheet => 'application', :tags => false).should == @processed_template
|
331
341
|
end
|
332
342
|
end
|
@@ -345,6 +355,8 @@ describe "ApplicationView" do
|
|
345
355
|
File.stub!(:open).with(/application.css$/, anything).and_yield(@application_file)
|
346
356
|
File.stub!(:open).with(/sidebar.css$/, anything).and_yield(@sidebar_file)
|
347
357
|
|
358
|
+
Epic::Compressor.stub!(:new).with(/applicationsidebar.css/).and_return(mock('compressor', :compress => "application\nsidebar"))
|
359
|
+
|
348
360
|
@view.stub!(:process_template).and_return("application", "sidebar")
|
349
361
|
end
|
350
362
|
|
@@ -371,9 +383,10 @@ describe "ApplicationView" do
|
|
371
383
|
|
372
384
|
it "should return blank string if partial can't be found" do
|
373
385
|
File.stub!(:exists?).and_return(false)
|
374
|
-
|
386
|
+
Epic::Compressor.should_receive(:new).with(/application.css/).and_return(mock('compressor', :compress => ""))
|
387
|
+
# lambda {
|
375
388
|
@view.render(:stylesheet => 'application').should == ""
|
376
|
-
}.should_not raise_error
|
389
|
+
# }.should_not raise_error
|
377
390
|
end
|
378
391
|
end
|
379
392
|
|