Class: Lash::JavaScriptBundler
- Inherits:
-
Object
- Object
- Lash::JavaScriptBundler
- Defined in:
- lib/lash/java_script_bundler.rb
Overview
Bundles JavaScripts into single files or individually minified scripts
Example
bundler = JavaScriptBundler.new
bundler.bundle( "application", :style => :single ) # => bundle_application.js
bundler.bundle( "demand", :style => :individual ) # => demand/form.min.js
# => demand/fancybox.min.js
Instance Method Summary collapse
-
#bundle(directory, options = nil) ⇒ Object
Bundles all the scripts in the directory.
- #bundle_style(directory) ⇒ Object
-
#initialize(options = nil) ⇒ JavaScriptBundler
constructor
A new instance of JavaScriptBundler.
Constructor Details
#initialize(options = nil) ⇒ JavaScriptBundler
Returns a new instance of JavaScriptBundler.
19 20 21 22 23 24 25 |
# File 'lib/lash/java_script_bundler.rb', line 19 def initialize( = nil ) @options ||= {} @minifiers = [ [:minifiers] || ClosureMinifier.new ].flatten @options[:javascripts_path] ||= File.( File.join( Rails.root, "public/javascripts" ) ) @demand_dirs ||= [:demand_dirs] || ["demand"] @cdn_dirs ||= [:cdn_dirs] || ["cdn"] end |
Instance Method Details
#bundle(directory, options = nil) ⇒ Object
Bundles all the scripts in the directory
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/lash/java_script_bundler.rb', line 28 def bundle( directory, = nil ) = ( || {}, directory ) files = Lash::Files.recursive_file_list( [:directory], '.js' ) case [:style] when :single bundle_into_single_script files, when :individual files = files.reject{ |f| f.end_with? 'min.js' } bundle_individual_scripts files, end end |
#bundle_style(directory) ⇒ Object
41 42 43 |
# File 'lib/lash/java_script_bundler.rb', line 41 def bundle_style( directory ) infer_style_from_directory directory end |