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,168 +1,79 @@
1
- module Kernel
2
-
3
- def Boolean(string)
4
- return true if string == true || string =~ /^true$/i
5
- return false if string == false || string.nil? || string =~ /^false$/i
6
- raise ArgumentError.new("invalid value for Boolean: \"#{string}\"")
7
- end
8
-
9
- end
10
-
11
- class ValidationError < StandardError
12
- end
13
-
14
-
15
- class Configurable
16
- attr_reader :options
1
+ module Distil
17
2
 
18
- @@options= {}
19
-
20
- def get_option(name)
21
- return nil if !@options.respond_to?(name)
22
- value=@options[name]
23
- value.respond_to?(:value_of) ? value.value_of(self) : value
24
- end
25
-
26
- def get_options(settings=nil, parent=nil)
27
- keys= @@options.keys
28
- values= @@options.map { |k,v| convert_type(v[:type], v[:value]) }
3
+ class Configurable
29
4
 
30
- s= @options ? @options : (@options=Struct.new(*keys).new(*values))
31
- return s if !settings
32
-
33
- setting_keys= settings.keys.map { |key| key.to_s }
34
-
35
- @@options.each { |key, value|
36
-
37
- intersect= value[:aliases] & setting_keys
38
- next if !parent && intersect.empty?
39
-
40
- if (intersect.empty?)
41
- s[key]= parent[key]
42
- next
43
- end
44
-
45
- if (intersect.length>1)
46
- raise ArgumentError, "Multiple variants for #{key.to_s} defined: #{intersect.join(", ")}"
47
- end
48
-
49
- setting_key= intersect[0]
50
- setting_value= settings[setting_key]
51
- settings.delete(setting_key)
52
-
53
- # decide if any type conversions are needed...
54
- setting_value= convert_type(value[:type], setting_value)
55
-
56
- if (value.has_key?(:valid_values) && !value[:valid_values].include?(setting_value))
57
- raise ValidationError, "Invalid value for '#{setting_key}': #{setting_value}"
58
- end
59
-
60
- s[key]= setting_value
61
-
62
- }
63
-
64
- @extras.merge!(settings)
65
- s
66
- end
67
-
68
- # option name, [type], [default], [options]
69
- def self.option(name, *rest)
70
-
71
- name_string= name.to_s
72
-
73
- info= {
74
- :aliases=>[name_string, name_string.gsub('_', '-'), name_string.gsub('_', ' ')].uniq
75
- }
76
-
77
- arg= rest.shift
78
-
79
- if (arg.is_a?(Class) || arg==URI)
80
- info[:type]= arg
81
- info[:value]= nil
82
- arg= rest.shift
5
+ @@config_aliases={}
6
+ def self.alias_config_key(original, key_alias)
7
+ @@config_aliases[key_alias.to_s]= original.to_s
83
8
  end
84
-
85
- if (!arg.nil? && !arg.is_a?(Hash))
86
- info[:value]= arg
87
- info[:type]= arg.class if !info.has_key?(:type)
88
- arg= rest.shift
9
+
10
+ def key_for_alias(key_alias)
11
+ key_alias= key_alias.to_s.gsub("-", "_").gsub(" ", "_")
12
+ @@config_aliases[key_alias] || key_alias
89
13
  end
14
+
15
+ class ConfigDsl
90
16
 
91
- # handle named arguments
92
- if (arg.is_a?(Hash))
93
- if arg.has_key?(:aliases)
94
- info[:aliases].concat(arg[:aliases]).uniq!
95
- arg.delete(:aliases)
17
+ def initialize(hash)
18
+ @hash= hash
19
+ @used= Set.new
96
20
  end
97
- info.merge!(arg)
98
- end
99
21
 
