coyote 0.7.0 → 1.0.0.beta1

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 (53) hide show
  1. data/Manifest +13 -31
  2. data/README.md +1 -91
  3. data/Rakefile +8 -4
  4. data/bin/coyote +9 -32
  5. data/coyote.gemspec +4 -10
  6. data/lib/coyote.rb +28 -62
  7. data/lib/coyote/asset.rb +51 -0
  8. data/lib/coyote/assets/coffeescript.rb +29 -0
  9. data/lib/coyote/assets/javascript.rb +4 -0
  10. data/lib/coyote/bundle.rb +101 -0
  11. data/lib/coyote/closure_compiler.rb +9 -9
  12. data/lib/coyote/configuration.rb +23 -77
  13. data/lib/coyote/notifications.rb +22 -0
  14. data/test/scripts/input1.js +1 -0
  15. data/test/scripts/input2.js +1 -0
  16. data/test/scripts/input3.js +1 -0
  17. data/test/scripts/input4.js +1 -0
  18. data/test/scripts/lib/input5.coffee +3 -0
  19. data/test/scripts/lib/input6.js +1 -0
  20. data/test/scripts/lib/keystone/input7.js +2 -0
  21. data/test/scripts/vendor/input8.coffee +1 -0
  22. metadata +29 -70
  23. data/config/coyote-icon.png +0 -0
  24. data/config/coyote-usage.txt +0 -16
  25. data/config/coyote.yaml +0 -2
  26. data/lib/coyote/generator.rb +0 -49
  27. data/lib/coyote/notification.rb +0 -62
  28. data/lib/coyote/script.rb +0 -124
  29. data/lib/coyote/scripts/coffeescript.rb +0 -32
  30. data/lib/coyote/scripts/combine.rb +0 -54
  31. data/lib/coyote/scripts/javascript.rb +0 -4
  32. data/test/src/public/assets/javascripts/app/application/interface.coffee +0 -10
  33. data/test/src/public/assets/javascripts/app/application/main.coffee +0 -14
  34. data/test/src/public/assets/javascripts/app/application/pages/home.coffee +0 -9
  35. data/test/src/public/assets/javascripts/app/boot.coffee +0 -1
  36. data/test/src/public/assets/javascripts/lib/extensions.coffee +0 -8
  37. data/test/src/public/assets/javascripts/lib/imulus.coffee +0 -7
  38. data/test/src/public/assets/javascripts/lib/imulus/forms.coffee +0 -46
  39. data/test/src/public/assets/javascripts/lib/imulus/maps/infowindow.coffee +0 -37
  40. data/test/src/public/assets/javascripts/lib/imulus/maps/map.coffee +0 -51
  41. data/test/src/public/assets/javascripts/lib/imulus/maps/marker.coffee +0 -66
  42. data/test/src/public/assets/javascripts/lib/imulus/maps/point.coffee +0 -5
  43. data/test/src/public/assets/javascripts/lib/imulus/maps/results.coffee +0 -117
  44. data/test/src/public/assets/javascripts/lib/imulus/tables.coffee +0 -11
  45. data/test/src/public/assets/javascripts/lib/imulus/triggers.coffee +0 -26
  46. data/test/src/public/assets/javascripts/scripts.coffee +0 -14
  47. data/test/src/public/assets/javascripts/vendor/jquery.js +0 -18
  48. data/test/src/public/assets/javascripts/vendor/jquery/jquery.cookie.js +0 -89
  49. data/test/src/public/assets/javascripts/vendor/jquery/jquery.cycle.js +0 -21
  50. data/test/src/public/assets/javascripts/vendor/jquery/jquery.query.js +0 -224
  51. data/test/src/public/assets/javascripts/vendor/swfobject.js +0 -4
  52. data/test/src/public/scripts/scripts.combine +0 -18
  53. data/test/src/public/scripts/scripts.js +0 -944
