Class: Sprockets::Rollup

Inherits:
Object
  • Object
show all
Defined in:
lib/sprockets/rollup.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Rollup

Returns a new instance of Rollup.



48
49
50
# File 'lib/sprockets/rollup.rb', line 48

def initialize(options = {})
  @options = configuration_hash.merge(options).freeze
end

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



10
11
12
# File 'lib/sprockets/rollup.rb', line 10

def configuration
  @configuration
end

Instance Attribute Details

#cache_keyObject (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_keyObject



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_hashObject



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

Yields:



23
24
25
26
# File 'lib/sprockets/rollup.rb', line 23

def configure
  self.configuration ||= OpenStruct.new
  yield configuration
end

.instanceObject



19
20
21
# File 'lib/sprockets/rollup.rb', line 19

def instance
  @instance ||= new
end

.reset_configurationObject



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

Raises:

  • (ArgumentError)


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_hashObject



44
45
46
# File 'lib/sprockets/rollup.rb', line 44

def configuration_hash
  self.class.configuration_hash
end

#rollup(input) ⇒ Object

Raises:

  • (ArgumentError)


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