Class: Color::RGB::JP::Compiler::Compiler
- Inherits:
-
Object
- Object
- Color::RGB::JP::Compiler::Compiler
- 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
-
#encoding ⇒ Object
Returns the value of attribute encoding.
-
#generator ⇒ Object
Returns the value of attribute generator.
-
#pallet ⇒ Object
Returns the value of attribute pallet.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#preprocessor ⇒ Object
Returns the value of attribute preprocessor.
-
#trim_mode ⇒ Object
Returns the value of attribute trim_mode.
Instance Method Summary collapse
- #compile(src, input) ⇒ Object
- #execute(input, output, do_compile) ⇒ Object
-
#initialize(pallet, encoding, prefix, generator) ⇒ Compiler
constructor
A new instance of Compiler.
- #preprocess(src, input) ⇒ Object
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
#encoding ⇒ Object
Returns the value of attribute encoding.
19 20 21 |
# File 'lib/color/rgb/jp/compiler/compiler.rb', line 19 def encoding @encoding end |
#generator ⇒ Object
Returns the value of attribute generator.
19 20 21 |
# File 'lib/color/rgb/jp/compiler/compiler.rb', line 19 def generator @generator end |
#pallet ⇒ Object
Returns the value of attribute pallet.
19 20 21 |
# File 'lib/color/rgb/jp/compiler/compiler.rb', line 19 def pallet @pallet end |
#prefix ⇒ Object
Returns the value of attribute prefix.
19 20 21 |
# File 'lib/color/rgb/jp/compiler/compiler.rb', line 19 def prefix @prefix end |
#preprocessor ⇒ Object
Returns the value of attribute preprocessor.
19 20 21 |
# File 'lib/color/rgb/jp/compiler/compiler.rb', line 19 def preprocessor @preprocessor end |
#trim_mode ⇒ Object
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 |