fusion 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +25 -0
  2. data/lib/fusion.rb +42 -2
  3. metadata +28 -4
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # Fusion #
2
+
3
+ Is a javascript bundling plugin designed to work like sass. Configure it at startup. Re-bundle when you see a new request.
4
+
5
+ ## How? ##
6
+
7
+ ### Configuration ###
8
+
9
+ - You can specify multiple bundles in one yaml file.
10
+ - Per bundle, specify
11
+ + The output file name
12
+ + An input file list (whose order is preserved)
13
+ + An input directory
14
+
15
+ The unique set of files specified this way will be combined into one file.
16
+
17
+ ### Modes ###
18
+
19
+ The quick mode just does a dumb concatentation. This is very fast. Its recommended that you use this mode when using the 'reloading' feature.
20
+
21
+ The optimized mode uses Google Closure Compiler's SIMPLE_OPTIMIZATIONS flag -- which means comments and whitespace are stripped, and basic (non-obfuscating) optimizations are performed (such as inlining a function thats only called once).
22
+
23
+ ### Example ###
24
+
25
+ See the example [bundle.yaml](fusion/blob/master/doc/example-bundles.yaml) file. This example config will create 3 bundles: main.js / checkout.js / bottom.js
data/lib/fusion.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  require 'yaml'
2
2
  require 'open4'
3
+ require 'uri'
4
+ require 'rubygems' #I'm getting an error loading mechanize ... do I need to load this?
5
+ require 'mechanize'
6
+ require 'logger'
3
7
 
4
8
  module Fusion
5
9
 
@@ -19,6 +23,8 @@ module Fusion
19
23
 
20
24
  def initialize
21
25
  @bundle_options = Fusion.instance_variable_get('@options')
26
+ @log = @bundle_options[:logger] || Logger.new(STDOUT)
27
+
22
28
  @bundle_configs = YAML::load(File.open(@bundle_options[:bundle_file_path]))
23
29
  end
24
30
 
@@ -29,7 +35,7 @@ module Fusion
29
35
  bundle(config)
30
36
  end
31
37
 
32
- puts "Javascript Reloaded #{@bundle_configs.size} bundle(s) (#{Time.now - start}s)"
38
+ @log.debug "Javascript Reloaded #{@bundle_configs.size} bundle(s) (#{Time.now - start}s)"
33
39
  end
34
40
 
35
41
  def gather_files(config)
@@ -37,7 +43,15 @@ module Fusion
37
43
 
38
44
  if(config[:input_files])
39
45
  config[:input_files].each do |input_file|
40
- input_files << File.join(@bundle_options[:project_path], input_file)
46
+ @log.debug "Remote file? #{!(input_file =~ URI::regexp).nil?}"
47
+
48
+ if (input_file =~ URI::regexp).nil?
49
+ # Not a URL
50
+ input_files << File.join(@bundle_options[:project_path], input_file)
51
+ else
52
+ # This is a remote file, if we don't have it, get it
53
+ input_files << get_remote_file(input_file)
54
+ end
41
55
  end
42
56
  end
43
57
 
@@ -59,6 +73,32 @@ module Fusion
59
73
  File.join(@bundle_options[:project_path], config[:output_file])
60
74
  end
61
75
 
76
+ def get_remote_file(url)
77
+ filename = url.split("/").last
78
+ local_directory = File.join(@bundle_options[:project_path], ".remote")
79
+ local_file_path = File.join(local_directory, filename)
80
+
81
+ return local_file_path if File.exists?(local_file_path)
82
+
83
+ @log.debug "Fetching remote file (#{url})"
84
+
85
+ m = Mechanize.new
86
+ response = m.get(url)
87
+
88
+ raise Exception.new("Error downloading file (#{url}) -- returned code #{repsonse.code}") unless response.code == "200"
89
+
90
+ @log.debug "Got file (#{url})"
91
+
92
+ unless Dir.exists?(local_directory)
93
+ Dir.mkdir(local_directory)
94
+ end
95
+
96
+ File.open(local_file_path,"w") {|f| f << response.body}
97
+
98
+ local_file_path
99
+ end
100
+
101
+
62
102
  end
63
103
 
64
104
  class Quick < Basic
metadata CHANGED
@@ -1,8 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fusion
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 3
9
+ version: 0.0.3
6
10
  platform: ruby
7
11
  authors:
8
12
  - Sean Jezewski
@@ -10,7 +14,7 @@ autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
16
 
13
- date: 2011-06-09 00:00:00 -07:00
17
+ date: 2011-07-06 00:00:00 -07:00
14
18
  default_executable:
15
19
  dependencies:
16
20
  - !ruby/object:Gem::Dependency
@@ -21,9 +25,24 @@ dependencies:
21
25
  requirements:
22
26
  - - ">="
23
27
  - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
24
30
  version: "0"
25
31
  type: :runtime
26
32
  version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: mechanize
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
27
46
  description: Fusion bundles and re-bundles your javascript in two modes - quick (dumb concatenation) and optimized (google closure compiler's SIMPLE_OPTIMIZATIONS level
28
47
  email:
29
48
  - sean@moovweb.com
@@ -34,6 +53,7 @@ extensions: []
34
53
  extra_rdoc_files: []
35
54
 
36
55
  files:
56
+ - README.md
37
57
  - lib/fusion.rb
38
58
  - compiler/compiler.jar
39
59
  - compiler/COPYING
@@ -52,17 +72,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
52
72
  requirements:
53
73
  - - ">="
54
74
  - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
55
77
  version: "0"
56
78
  required_rubygems_version: !ruby/object:Gem::Requirement
57
79
  none: false
58
80
  requirements:
59
81
  - - ">="
60
82
  - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
61
85
  version: "0"
62
86
  requirements: []
63
87
 
64
88
  rubyforge_project:
65
- rubygems_version: 1.5.0
89
+ rubygems_version: 1.3.7
66
90
  signing_key:
67
91
  specification_version: 3
68
92
  summary: Simple javascript bundler plugin.