distil 0.13.6 → 0.14.0.b

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 (59) hide show
  1. data/Rakefile +1 -0
  2. data/VERSION +1 -1
  3. data/assets/distil.js +9 -7
  4. data/bin/distil +36 -60
  5. data/distil.gemspec +17 -32
  6. data/distil.tmproj +46 -15
  7. data/lib/distil/browser.rb +30 -26
  8. data/lib/distil/configurable.rb +64 -153
  9. data/lib/distil/error-reporter.rb +22 -20
  10. data/lib/distil/file-vendor.rb +29 -0
  11. data/lib/distil/hash-additions.rb +45 -0
  12. data/lib/distil/javascript-code.rb +12 -0
  13. data/lib/distil/{task/validate-js-task.rb → javascript-file-validator.rb} +19 -23
  14. data/lib/distil/library.rb +243 -0
  15. data/lib/distil/product/cache-manifest-product.rb +21 -0
  16. data/lib/distil/product/css-product.rb +41 -23
  17. data/lib/distil/product/html-product.rb +20 -0
  18. data/lib/distil/product/javascript-product.rb +122 -111
  19. data/lib/distil/product.rb +90 -76
  20. data/lib/distil/project.rb +370 -104
  21. data/lib/distil/recursive-http-fetcher.rb +72 -0
  22. data/lib/distil/server.rb +43 -0
  23. data/lib/distil/source-file/css-file.rb +56 -3
  24. data/lib/distil/source-file/html-file.rb +5 -6
  25. data/lib/distil/source-file/javascript-file.rb +96 -8
  26. data/lib/distil/source-file/json-file.rb +2 -4
  27. data/lib/distil/source-file/yui-minifiable-file.rb +19 -0
  28. data/lib/distil/source-file.rb +50 -92
  29. data/lib/distil/subclass-tracker.rb +13 -0
  30. data/lib/distil.rb +21 -37
  31. metadata +40 -39
  32. data/assets/mime.types +0 -1240
  33. data/lib/distil/configurable/file-set.rb +0 -85
  34. data/lib/distil/configurable/interpolated.rb +0 -36
  35. data/lib/distil/configurable/output-path.rb +0 -25
  36. data/lib/distil/configurable/project-path.rb +0 -25
  37. data/lib/distil/product/concatenated.rb +0 -83
  38. data/lib/distil/product/debug.rb +0 -32
  39. data/lib/distil/product/javascript-base-product.rb +0 -35
  40. data/lib/distil/product/javascript-doc-product.rb +0 -61
  41. data/lib/distil/product/minified.rb +0 -41
  42. data/lib/distil/product/page-product.rb +0 -27
  43. data/lib/distil/product/pdoc-product.rb +0 -42
  44. data/lib/distil/project/distil-project.rb +0 -157
  45. data/lib/distil/project/external-project.rb +0 -58
  46. data/lib/distil/project/remote-project.rb +0 -43
  47. data/lib/distil/target.rb +0 -251
  48. data/lib/distil/task/css-dependency-task.rb +0 -64
  49. data/lib/distil/task/jsl-dependency-task.rb +0 -50
  50. data/lib/distil/task/nib-task.rb +0 -72
  51. data/lib/distil/task.rb +0 -50
  52. data/lib/jsdoc.conf +0 -18
  53. data/lib/test/HtmlTestReporter.js +0 -127
  54. data/lib/test/Test.js +0 -248
  55. data/lib/test/TestReporter.js +0 -79
  56. data/lib/test/TestRunner.js +0 -132
  57. data/lib/test/browser.rb +0 -97
  58. data/lib/test/scriptwrapper.html +0 -10
  59. data/lib/test/unittest.html +0 -127
@@ -1,108 +1,122 @@
1
1
  module Distil
2
2
 
3
- class Product < Configurable
4
- option :concatenated_name, OutputPath, "$(name)-uncompressed.$(extension)", :aliases=>['concatenated']
5
- option :debug_name, OutputPath, "$(name)-debug.$(extension)", :aliases=>['debug']
6
- option :minified_name, OutputPath, "$(name).$(extension)", :aliases=>['minified']
7
- option :compressed_name, OutputPath, "$(name).$(extension).gz", :aliases=>['compressed']
8
-
9
- option :force, false
10
-
11
- include ErrorReporter
12
-
13
- attr_accessor :assets, :target, :join_string
14
- class_attr :extension
3
+ RELEASE_VARIANT= :release
4
+ DEBUG_VARIANT= :debug
5
+
6
+ class Product
7
+ class_attr :content_type
8
+ class_attr :variants
15
9
 
16
- def initialize(settings, target)
17
- @target= target
10
+ attr_reader :project, :files, :language, :variant, :assets, :libraries
11
+
12
+ def initialize(project, language, variant=nil)
13
+ @project= project
14
+ @language= language ? language.to_s : language
18
15
  @files= []
16
+ @libraries= []
19
17
  @assets= Set.new
20
- super(settings, target)
18
+ @variant= variant
21
19
  end
22
20
 
23
- def can_embed_file?(file)
24
- false
25
- end
26
-
27
- def handles_file?(file)
28
- [extension].include?(file.extension)
21
+ def notice_comment
22
+ return @notice_comment if @notice_comment
23
+ notice_text= project.notice_text
24
+ return @notice_command= "" if !notice_text || notice_text.empty?
25
+
26
+ @notice_comment= "/*!\n "
27
+ @notice_comment<< project.notice_text.split("\n").join("\n ")
28
+ @notice_comment<< "\n */\n"
29
29
  end