100
- if @@options.has_key?(name)
101
- orig= @@options[name]
102
- if orig.has_key?(:type) && info.has_key?(:type) && info[:type]!=orig[:type]
103
- raise ArgumentError, "Redefinition of option #{self}##{name} changes type"
22
+ def with_each(key)
23
+ case when @hash.include?(key.to_sym)
24
+ value= @hash[key.to_sym]
25
+ when @hash.include?(key.to_s)
26
+ value= @hash[key.to_s]
27
+ else
28
+ return
29
+ end
30
+
31
+ value= value.split(",").map { |s| s.strip } if value.is_a?(String)
32
+ value.each { |v| yield v }
33
+ @used << key.to_s
104
34
  end
105
- if orig.has_key?(:value) && !info[:value].nil? && info[:value]!=orig[:value]
106
- raise ArgumentError, "Redefinition of option #{name} changes value"
35
+
36
+ def with(key)
37
+ case when @hash.include?(key.to_sym)
38
+ yield @hash[key.to_sym]
39
+ when @hash.include?(key.to_s)
40
+ yield @hash[key.to_s]
41
+ else
42
+ return
43
+ end
44
+ @used << key.to_s
107
45
  end
108
- orig[:type]||=info[:type]
109
- orig[:value]||=info[:value]
110
- orig[:aliases].concat(info[:aliases]).uniq!
111
- else
112
- @@options[name]= info
113
- end
114
-
115
- self.send :define_method, name do
116
- value=@options[name]
117
- value.respond_to?(:value_of) ? value.value_of(self) : value
46
+
47
+ def used?(key)
48
+ @used.include?(key.to_s)
49
+ end
50
+
118
51
  end
119
52
 
120
- self.send :define_method, "#{name}=" do |value|
121
- @options[name]= convert_type(@@options[name][:type], value)
53
+ def configure_with(hash)
54
+ new_hash= {}
55
+ hash.each { |key, value|
56
+ new_hash[key_for_alias(key)]= value
57
+ }
58
+
59
+ dsl= ConfigDsl.new(new_hash)
60
+ yield dsl if block_given?
61
+
62
+ new_hash.each { |key, value|
63
+ next if dsl.used?(key.to_s)
64
+
65
+ key= key_for_alias(key)
66
+ case
67
+ when self.respond_to?("#{key}=")
68
+ self.send "#{key}=", value
69
+ when self.respond_to?(key) && 0!=self.method(key).arity
70
+ self.send key, value
71
+ else
72
+ self.instance_variable_set("@#{key}", value)
73
+ end
74
+ }
122
75
  end
123
76
 
124
- # self.send :protected, "#{name}=".to_s
125
-
126
- end
127
-
128
- def initialize(options={}, parent=nil)
129
- @extras= Hash.new
130
- if (parent.is_a?(Configurable))
131
- parent_options= parent.options
132
- end
133
- get_options(options, parent_options)
134
77
  end
135
78
 
136
- private
137
-
138
- def convert_type(type, value)
139
- case
140
- when FalseClass==type || TrueClass==type
141
- Boolean(value)
142
- when Array==type
143
- value.is_a?(String) ? value.split(/\s*,\s*/) : value
144
- when Fixnum==type
145
- value.to_i
146
- when nil==type || NilClass==type
147
- value
148
- when String==type
149
- value ? value.to_s : nil;
150
- when value.nil?
151
- value
152
- when URI==type
153
- URI.parse(value)
154
- else
155
- if type.respond_to?(:from_options)
156
- type.from_options(value, self)
157
- else
158
- puts "type=#{type} value=#{value}"
159
- type.new(value)
160
- end
161
- end
162
- end
163
-
164
- end
165
-
166
- Dir.glob("#{File.dirname(__FILE__)}/configurable/*.rb") { |file|
167
- require file
168
- }
79
+ end
@@ -23,42 +23,44 @@ module Distil
23
23
  @@total_warning_count
24
24
  end
25
25
 
26
+ def has_errors?
27
+ @@error_count > 0
28
+ end
29
+
30
+ def has_warnings?
31
+ @@warning_count > 0
32
+ end
33
+
26
34
  def self.error(message, file=nil, line_number=nil)
