Class: Sprockets::Rollup
- Inherits:
-
Object
- Object
- Sprockets::Rollup
- Defined in:
- lib/sprockets/rollup.rb
Class Attribute Summary collapse
-
.configuration ⇒ Object
Returns the value of attribute configuration.
Instance Attribute Summary collapse
-
#cache_key ⇒ Object
readonly
Returns the value of attribute cache_key.
Class Method Summary collapse
- .cache_key ⇒ Object
- .call(input) ⇒ Object
- .configuration_hash ⇒ Object
- .configure {|configuration| ... } ⇒ Object
- .instance ⇒ Object
- .reset_configuration ⇒ Object
Instance Method Summary collapse
- #call(input) ⇒ Object
- #compile(input) ⇒ Object
- #configuration_hash ⇒ Object
-
#initialize(options = {}) ⇒ Rollup
constructor
A new instance of Rollup.
- #rollup(input) ⇒ Object
- #transform(input) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Rollup
Returns a new instance of Rollup.
48 49 50 |
# File 'lib/sprockets/rollup.rb', line 48 def initialize( = {}) @options = configuration_hash.merge().freeze end |
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
10 11 12 |
# File 'lib/sprockets/rollup.rb', line 10 def configuration @configuration end |
Instance Attribute Details
#cache_key ⇒ Object (readonly)
Returns the value of attribute cache_key.
42 43 44 |
# File 'lib/sprockets/rollup.rb', line 42 def cache_key @cache_key end |
Class Method Details
.cache_key ⇒ Object
36 37 38 |
# File 'lib/sprockets/rollup.rb', line 36 def cache_key instance.cache_key end |
.call(input) ⇒ Object
32 33 34 |
# File 'lib/sprockets/rollup.rb', line 32 def call(input) instance.call(input) end |
.configuration_hash ⇒ Object
12 13 14 15 16 17 |
# File 'lib/sprockets/rollup.rb', line 12 def configuration_hash configuration.to_h.reduce({}) do |hash, (key, val)| hash[key.to_s] = val hash end end |
.configure {|configuration| ... } ⇒ Object
23 24 25 26 |
# File 'lib/sprockets/rollup.rb', line 23 def configure self.configuration ||= OpenStruct.new yield configuration end |
.instance ⇒ Object
19 20 21 |
# File 'lib/sprockets/rollup.rb', line 19 def instance @instance ||= new end |
.reset_configuration ⇒ Object
28 29 30 |
# File 'lib/sprockets/rollup.rb', line 28 def reset_configuration self.configuration = OpenStruct.new end |
Instance Method Details
#call(input) ⇒ Object
52 53 54 |
# File 'lib/sprockets/rollup.rb', line 52 def call(input) transform input end |
#compile(input) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/sprockets/rollup.rb', line 67 def compile(input) path_to_buble = File.join File.dirname(__FILE__), "buble.js" output = nil IO.popen(['node', path_to_buble], 'r+') do |pipe| pipe.write(input) pipe.close_write output = pipe.read end raise ArgumentError, output if $? != 0 output end |
#configuration_hash ⇒ Object
44 45 46 |
# File 'lib/sprockets/rollup.rb', line 44 def configuration_hash self.class.configuration_hash end |
#rollup(input) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/sprockets/rollup.rb', line 60 def rollup(input) path_to_rollup = File.join File.dirname(__FILE__), "rollup.js" output = `node #{path_to_rollup} #{input[:filename].shellescape}` raise ArgumentError, output if $? != 0 output end |
#transform(input) ⇒ Object
56 57 58 |
# File 'lib/sprockets/rollup.rb', line 56 def transform(input) compile(rollup(input)) end |