@@ -0,0 +1,29 @@
1
+ module Coyote
2
+ class CoffeeScript < Asset
3
+
4
+
5
+ def update!
6
+ super
7
+ compile!
8
+ end
9
+
10
+
11
+ protected
12
+
13
+ # Defines the regex pattern for scanning the contents of the
14
+ # file to look for require directives
15
+ def require_pattern
16
+ Regexp.new(/#=\s*require\s(.*)$/i) # '#= require a/b/c.coffee' => 'a/b/c.coffee'
17
+ end
18
+
19
+
20
+ private
21
+
22
+ def compile!
23
+ @contents = `cat #{@absolute_path} | coffee -sc`
24
+ end
25
+
26
+
27
+
28
+ end
29
+ end
@@ -0,0 +1,4 @@
1
+ module Coyote
2
+ class JavaScript < Asset
3
+ end
4
+ end
@@ -0,0 +1,101 @@
1
+ require 'coyote/closure_compiler'
2
+
3
+ module Coyote
4
+ autoload :Asset, 'coyote/asset'
5
+
6
+ class Bundle
7
+
8
+ attr_reader :contents
9
+
10
+ def initialize(entry_point, output_path)
11
+ @output_path = output_path
12
+ @assets = {}
13
+ @contents = ""
14
+ add entry_point
15
+ update!
16
+ end
17
+
18
+
19
+ def files(absolute = false)
20
+ @assets.collect do |path, asset|
21
+ absolute ? asset.absolute_path : asset.relative_path
22
+ end.reverse
23
+ end
24
+
25
+
26
+ def add(path)
27
+ if File.directory? path
28
+ add_directory path
29
+ elsif File.exists? path
30
+ add_asset path
31
+ else
32
+ notify "Could not find #{path}", :failure
33
+ end
34
+ end
35
+
36
+
37
+ def update!(changed_files = [])
38
+ @contents = ""
39
+
40
+ unless changed_files.empty?
41
+ changed_files.each do |path|
42
+ @assets["#{Dir.pwd}/#{path}"].update!
43
+ end
44
+ end
45
+
46
+ files(true).each { |path| @contents += "#{@assets[path].contents} \n\n" }
47
+ end
48
+
49
+
50
+ def compress!
51
+ notify "#{Time.new.strftime("%I:%M:%S")} Compressing bundle...", :warning
52
+ compiler = ClosureCompiler.new.compile(@contents)
53
+ if compiler.success?
54
+ @contents = compiler.compiled_code
55
+ elsif compiler.file_too_big?
56
+ notify "Input code too big for API, creating uncompressed file\n", :failure
57
+ elsif compiler.errors
58
+ notify "Google closure API failed to compile, creating uncompressed file\n", :failure
59
+ notify "Errors:", :failure
60
+ notify "#{compiler.errors.to_s}", :failure
61
+ end
62
+ end
63
+
64
+ def save
65
+ output = File.open @output_path, 'w+'
66
+ output.write @contents
67
+ output.close
68
+ end
69
+
70
+ def manifest
71
+ files.inject("") { |result, file| result + "\n + #{file}" }
72
+ end
73
+
74
+ private
75
+
76
+ def add_asset(path)
77
+ asset = Asset.select_and_init(path)
78
+
79
+ unless @assets[asset.absolute_path].nil?
80
+ @assets.delete(asset.absolute_path)
81
+ end
82
+
83
+ @assets[asset.absolute_path] = asset
84
+ add_dependencies(asset)
85
+ end
86
+
87
+
88
+ def add_directory(dir_path)
89
+ Dir.foreach(dir_path) do |path|
90
+ next if path == '.' or path == '..'
91
+ add "#{dir_path}/#{path}"
92
+ end
93
+ end
94
+
95
+
96
+ def add_dependencies(asset)
97
+ asset.dependencies.each { |path| add path }
98
+ end
99
+
100
+ end
101
+ end
@@ -1,12 +1,13 @@
1
1
  require 'net/http'
2
+ require 'rexml/document'
2
3
 
3
4
  module Coyote
4
5
  class ClosureCompiler
5
-
6
+
6
7
  def initialize
7
8
  @request = Net::HTTP::Post.new('/compile', 'Content-type' => 'application/x-www-form-urlencoded')
8
9
  end
9
-
10
+
10
11
  def compile(content)
11
12
  @content = content
12
13
  params = {
@@ -21,22 +22,21 @@ module Coyote
21
22
  res = Net::HTTP.new('closure-compiler.appspot.com', 80).start {|http| http.request(@request) }
22
23
  case res
23
24
  when Net::HTTPSuccess
24
- #puts res.body
25
25
  @doc = REXML::Document.new(res.body)
26
26
  end
27
- rescue REXML::ParseException => msg
27
+ rescue REXML::ParseException => msg
28
28
  print "Failed: #{msg}\n".red
29
29
  rescue
30
30
  #these should be caught by external checking
31
31
  end
32
-
32
+
33
33
  self
34
34
  end
35
-
35
+
36
36
  def success?
37
37
  @doc && @doc.root && @doc.root.elements['serverErrors'].nil?
38
38
  end
39
-
39
+
40
40
  def errors
41
41
  unless @doc
42
42
  nil
@@ -44,11 +44,11 @@ module Coyote
44
44
  @doc.root.elements["serverErrors"]
45
45
  end
46
46
  end
47
-
47
+
48
48
  def compiled_code
49
49
  @doc.root.elements['compiledCode'].text
50
50
  end
51
-
51
+
52
52
  def file_too_big?
53
53
  @doc && @doc.root && @doc.root.elements["serverErrors/error[@code='8']"] != nil
54
54
  end
@@ -1,85 +1,31 @@
1
1
  module Coyote
2
2
  class Configuration
3
+ attr_accessor :input, :output, :options
3
4
 
4
- attr_accessor :options, :output, :source
5
- attr_reader :inputs
6
-
7
- def initialize(options = {})
8
- @options = options
9
- @inputs = {}
10
- @output = Coyote::Defaults::OUTPUT
11
- end
12
-
13
-
14
- def should_compress?
15
- @options['compress'] || false
16
- end
17
-
18
-
19
- def inputs=(inputs)
20
- add_input inputs
21
- end
22
-
23
-
24
- def add_input(input)
25
- if input.class == Array
26
- input.each do |input|
27
- find_and_add_files input
28
- end
29
- elsif input.class == String and @output != input
30
- find_and_add_files input
31
- end
32
- end
33
-
34
-
35
- def load_from_yaml!(yaml_file = Coyote::CONFIG_FILENAME)
36
- if File.exists?(yaml_file)
37
- begin
38
- config = YAML.load(File.open(yaml_file))
39
- if config.class == Hash && ! config.empty?
40
- self.inputs = config['input']
41
- @output = config['output']
42
- if config['options'] && config['options'].class == Hash
43
- @options = config['options'].merge(@options)
44
- end
45
- @source = yaml_file
46
- else
47
- Coyote::Notification.new "Coyote configuration exists but has not been defined yet. Configure it in #{yaml_file}\n", "failure"
48
- exit(0)
49
- end
50
- rescue ArgumentError => e
51
- Coyote::Notification.new "Could not parse YAML: #{e.message}\n", "failure"
52
- exit
53
- end
54
- else
55
- Coyote::Notification.new "Could not find a Coyote configuration file #{yaml_file}. Use 'coyote new' to create one.\n", "failure"
56
- exit
57
- end
58
- end
59
-
60
-
61
-
62
- private
63
-
64
- def find_and_add_files(path)
65
- Dir.glob(path).each do |file|
66
- # Grab the absolute path of the file
67
- # so we can ensure we don't have duplicate inputs
68
- filename = File.absolute_path(file)
69
-
70
- script = Coyote::Script.select_and_init(filename)
71
- script.requires.each { |path| find_and_add_files(path) }
72
-
73
- # Check to see if the file already exists in the inputs hash
74
- # If not, add it with the full file path as the key
75
- if @inputs[filename].nil?
76
- @inputs[filename] = script
77
- end
78
- end
79
- end
80
-
5
+ def initialize
6
+ @input = ""; @output = ""; @options = {}
7
+ end
8
+ end
9
+ end
81
10
 
82
11
 
12
+ def coyote(method, &block)
13
+ config = Coyote::Configuration.new
14
+ yield config
15
+
16
+ if config.input.empty?
17
+ notify "Coyote: Input filepath must be defined", :failure
18
+ exit 0
19
+ end
83
20
 
21
+ if config.output.empty?
22
+ notify "Coyote: Output filepath must be defined", :failure
23
+ exit 0
24
+ end
25
+
26
+ if method == :watch
27
+ config.options[:watch] = true
84
28
  end
29
+
30
+ Coyote::run config.input, config.output, config.options
85
31
  end
@@ -0,0 +1,22 @@
1
+ require 'term/ansicolor'
2
+ include Term::ANSIColor
3
+
4
+ module Coyote
5
+ module Notifications
6
+
7
+ def self.notify(msg, type = "message")
8
+ notify msg, type
9
+ end
10
+
11
+ def notify(msg, type = :message)
12
+ msg = "#{msg}\n"
13
+ case type
14
+ when :success ; print msg.green
15
+ when :warning ; print msg.yellow
16
+ when :failure ; print msg.red
17
+ else ; print msg.white
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1 @@
1
+ console.log('Input1.js');
@@ -0,0 +1 @@
1
+ console.log('Input2.js');
@@ -0,0 +1 @@
1
+ console.log('Input3.js');
@@ -0,0 +1 @@
1
+ console.log('Input4.js');
@@ -0,0 +1,3 @@
1
+ #= require ../vendor/input8.coffee
2
+
3
+ console.log 'Input5.coffee'
@@ -0,0 +1 @@
1
+ console.log('Input6.js');
@@ -0,0 +1,2 @@
1
+ console.log('Input7.js');
2
+ console.log("Hello World");
@@ -0,0 +1 @@
1
+ console.log 'Input8.coffee'
metadata CHANGED
@@ -1,20 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coyote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
5
- prerelease:
4
+ version: 1.0.0.beta1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Imulus
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-18 00:00:00.000000000 -07:00
12
+ date: 2012-02-13 00:00:00.000000000 -07:00
13
13
  default_executable: coyote
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rb-fsevent
17
- requirement: &2153943140 !ruby/object:Gem::Requirement
17
+ requirement: &2152452780 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,21 +22,10 @@ dependencies:
22
22
  version: 0.4.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2153943140
26
- - !ruby/object:Gem::Dependency
27
- name: rb-appscript
28
- requirement: &2153942660 !ruby/object:Gem::Requirement
29
- none: false
30
- requirements:
31
- - - ! '>='
32
- - !ruby/object:Gem::Version
33
- version: 0.6.1
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: *2153942660
25
+ version_requirements: *2152452780
37
26
  - !ruby/object:Gem::Dependency
38
27
  name: term-ansicolor
39
- requirement: &2153942180 !ruby/object:Gem::Requirement
28
+ requirement: &2152452300 !ruby/object:Gem::Requirement
40
29
  none: false
41
30
  requirements:
42
31
  - - ! '>='
@@ -44,10 +33,10 @@ dependencies:
44
33
  version: 1.0.5
45
34
  type: :runtime
46
35
  prerelease: false
47
- version_requirements: *2153942180
36
+ version_requirements: *2152452300
48
37
  - !ruby/object:Gem::Dependency
49
38
  name: rb-fsevent
50
- requirement: &2153941700 !ruby/object:Gem::Requirement
39
+ requirement: &2152451820 !ruby/object:Gem::Requirement
51
40
  none: false
52
41
  requirements:
53
42
  - - ! '>='
@@ -55,21 +44,10 @@ dependencies:
55
44
  version: 0.4.0
56
45
  type: :development
57
46
  prerelease: false
58
- version_requirements: *2153941700
59
- - !ruby/object:Gem::Dependency
60
- name: rb-appscript
61
- requirement: &2153941220 !ruby/object:Gem::Requirement
62
- none: false
63
- requirements:
64
- - - ! '>='
65
- - !ruby/object:Gem::Version
66
- version: 0.6.1
67
- type: :development
68
- prerelease: false
69
- version_requirements: *2153941220
47
+ version_requirements: *2152451820
70
48
  - !ruby/object:Gem::Dependency
71
49
  name: term-ansicolor
72
- requirement: &2153940740 !ruby/object:Gem::Requirement
50
+ requirement: &2152451340 !ruby/object:Gem::Requirement
73
51
  none: false
74
52
  requirements:
75
53
  - - ! '>='
@@ -77,7 +55,7 @@ dependencies:
77
55
  version: 1.0.5
78
56
  type: :development
79
57
  prerelease: false
80
- version_requirements: *2153940740
58
+ version_requirements: *2152451340
81
59
  description: An intelligent command-line tool for combining, compressing and compiling
82
60
  your JavaScript and CoffeeScript files.
83
61
  email: developer@imulus.com
@@ -88,6 +66,10 @@ extra_rdoc_files:
88
66
  - README.md
89
67
  - bin/coyote
90
68
  - lib/coyote.rb
69
+ - lib/coyote/asset.rb
70
+ - lib/coyote/assets/coffeescript.rb
71
+ - lib/coyote/assets/javascript.rb
72
+ - lib/coyote/bundle.rb
91
73
  - lib/coyote/closure_compiler.rb
92
74
  - lib/coyote/configuration.rb
93
75
  - lib/coyote/fs_listener.rb
@@ -95,21 +77,17 @@ extra_rdoc_files:
95
77
  - lib/coyote/fs_listeners/linux.rb
96
78
  - lib/coyote/fs_listeners/polling.rb
97
79
  - lib/coyote/fs_listeners/windows.rb
98
- - lib/coyote/generator.rb
99
- - lib/coyote/notification.rb
100
- - lib/coyote/script.rb
101
- - lib/coyote/scripts/coffeescript.rb
102
- - lib/coyote/scripts/combine.rb
103
- - lib/coyote/scripts/javascript.rb
80
+ - lib/coyote/notifications.rb
104
81
  files:
105
82
  - README.md
106
83
  - Rakefile
107
84
  - bin/coyote
108
- - config/coyote-icon.png
109
- - config/coyote-usage.txt
110
- - config/coyote.yaml
111
85
  - coyote.gemspec
112
86
  - lib/coyote.rb
87
+ - lib/coyote/asset.rb
88
+ - lib/coyote/assets/coffeescript.rb
89
+ - lib/coyote/assets/javascript.rb
90
+ - lib/coyote/bundle.rb
113
91
  - lib/coyote/closure_compiler.rb
114
92
  - lib/coyote/configuration.rb
115
93
  - lib/coyote/fs_listener.rb
@@ -117,34 +95,15 @@ files:
117
95
  - lib/coyote/fs_listeners/linux.rb
118
96
  - lib/coyote/fs_listeners/polling.rb
119
97
  - lib/coyote/fs_listeners/windows.rb
120
- - lib/coyote/generator.rb
121
- - lib/coyote/notification.rb
122
- - lib/coyote/script.rb
123
- - lib/coyote/scripts/coffeescript.rb
124
- - lib/coyote/scripts/combine.rb
125
- - lib/coyote/scripts/javascript.rb
126
- - test/src/public/assets/javascripts/app/application/interface.coffee
127
- - test/src/public/assets/javascripts/app/application/main.coffee
128
- - test/src/public/assets/javascripts/app/application/pages/home.coffee
129
- - test/src/public/assets/javascripts/app/boot.coffee
130
- - test/src/public/assets/javascripts/lib/extensions.coffee
131
- - test/src/public/assets/javascripts/lib/imulus.coffee
132
- - test/src/public/assets/javascripts/lib/imulus/forms.coffee
133
- - test/src/public/assets/javascripts/lib/imulus/maps/infowindow.coffee
134
- - test/src/public/assets/javascripts/lib/imulus/maps/map.coffee
135
- - test/src/public/assets/javascripts/lib/imulus/maps/marker.coffee
136
- - test/src/public/assets/javascripts/lib/imulus/maps/point.coffee
137
- - test/src/public/assets/javascripts/lib/imulus/maps/results.coffee
138
- - test/src/public/assets/javascripts/lib/imulus/tables.coffee
139
- - test/src/public/assets/javascripts/lib/imulus/triggers.coffee
140
- - test/src/public/assets/javascripts/scripts.coffee
141
- - test/src/public/assets/javascripts/vendor/jquery.js
142
- - test/src/public/assets/javascripts/vendor/jquery/jquery.cookie.js
143
- - test/src/public/assets/javascripts/vendor/jquery/jquery.cycle.js
144
- - test/src/public/assets/javascripts/vendor/jquery/jquery.query.js
145
- - test/src/public/assets/javascripts/vendor/swfobject.js
146
- - test/src/public/scripts/scripts.combine
147
- - test/src/public/scripts/scripts.js
98
+ - lib/coyote/notifications.rb
99
+ - test/scripts/input1.js
100
+ - test/scripts/input2.js
101
+ - test/scripts/input3.js
102
+ - test/scripts/input4.js
103
+ - test/scripts/lib/input5.coffee
104
+ - test/scripts/lib/input6.js
105
+ - test/scripts/lib/keystone/input7.js
106
+ - test/scripts/vendor/input8.coffee
148
107
  - Manifest
149
108
  has_rdoc: true
150
109
  homepage: http://github.com/imulus/coyote