27
35
  @@error_count+=1
28
- if (file && line_number)
29
- printf("%s:%d: error: %s\n", file, line_number, message)
36
+
37
+ case when file && line_number
38
+ puts "#{file}:#{line_number}: error: #{message}"
39
+ when file
40
+ puts "#{file}: error: #{message}"
30
41
  else
31
- printf("error: %s\n", message)
42
+ puts "error: #{message}"
32
43
  end
33
44
  end
34
45
 
35
46
  def error(message, file=nil, line_number=nil)
36
- @@error_count+=1
37
- if (file && line_number)
38
- printf("%s:%d: error: %s\n", file, line_number, message)
39
- else
40
- printf("error: %s\n", message)
41
- end
47
+ ErrorReporter.error(message, file, line_number)
42
48
  end
43
49
 
44
50
  def self.warning(message, file=nil, line_number=nil)
45
51
  @@warning_count+=1
46
- return if (ignore_warnings)
47
- if (file && line_number)
48
- printf("%s:%d: warning: %s\n", file, line_number, message)
52
+ return if (@@ignore_warnings)
53
+ case when file && line_number
54
+ puts "#{file}:#{line_number}: warning: #{message}"
55
+ when file
56
+ puts "#{file}: warning: #{message}"
49
57
  else
50
- printf("warning: %s\n", message)
58
+ puts "warning: #{message}"
51
59
  end
52
60
  end
53
61
 
54
62
  def warning(message, file=nil, line_number=nil)
55
- @@warning_count+=1
56
- return if (ignore_warnings)
57
- if (file && line_number)
58
- printf("%s:%d: warning: %s\n", file, line_number, message)
59
- else
60
- printf("warning: %s\n", message)
61
- end
63
+ ErrorReporter.warning(message, file, line_number)
62
64
  end
63
65
 
64
66
  def report
@@ -0,0 +1,29 @@
1
+ module Distil
2
+
3
+ module FileVendor
4
+
5
+ def cache_file(file)
6
+ @file_cache={} if @file_cache.nil?
7
+ @file_cache[file.full_path]= file
8
+ end
9
+
10
+ def file_from_path(filepath)
11
+ return if !filepath
12
+ @file_cache={} if @file_cache.nil?
13
+ full_path= File.expand_path(filepath)
14
+ file= @file_cache[full_path]
15
+ return file if file
16
+
17
+ extension= File.extname(filepath)[1..-1]
18
+
19
+ SourceFile.subclasses.each { |handler|
20
+ next if (handler.extension != extension)
21
+ return handler.new(filepath, self)
22
+ }
23
+
24
+ return SourceFile.new(filepath, self)
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,45 @@
1
+ # Hash#deep_merge
2
+ # From: http://pastie.textmate.org/pastes/30372, Elliott Hird
3
+ # Source: http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
4
+ # This file contains extensions to Ruby and other useful snippits of code.
5
+ # Time to extend Hash with some recursive merging magic.
6
+
7
+ class Hash
8
+
9
+ # Merges self with another hash, recursively.
10
+ #
11
+ # This code was lovingly stolen from some random gem:
12
+ # http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
13
+ #
14
+ # Thanks to whoever made it.
15
+
16
+ def deep_merge(hash)
17
+ target = dup
18
+
19
+ hash.keys.each do |key|
20
+ if hash[key].is_a? Hash and self[key].is_a? Hash
21
+ target[key] = target[key].deep_merge(hash[key])
22
+ next
23
+ end
24
+
25
+ target[key] = hash[key]
26
+ end
27
+
28
+ target
29
+ end
30
+
31
+
32
+ # From: http://www.gemtacular.com/gemdocs/cerberus-0.2.2/doc/classes/Hash.html
33
+ # File lib/cerberus/utils.rb, line 42
34
+
35
+ def deep_merge!(second)
36
+ second.each_pair do |k,v|
37
+ if self[k].is_a?(Hash) and second[k].is_a?(Hash)
38
+ self[k].deep_merge!(second[k])
39
+ else
40
+ self[k] = second[k]
41
+ end
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,12 @@
1
+ class JavascriptCode < String
2
+ def to_json(*options)
3
+ self
4
+ end
5
+ end
6
+
7
+ module Kernel
8
+ # A convenience factory method
9
+ def JavascriptCode(str)
10
+ JavascriptCode.new(str)
11
+ end
12
+ end
@@ -1,33 +1,25 @@
1
1
  module Distil