30
30
 
31
- def files
32
- @files
31
+ def filename
32
+ filename= "#{project.name}"
33
+ filename << "-#{language}" if language
34
+ filename << "-#{variant}" if variants.length>1
35
+ filename << ".#{content_type}"
33
36
  end
34
37
 
35
- def external_files
36
- []
38
+ def output_path
39
+ @output_path ||= File.join(project.output_path, filename)
37
40
  end
38
41
 
39
- def files=(fileset)
40
- fileset.each { |f|
41
- next if !handles_file?(f)
42
- @files << f
43
- @assets.merge(f.assets)
44
- }
42
+ def handles_file?(file)
43
+ # puts "#{self.class}#handles_file: #{file} file-lang=#{file.language} prod-lang=#{language} equal=#{file.language==language}"
44
+ return (file.extension==content_type) &&
45
+ (language.nil? || file.language.nil? || file.language==language)
45
46
  end
46
-
47
- def up_to_date
48
- return @up_to_date if !@up_to_date.nil?
49
- return false if force
50
-
51
- return @up_to_date=false if !File.exists?(filename)
47
+
48
+ def include_file(file)
49
+ if file.is_a?(Library)
50
+ return true if @libraries.include?(file)
51
+ @libraries << file
52
+ return true
53
+ end
52
54
 
53
- output_modified= File.stat(filename).mtime
54
- max_asset_modified= File.stat(target.project.project_file).mtime
55
+ return true if @files.include?(file)
55
56
 
56
- assets.each { |f|
57
- max_asset_modified= f.last_modified if f.last_modified > max_asset_modified
58
- }
57
+ if handles_file?(file)
58
+ @files << file
59
+ @assets.merge(file.assets) if file.assets
60
+ end
61
+ end
62
+
63
+ def up_to_date?
64
+ count= files.length
65
+ return true if 0==@files.length
66
+ return false unless File.exists?(output_path)
67
+ product_last_modified= File.stat(output_path).mtime
59
68
  files.each { |f|
60
- max_asset_modified= f.last_modified if f.last_modified > max_asset_modified
61
- }
62
-
63
- external_files.each { |f|
64
- next if !File.exist?(f)
65
- last_modified= File.stat(f).mtime
66
- max_asset_modified= last_modified if last_modified > max_asset_modified
69
+ return false if f.last_modified > product_last_modified
67
70
  }
71
+ true
72
+ end
68
73
 
69
- return @up_to_date=(output_modified > max_asset_modified)
74
+ def build
75
+ return if up_to_date?
76
+
77
+ FileUtils.mkdir_p(File.dirname(output_path))
78
+ self.send "build_#{variant}"
79
+ minimise
80
+ gzip
81
+ end
82
+
83
+ def clean
84
+ FileUtils.rm output_path if File.exists?(output_path)
85
+ return unless RELEASE_VARIANT==variant
86
+ FileUtils.rm minimised_filename if File.exists?(minimised_filename)
87
+ FileUtils.rm gzip_filename if File.exists?(gzip_filename)
70
88
  end
71
89
 
72
- def filename
73
- raise NotImplementedError.new("This product does not implement the filename method.")
90
+ def minimised_filename
91
+ @minimised_filename if @minimised_filename
92
+
93
+ minimised_filename= "#{project.name}"
94
+ minimised_filename << "-#{language}" if language
95
+ minimised_filename << ".#{content_type}"
96
+ @minimised_filename= File.join(project.output_path, minimised_filename)
74
97
  end
75
98
 
76
- def write_output
77
- raise NotImplementedError.new("No write_output method has been defined for this product.")
99
+ def minimise
100
+ return unless RELEASE_VARIANT==variant
101
+ system("java -jar #{COMPRESSOR} --type #{content_type} -o #{minimised_filename} #{output_path}")
78
102
  end
79
103
 
80
- def clean
81
- FileUtils.rm filename if File.exist? filename
104
+ def gzip_filename
105
+ @gzip_filename ||= "#{minimised_filename}.gz"
82
106
  end
83
107
 
84
- def relative_path(file)
85
- file=SourceFile.from_path(file) if file.is_a?(String)
86
-
87
- file_path= file.full_path
88
- output_folder= target.project.output_folder
89
- source_folder= target.project.source_folder
90
-
91
- path=file.relative_to_folder(source_folder) if 0==file_path.index(source_folder)
92
- path=file.relative_to_folder(output_folder) if 0==file_path.index(output_folder)
93
- path
108
+ def gzip
109
+ return unless RELEASE_VARIANT==variant
110
+ Zlib::GzipWriter.open(gzip_filename) do |gz|
111
+ gz.write File.read(minimised_filename)
112
+ end
94
113
  end
95
-
114
+
96
115
  end
97
116
 
98
117
  end
99
118
 
100
- require 'distil/product/concatenated'
101
- require 'distil/product/debug'
102
- require 'distil/product/minified'
103
- require 'distil/product/css-product'
104
- require 'distil/product/javascript-base-product'
105
- require 'distil/product/javascript-product'
106
- require 'distil/product/javascript-doc-product'
107
- require 'distil/product/pdoc-product'
108
- require 'distil/product/page-product'
119
+ # load all the other file types
120
+ Dir.glob("#{Distil::LIB_DIR}/distil/product/*.rb") { |file|
121
+ require file
122
+ }