Class: PuppetHerald::Javascript
- Inherits:
-
Object
- Object
- PuppetHerald::Javascript
- Defined in:
- lib/puppet-herald/javascript.rb
Overview
A javascript processing class
Instance Method Summary collapse
-
#files ⇒ Array
Returns a list of JS files to be inserted into main HTML.
-
#initialize ⇒ Javascript
constructor
Initialize JS class.
-
#uglify(mapname) ⇒ Hash
Uglify an application JS’s into one minified JS file.
Constructor Details
#initialize ⇒ Javascript
Initialize JS class
6 7 8 9 |
# File 'lib/puppet-herald/javascript.rb', line 6 def initialize @files = nil @base = 'lib/puppet-herald/public' end |
Instance Method Details
#files ⇒ Array
Returns a list of JS files to be inserted into main HTML
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/puppet-herald/javascript.rb', line 13 def files require 'puppet-herald' @files = nil if PuppetHerald.in_dev? if @files.nil? public_dir = PuppetHerald.relative_dir(@base) all = Dir.chdir(public_dir) { Dir.glob('**/*.js') } all = all.reverse.reject { |file| file.match(/_test\.js$/) } @files = all.reject { |file| file.match(/bower_components/) } end @files end |
#uglify(mapname) ⇒ Hash
Uglify an application JS’s into one minified JS file
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/puppet-herald/javascript.rb', line 28 def uglify(mapname) require 'uglifier' filenames = files sources = filenames.collect { |file| File.read(PuppetHerald.relative_dir("#{@base}/#{file}")) } source = sources.join "\n" = { source_map_url: mapname, source_filename: filenames[0], compress: { angular: true, hoist_vars: true } } uglifier = Uglifier.new() uglified, source_map = uglifier.compile_with_map(source) { 'js' => uglified, 'js.map' => source_map } end |