ymdp 0.1.11 → 0.1.12

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/Gemfile CHANGED
@@ -19,6 +19,6 @@ gem "ymdp_generator"
19
19
  gem "ymdt"
20
20
  gem "yrb"
21
21
  gem "idiom"
22
- gem "w3c_validators"
22
+ gem "epic"
23
23
 
24
24
  bin_path "vendor/bin"
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 "w3c_validators", ">= 0"
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.11
1
+ 0.1.12
@@ -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
- @wip
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
@@ -13,8 +13,7 @@ require 'erb'
13
13
  require 'set'
14
14
 
15
15
  require 'base'
16
- require 'validator/validator'
17
16
  require 'view/tag_helper'
18
17
  require 'view/asset_tag_helper'
19
- require 'support/file'
18
+ require 'f'
20
19
  require 'configuration/config'
@@ -1,4 +1,4 @@
1
- require 'support/file'
1
+ require 'f'
2
2
  require 'grit'
3
3
  include Grit
4
4
 
@@ -275,13 +275,17 @@ module YMDP
275
275
  #
276
276
  def write_template(result)
277
277
  result = super(result)
278
-
279
- if CONFIG.validate_html? && !YMDP::Validator::HTML.validate(destination_path)
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 = YMDP::Compressor::JavaScript.compress(tmp_filename) if CONFIG.compress_embedded_js?
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
- YMDP::Validator::JSON.validate(destination_path)
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
- YMDP::Validator::JavaScript.configure do |config|
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
@@ -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
- YMDP::Validator::JavaScript.validate(path)
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
- YMDP::Validator::JSON.validate(path)
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
- YMDP::Validator::HTML.validate(filename) if filename =~ /#{@path}/
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
- YMDP::Validator::JavaScript.validate(js_fragment_path)
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 'compressor/compressor'
2
- require 'validator/validator'
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 = YMDP::Compressor::JavaScript.compress(tmp_filename) if CONFIG.compress_embedded_js?
272
+ output = Epic::Compressor.new(tmp_filename).compress if configuration.compress["embedded_js"]
274
273
 
275
- YMDP::Validator::JavaScript.validate(tmp_filename) if validate && CONFIG.validate_embedded_js?
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 = YMDP::Compressor::Stylesheet.compress(tmp_filename) if CONFIG.compress_css?
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
- YMDP::Compressor::JavaScript.stub!(:compress).and_return(@compressed_template)
191
- YMDP::Validator::JavaScript.stub!(:validate)
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
- @config.stub!(:compress_embedded_js?).and_return(false)
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
- @config.stub!(:compress_embedded_js?).and_return(false)
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
- YMDP::Validator::JavaScript.should_not_receive(:validate)
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
- @config.stub!(:validate_embedded_js?).and_return(false)
244
+ @validate["embedded_js"]["build"] = false
236
245
  F.should_receive(:save_to_file).with(anything, /\/tmp\/application.js/).and_return(true)
237
- YMDP::Validator::JavaScript.should_not_receive(:validate)
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
- @config.stub!(:validate_embedded_js?).and_return(false)
251
+ @validate["embedded_js"]["build"] = false
243
252
  F.should_receive(:save_to_file).with(anything, /\/tmp\/application.js/).and_return(true)
244
- YMDP::Validator::JavaScript.should_not_receive(:validate)
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
- YMDP::Compressor::Stylesheet.stub!(:compress).and_return(@compressed_template)
304
- YMDP::Validator::Stylesheet.stub!(:validate).and_return(true)
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
- @config.stub!(:compress_css?).and_return(false)
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
- @config.stub!(:compress_css?).and_return(false)
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
- lambda {
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