Class: RBlade::Compiler
- Inherits:
-
Object
- Object
- RBlade::Compiler
- Defined in:
- lib/rblade/compiler.rb
Class Method Summary collapse
- .compile_attribute_string(string_template) ⇒ Object
- .compile_string(string_template, component_store) ⇒ Object
- .compile_tokens(tokens) ⇒ Object
- .generate_source_map(string_template, component_store) ⇒ Object
- .tokenize_string(string_template, component_store) ⇒ Object
Class Method Details
.compile_attribute_string(string_template) ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/rblade/compiler.rb', line 97 def self.compile_attribute_string(string_template) tokens = [Token.new(:unprocessed, string_template)] CompilesComments.compile!(tokens) CompilesRuby.compile! tokens CompilesPrints.compile!(tokens) compile_tokens tokens end |
.compile_string(string_template, component_store) ⇒ Object
41 42 43 44 45 |
# File 'lib/rblade/compiler.rb', line 41 def self.compile_string(string_template, component_store) tokens = tokenize_string string_template, component_store compile_tokens tokens end |
.compile_tokens(tokens) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/rblade/compiler.rb', line 107 def self.compile_tokens(tokens) output = +"" i = 0 while i < tokens.count token = tokens[i] if token.type == :unprocessed || token.type == :raw_text output << "@output_buffer.raw_buffer<<-'" # Merge together consecutive prints while tokens[i + 1]&.type == :unprocessed || tokens[i + 1]&.type == :raw_text output << RBlade.escape_quotes(token.value) i += 1 token = tokens[i] end output << RBlade.escape_quotes(token.value) output << "';" else output << token.value end i += 1 end output end |
.generate_source_map(string_template, component_store) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rblade/compiler.rb', line 47 def self.generate_source_map(string_template, component_store) tokens = tokenize_string string_template, component_store source_map = SourceMap.new(string_template) i = 0 while i < tokens.count token = tokens[i] if token.type == :unprocessed || token.type == :raw_text start_offset = token.start_offset compiled_code = +"@output_buffer.raw_buffer<<-'" # Merge together consecutive prints while tokens[i + 1]&.type == :unprocessed || tokens[i + 1]&.type == :raw_text compiled_code << RBlade.escape_quotes(token.value) i += 1 token = tokens[i] end compiled_code << RBlade.escape_quotes(token.value) compiled_code << "';" source_map.add(start_offset, token.end_offset, compiled_code) else source_map.add(token.start_offset, token.end_offset, token.value) end i += 1 end source_map end |
.tokenize_string(string_template, component_store) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rblade/compiler.rb', line 80 def self.tokenize_string(string_template, component_store) tokens = [Token.new(:unprocessed, string_template, 0, string_template.length)] CompilesVerbatim.new.compile! tokens CompilesComments.new.compile! tokens TokenizesComponents.new.tokenize! tokens CompilesInjections.new.compile! tokens TokenizesStatements.new.tokenize! tokens CompilesStatements.new.compile! tokens component_compiler = CompilesComponents.new(component_store) component_compiler.compile! tokens component_compiler. tokens end |