2
2
 
3
+ JSL_CONF= "#{LIB_DIR}/jsl.conf"
3
4
  LINT_COMMAND= "#{VENDOR_DIR}/jsl-0.3.0/bin/jsl"
4
- # LINT_COMMAND= "/Users/jeff/.gem/ruby/1.8/gems/distil-0.10.2/vendor/jsl-0.3.0/bin/jsl"
5
-
5
+ # LINT_COMMAND= "/Users/jeff/.gem/ruby/1.8/gems/distil-0.13.6/vendor/jsl-0.3.0/bin/jsl"
6
6
  JS_GLOBALS= Set.new ['Array', 'Boolean', 'Date', 'Error', 'EvalError',
7
7
  'Function', 'Math', 'Number', 'Object', 'RangeError',
8
8
  'ReferenceError', 'RegExp', 'String', 'SyntaxError',
9
9
  'TypeError', 'URIError']
10
-
11
- class ValidateJsTask < Task
10
+
11
+ module JavascriptFileValidator
12
12
 
13
13
  include ErrorReporter
14
14
 
15
- option :jsl_conf, "#{LIB_DIR}/jsl.conf"
16
- option :global_export
17
- option :additional_globals
18
-
19
- def handles_file(file)
20
- return ["js"].include?(file.content_type)
21
- end
22
-
23
- def process_files(files)
15
+ def validate_javascript_files
24
16
  return if (!File.exists?(LINT_COMMAND))
25
17
 
26
18
  tmp= Tempfile.new("jsl.conf")
27
19
 
28
20
  conf_files= [ "jsl.conf",
29
21
  "#{ENV['HOME']}/.jsl.conf",
30
- jsl_conf
22
+ JSL_CONF
31
23
  ]
32
24
 
33
25
  jsl_conf= conf_files.find { |f| File.exists?(f) }
@@ -46,19 +38,24 @@ module Distil
46
38
  tmp << "+define #{g}\n"
47
39
  }
48
40
 
49
- target.file_aliases.each { |original, full_path|
50
- next if !File.exist?(full_path)
51
- tmp << "+alias #{original} #{full_path}\n"
41
+ libraries.each { |l|
42
+ tmp.puts "+alias #{l.name} #{l.file_for(:js, nil, DEBUG_VARIANT)}"
52
43
  }
53
44
 
54
- files.each { |f|
55
- next if !handles_file(f)
56
- tmp << "+process #{f}\n"
45
+ dependency_aliases.each { |name, file|
46
+ tmp.puts "+alias #{name} #{file}"
47
+ }
48
+
49
+ source_files.each { |f|
50
+ tmp.puts "+process #{f}" if f.content_type=="js"
57
51
  }
58
52
 
59
53
  tmp.close()
60
54
  command= "#{LINT_COMMAND} -nologo -nofilelisting -conf #{tmp.path}"
61
55
 
56
+ # puts "\n\n\n\n#{name}\n\n"
57
+ # puts "jsl conf:\n#{File.read(tmp.path)}\n\n"
58
+
62
59
  stdin, stdout, stderr= Open3.popen3(command)
63
60
  stdin.close
64
61
  output= stdout.read
@@ -81,8 +78,7 @@ module Distil
81
78
  puts
82
79
  end
83
80
 
84
- end
85
-
81
+ end
86
82
  end
87
83
 
88
- end
84
+ end