Class: Color::RGB::JP::Compiler::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/color/rgb/jp/compiler/compiler.rb

Constant Summary collapse

COLOR_NAME_CHAR =
/[^[:space:][:punct:][:cntrl:]]/
COLOR_NAME_RE =
/#{COLOR_NAME_CHAR}+(?:-#{COLOR_NAME_CHAR}+)*/
DEFAULT_PREPROCESSOR =
[:preprocess_alias, :preprocess_color]
DEFAULT_TRIM_MODE =
">%"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pallet, encoding, prefix, generator) ⇒ Compiler

Returns a new instance of Compiler.



21
22
23
24
25
26
27
28
# File 'lib/color/rgb/jp/compiler/compiler.rb', line 21

def initialize(pallet, encoding, prefix, generator)
  @pallet = pallet
  @encoding = encoding
  @prefix = prefix
  @generator = generator
  @preprocessor = DEFAULT_PREPROCESSOR
  @trim_mode = DEFAULT_TRIM_MODE
end

Instance Attribute Details

#encodingObject

Returns the value of attribute encoding.



19
20
21
# File 'lib/color/rgb/jp/compiler/compiler.rb', line 19

def encoding
  @encoding
end

#generatorObject

Returns the value of attribute generator.



19
20
21
# File 'lib/color/rgb/jp/compiler/compiler.rb', line 19

def generator
  @generator
end

#palletObject

Returns the value of attribute pallet.



19
20
21
# File 'lib/color/rgb/jp/compiler/compiler.rb', line 19

def pallet
  @pallet
end

#prefixObject

Returns the value of attribute prefix.



19
20
21
# File 'lib/color/rgb/jp/compiler/compiler.rb', line 19

def prefix
  @prefix
end

#preprocessorObject

Returns the value of attribute preprocessor.



19
20
21
# File 'lib/color/rgb/jp/compiler/compiler.rb', line 19

def preprocessor
  @preprocessor
end

#trim_modeObject

Returns the value of attribute trim_mode.



19
20
21
# File 'lib/color/rgb/jp/compiler/compiler.rb', line 19

def trim_mode
  @trim_mode
end

Instance Method Details

#compile(src, input) ⇒ Object



47
48
49
50
51
# File 'lib/color/rgb/jp/compiler/compiler.rb', line 47

def compile(src, input)
  e = ERB.new(src, 0, @trim_mode)
  e.filename = input if String === input
  e.result
end

#execute(input, output, do_compile) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/color/rgb/jp/compiler/compiler.rb', line 30

def execute(input, output, do_compile)
  with_input_stream(input) do |is|
    erbscript = preprocess(is.read, input)
    with_output_stream(output) do |os|
      if do_compile
        os.write compile(erbscript, input)
      else
        os.write erbscript
      end
    end
  end
end

#preprocess(src, input) ⇒ Object



43
44
45
# File 'lib/color/rgb/jp/compiler/compiler.rb', line 43

def preprocess(src, input)
  preprocess_snippet(prefix) + do_preprocess(src, @prefix)
end