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,14 +1,13 @@
1
1
  module Distil
2
-
2
+
3
3
  class HtmlFile < SourceFile
4
-
5
4
  extension "html"
6
5
  content_type "html"
7
6
 
8
- def minified_content(source)
7
+ def minified_content(source=content)
9
8
  source.gsub(/>\s+</, "><")
10
9
  end
11
-
12
10
  end
13
-
14
- end
11
+
12
+ end
13
+
@@ -1,17 +1,105 @@
1
1
  module Distil
2
+
3
+ JSL_IMPORT_REGEX= /\/\*jsl:import\s+([^\*]*)\*\//
4
+ NIB_ASSET_REGEX= /(NIB\.asset(?:Url)?)\(['"]([^)]+)['"]\)/
5
+ NIB_DECLARATION_REGEX= /NIB\(\s*(["'])(\w(?:\w|-)*)\1\s*,/
2
6
 
3
7
  class JavascriptFile < SourceFile
4
- extension 'js'
5
- content_type 'js'
8
+ include YuiMinifiableFile
9
+
10
+ extension "js"
11
+ content_type "js"
12
+
13
+ def check_nib
14
+ nib_name= basename(".js")
15
+
16
+ Dir.glob("#{dirname}/**/*") { |asset|
17
+ next if File.directory?(asset) || asset.to_s==full_path
18
+ asset= project.file_from_path(asset)
19
+
20
+ case
21
+ when 'js'==asset.content_type || 'css'==asset.content_type
22
+ add_dependency(asset)
23
+ when 'html'==asset.content_type
24
+ add_asset(asset)
25
+ project.add_alias_for_asset("#{nib_name}##{asset.basename}", asset)
26
+ else
27
+ add_asset(asset)
28
+ end
29
+ }
30
+ end
6
31
 
7
- def can_embed_as_content(file)
8
- [".css", ".html", ".json"].include?(file.extension)
32
+ def rewrite_content_relative_to_path(path)
33
+ text= content.gsub(JSL_IMPORT_REGEX, '')
34
+ text.gsub(NIB_ASSET_REGEX) do |match|
35
+ asset= project.file_from_path(File.join(dirname, $2))
36
+ if asset
37
+ "#{$1}(\"#{asset.relative_path}\")"
38
+ else
39
+ match
40
+ end
41
+ end
9
42
  end
43
+
44
+ def dependencies
45
+ @dependencies unless @dependencies.nil?
10
46
 
11
- def escape_embeded_content(content)
12
- content.gsub("\\", "\\\\").gsub("\n", "\\n").gsub("\"", "\\\"").gsub("'", "\\\\'")
13
- end
47
+ @dependencies= []
48
+ is_nib_file= (full_path =~ /([^\.\/]+)\.jsnib\/\1\.js$/)
49
+
50
+ content.each_with_index do |line, line_num|
51
+ line_num+=1
52
+
53
+ if is_nib_file && match=line.match(NIB_DECLARATION_REGEX)
54
+ unless match[2]==basename(".*")
55
+ error "NIB name must match match filename, otherwise NIB will be unloadable.", line_num
56
+ end
57
+ end
58
+
59
+ # handle dependencies
60
+ line.scan(JSL_IMPORT_REGEX) do |match|
61
+ import_file= File.join(dirname, $1)
62
+ if (File.exists?(import_file))
63
+ add_dependency project.file_from_path(import_file)
64
+ else
65
+ dependency= project.find_file($1, :js, :import)
66
+ if (dependency)
67
+ add_dependency project.file_from_path(dependency)
68
+ project.add_alias_for_file($1, dependency)
69
+ else
70
+ error "Missing import file: #{$1}", line_num
71
+ end
72
+ end
73
+ end
74
+
75
+ line.scan(NIB_ASSET_REGEX) do |match|
76
+ asset= project.file_from_path(File.join(dirname, $1))
77
+ if asset
78
+ add_asset(asset)
79
+ else
80
+ error "Missing asset file: #{$1}", line_num
81
+ end
82
+ end
83
+ end
14
84
 
85
+ if is_nib_file
86
+ # Handle special asset requirements for NIB files
87
+ check_nib
88
+ else
89
+ html= "#{basename(".js")}.html"
90
+ html_path= File.join(dirname, html)
91
+
92
+ # Add an alias for an HTML file with the same basename if it exists
93
+ if File.exists?(html_path)
94
+ asset= project.file_from_path(html_path)
95
+ add_asset(asset)
96
+ project.add_alias_for_asset(html, asset)
97
+ end
98
+ end
99
+
100
+ @dependencies
101
+ end
102
+
15
103
  end
16
-
104
+
17
105
  end
@@ -1,5 +1,3 @@
1
- require "distil/source-file/javascript-file"
2
-
3
1
  module Distil
4
2
 
5
3
  class JsonFile < JavascriptFile
@@ -7,10 +5,10 @@ module Distil
7
5
  extension 'json'
8
6
  content_type 'js'
9
7
 
10
- def minified_content(source)
8
+ def minified_content(source=content)
11
9
  super("(#{source})")[1..-3]
12
10
  end
13
11
 
14
12
  end
15
13
 
16
- end
14
+ end
@@ -0,0 +1,19 @@
1
+ module Distil
2
+ module YuiMinifiableFile
3
+
4
+ def minified_content(source=content)
5
+ # Run the Y!UI Compressor
6
+ return source if !content_type
7
+ buffer= ""
8
+
9
+ IO.popen("java -jar #{COMPRESSOR} --type #{content_type}", "r+") { |pipe|
10
+ pipe.puts(source)
11
+ pipe.close_write
12
+ buffer= pipe.read
13
+ }
14
+
15
+ buffer
16
+ end
17
+
18
+ end
19
+ end
@@ -3,24 +3,18 @@ require 'fileutils'
3
3
  module Distil
4
4
 
5
5
  class SourceFile
6
- attr_accessor :parent_folder, :full_path
6
+ attr_reader :full_path, :project
7
+ attr_accessor :language, :is_asset
8
+
7
9
  class_attr :extension
8
10
  class_attr :content_type
9
-
11
+
10
12
  include ErrorReporter
11
13
 
12
- def initialize(filepath)
14
+ def initialize(filepath, project)
13
15
  @full_path= File.expand_path(filepath)
14
-
15
- @parent_folder= File.dirname(@full_path)
16
- @dependencies= []
17
- @assets= []
18
-
19
- @@file_cache[@full_path]= self
20
- end
21
-
22
- def can_embed_as_content(file)
23
- false
16
+ @project= project
17
+ project.cache_file(self)
24
18
  end
25
19
 
26
20
  def warning(message, line=nil)
@@ -31,32 +25,25 @@ module Distil
31
25
  super(message, self, line)
32
26
  end
33
27
 
34
- @@file_types= []
35
- def self.inherited(subclass)
36
- @@file_types << subclass
37
- end
38
-
39
- def self.file_types
40
- @@file_types
28
+ def output_path
29
+ # SourceFiles get copied (or symlinked) into the output folder so that
30
+ # their path is the same as that relative to the source folder
31
+ @output_path||= File.join(project.output_path, relative_path)
41
32
  end
42
-
43
- @@file_cache= Hash.new
44
- def self.from_path(filepath)
45
- full_path= File.expand_path(filepath)
46
- file= @@file_cache[full_path]
47
- return file if file
48
-
49
- extension= File.extname(filepath)[1..-1]
50
33
 
51
- @@file_types.each { |handler|
52
- next if (handler.extension != extension)
53
-
54
- return handler.new(filepath)
55
- }
34
+ def relative_path
35
+ return @relative_path if @relative_path
36
+ if full_path.starts_with?(project.output_path)
37
+ @relative_path= Project.path_relative_to_folder(full_path, project.output_path)
38
+ else
39
+ @relative_path=Project.path_relative_to_folder(full_path, project.source_folder)
40
+ end
41
+ end
56
42
 
57
- return SourceFile.new(filepath)
43
+ def path_relative_to(path)
44
+ Project.path_relative_to_folder(full_path, path)
58
45
  end
59
-
46
+
60
47
  def to_s
61
48
  @full_path
62
49
  end
@@ -65,76 +52,44 @@ module Distil
65
52
  @full_path
66
53
  end
67
54
 
68
- def basename(suffix=extension)
69
- File.basename(@full_path, suffix)
55
+ def dirname
56
+ File.dirname(@full_path)
70
57
  end
71
-
72
- def file_path
73
- @file_path
58
+
59
+ def basename(suffix="")
60
+ File.basename(@full_path, suffix)
74
61
  end
75
62
 
76
- def file_path=(path)
77
- @file_path=path
78
- end
79
-
80
- def load_content
81
- File.read(@full_path)
63
+ def extension
64
+ @extension || self.class.extension || File.extname(full_path)[1..-1]
82
65
  end
83
66
 
84
- def escape_embeded_content(content)
85
- content
67
+ def content_type
68
+ @content_type || self.class.content_type || File.extname(full_path)[1..-1]
86
69
  end
87
-
70
+
88
71
  def content
89
- @content ||= load_content
72
+ @content ||= File.read(full_path)
90
73
  end
91
74
 
75
+ def rewrite_content_relative_to_path(path)
76
+ content
77
+ end
78
+
92
79
  def last_modified
93
80
  @last_modified ||= File.stat(@full_path).mtime
94
81
  end
95
82
 
96
- def minified_content(source)
97
- # Run the Y!UI Compressor
98
- return source if !content_type
99
- buffer= ""
100
-
101
- IO.popen("java -jar #{COMPRESSOR} --type #{content_type}", "r+") { |pipe|
102
- pipe.puts(source)
103
- pipe.close_write
104
- buffer= pipe.read
105
- }
106
-
107
- buffer
83
+ def minified_content(source=content)
84
+ return source
108
85
  end
109
86
 
110
- def self.path_relative_to_folder(path, folder)
111
- outputFolder= File.expand_path(folder).to_s
112
-
113
- # Remove leading slash and split into parts
114
- file_parts= path.slice(1..-1).split('/');
115
- output_parts= outputFolder.slice(1..-1).split('/');
116
-
117
- common_prefix_length= 0
118
-
119
- file_parts.each_index { |i|
120
- common_prefix_length= i
121
- break if file_parts[i]!=output_parts[i]
122
- }
123
-
124
- return '../'*(output_parts.length-common_prefix_length) + file_parts[common_prefix_length..-1].join('/')
125
- end
126
-
127
- def relative_to_folder(output_folder)
128
- self.class.path_relative_to_folder(@full_path, output_folder)
87
+ def path_relative_to_folder(folder)
88
+ Project.path_relative_to_folder(@full_path, folder)
129
89
  end
130
90
 
131
- def relative_to_file(source_file)
132
- folder= File.dirname(File.expand_path(source_file))
133
- self.relative_to_folder(folder)
134
- end
135
-
136
91
  def dependencies
137
- @dependencies
92
+ @dependencies||=[]
138
93
  end
139
94
 
140
95
  def add_dependency(file)
@@ -143,11 +98,12 @@ module Distil
143
98
  end
144
99
 
145
100
  def assets
146
- @assets
101
+ @assets||=Set.new
147
102
  end
148
103
 
149
104
  def add_asset(file)
150
- @assets << file
105
+ file.is_asset=true
106
+ assets << file
151
107
  end
152
108
 
153
109
  def copy_to(folder, prefix)
@@ -163,6 +119,8 @@ module Distil
163
119
  end
164
120
 
165
121
  # load all the other file types
166
- Dir.glob("#{Distil::LIB_DIR}/distil/source-file/*-file.rb") { |file|
167
- require file
168
- }
122
+ require 'distil/source-file/yui-minifiable-file'
123
+ require 'distil/source-file/css-file'
124
+ require 'distil/source-file/html-file'
125
+ require 'distil/source-file/javascript-file'
126
+ require 'distil/source-file/json-file'
@@ -0,0 +1,13 @@
1
+ class Class
2
+ def inherited(subclass)
3
+ if superclass.respond_to? :inherited
4
+ superclass.inherited(subclass)
5
+ end
6
+ @subclasses ||= []
7
+ @subclasses << subclass
8
+ end
9
+
10
+ def subclasses
11
+ @subclasses||[]
12
+ end
13
+ end
data/lib/distil.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "rubygems"
1
2
  require "set"
2
3
  require 'yaml'
3
4
  require 'tempfile'
@@ -5,7 +6,17 @@ require 'fileutils'
5
6
  require 'zlib'
6
7
  require "open3"
7
8
  require 'uri'
9
+ require 'erb'
8
10
  require 'open-uri'
11
+ require "json"
12
+
13
+ module Distil
14
+ class ValidationError < StandardError
15
+ end
16
+
17
+ COMPRESSOR= File.expand_path("#{VENDOR_DIR}/yuicompressor-2.4.2.jar")
18
+
19
+ end
9
20
 
10
21
  def class_attr(*rest)
11
22
  rest.each { |name|
@@ -30,10 +41,6 @@ def class_attr(*rest)
30
41
  }
31
42
  end
32
43
 
33
- def exist?(path, file)
34
- File.file?(File.join(path, file))
35
- end
36
-
37
44
  class String
38
45
  def as_identifier
39
46
  word= self.to_s.gsub(/(?:^|\W)(.)/) { $1.upcase }
@@ -45,40 +52,17 @@ class String
45
52
  end
46
53
  end
47
54
 
48
-
49
- # Do a simple token substitution. Tokens begin and end with @.
50
- def replace_tokens(string, params)
51
- return string.gsub(/(\n[\t ]*)?@([^@ \t\r\n]*)@/) { |m|
52
- key= $2
53
- ws= $1
54
- value= params[key]||m;
55
- if (ws && ws.length)
56
- ws + value.split("\n").join(ws);
57
- else
58
- value
59
- end
60
- }
61
- end
62
-
63
- module Distil
64
-
65
- FRAMEWORK_TYPE = "framework"
66
- APP_TYPE = "application"
67
-
68
- WEAK_LINKAGE = 'weak'
69
- STRONG_LINKAGE = 'strong'
70
- LAZY_LINKAGE = 'lazy'
71
-
72
- DEBUG_MODE = 'debug'
73
- RELEASE_MODE = 'release'
74
-
75
- end
76
-
77
- require 'distil/browser'
55
+ require 'distil/hash-additions'
56
+ require 'distil/javascript-code'
78
57
  require 'distil/error-reporter'
58
+ require 'distil/subclass-tracker'
79
59
  require 'distil/configurable'
80
60
  require 'distil/source-file'
81
- require 'distil/task'
61
+ require 'distil/file-vendor'
82
62
  require 'distil/product'
83
- require 'distil/target'
84
- require 'distil/project'
63
+ require 'distil/javascript-file-validator'
64
+ require 'distil/project'
65
+ require 'distil/recursive-http-fetcher'
66
+ require 'distil/library'
67
+ require 'distil/browser'
68
+ require 'distil/server'
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: distil
3
3
  version: !ruby/object:Gem::Version
4
- hash: 39
5
- prerelease: false
4
+ hash: 91
5
+ prerelease: true
6
6
  segments:
7
7
  - 0
8
- - 13
9
- - 6
10
- version: 0.13.6
8
+ - 14
9
+ - 0
10
+ - b
11
+ version: 0.14.0.b
11
12
  platform: ruby
12
13
  authors:
13
14
  - Jeff Watkins
@@ -15,7 +16,7 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-12-05 00:00:00 -08:00
19
+ date: 2010-12-21 00:00:00 -08:00
19
20
  default_executable: distil
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
@@ -66,6 +67,22 @@ dependencies:
66
67
  version: 1.4.8
67
68
  type: :runtime
68
69
  version_requirements: *id003
70
+ - !ruby/object:Gem::Dependency
71
+ name: directory_watcher
72
+ prerelease: false
73
+ requirement: &id004 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 17
79
+ segments:
80
+ - 1
81
+ - 1
82
+ - 1
83
+ version: 1.1.1
84
+ type: :runtime
85
+ version_requirements: *id004
69
86
  description: A build tool for Javascript and CSS that takes advantage of best-of-breed helper applications Javascript Lint and JSDoc Toolkit
70
87
  email:
71
88
  executables:
@@ -79,7 +96,6 @@ files:
79
96
  - Rakefile
80
97
  - VERSION
81
98
  - assets/distil.js
82
- - assets/mime.types
83
99
  - bin/distil
84
100
  - bin/distil-old
85
101
  - distil.gemspec
@@ -87,45 +103,28 @@ files:
87
103
  - lib/distil.rb
88
104
  - lib/distil/browser.rb
89
105
  - lib/distil/configurable.rb
90
- - lib/distil/configurable/file-set.rb
91
- - lib/distil/configurable/interpolated.rb
92
- - lib/distil/configurable/output-path.rb
93
- - lib/distil/configurable/project-path.rb
94
106
  - lib/distil/error-reporter.rb
107
+ - lib/distil/file-vendor.rb
108
+ - lib/distil/hash-additions.rb
109
+ - lib/distil/javascript-code.rb
110
+ - lib/distil/javascript-file-validator.rb
111
+ - lib/distil/library.rb
95
112
  - lib/distil/product.rb
96
- - lib/distil/product/concatenated.rb
113
+ - lib/distil/product/cache-manifest-product.rb
97
114
  - lib/distil/product/css-product.rb
98
- - lib/distil/product/debug.rb
99
- - lib/distil/product/javascript-base-product.rb
100
- - lib/distil/product/javascript-doc-product.rb
115
+ - lib/distil/product/html-product.rb
101
116
  - lib/distil/product/javascript-product.rb
102
- - lib/distil/product/minified.rb
103
- - lib/distil/product/page-product.rb
104
- - lib/distil/product/pdoc-product.rb
105
117
  - lib/distil/project.rb
106
- - lib/distil/project/distil-project.rb
107
- - lib/distil/project/external-project.rb
108
- - lib/distil/project/remote-project.rb
118
+ - lib/distil/recursive-http-fetcher.rb
119
+ - lib/distil/server.rb
109
120
  - lib/distil/source-file.rb
110
121
  - lib/distil/source-file/css-file.rb
111
122
  - lib/distil/source-file/html-file.rb
112
123
  - lib/distil/source-file/javascript-file.rb
113
124
  - lib/distil/source-file/json-file.rb
114
- - lib/distil/target.rb
115
- - lib/distil/task.rb
116
- - lib/distil/task/css-dependency-task.rb
117
- - lib/distil/task/jsl-dependency-task.rb
118
- - lib/distil/task/nib-task.rb
119
- - lib/distil/task/validate-js-task.rb
120
- - lib/jsdoc.conf
125
+ - lib/distil/source-file/yui-minifiable-file.rb
126
+ - lib/distil/subclass-tracker.rb
121
127
  - lib/jsl.conf
122
- - lib/test/HtmlTestReporter.js
123
- - lib/test/Test.js
124
- - lib/test/TestReporter.js
125
- - lib/test/TestRunner.js
126
- - lib/test/browser.rb
127
- - lib/test/scriptwrapper.html
128
- - lib/test/unittest.html
129
128
  - vendor/Makefile
130
129
  - vendor/extconf.rb
131
130
  - vendor/jsdoc-extras/plugins/distil-plugin.js
@@ -844,12 +843,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
844
843
  required_rubygems_version: !ruby/object:Gem::Requirement
845
844
  none: false
846
845
  requirements:
847
- - - ">="
846
+ - - ">"
848
847
  - !ruby/object:Gem::Version
849
- hash: 3
848
+ hash: 25
850
849
  segments:
851
- - 0
852
- version: "0"
850
+ - 1
851
+ - 3
852
+ - 1
853
+ version: 1.3.1
853
854
  requirements: []
854
855
 
855
856
  rubyforge_project: