Class: DevSystem::ErbShell::LERB
- Inherits:
-
ERB
- Object
- ERB
- DevSystem::ErbShell::LERB
- Defined in:
- lib/dev_system/subsystems/shell/shells/erb_shell.rb
Defined Under Namespace
Classes: BuildError, Error, ExecutionError
Constant Summary collapse
- DEFAULT_KEY =
loaders
"inline.txt.erb"- TAG_FORMATS =
format
%w|xml html|
- TRIM_MODE =
constructor
"<>-"
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
- ._load(erbs, filename, views_type) ⇒ Object
- ._load_into(erbs, filename, lineno, key, content) ⇒ Object
- .load(path_radical) ⇒ Object
-
.puts(string = nil) ⇒ Object
output.
Instance Method Summary collapse
-
#initialize(filename, lineno, key, content) ⇒ LERB
constructor
A new instance of LERB.
-
#result(the_binding, receiver = :unset) ⇒ Object
result.
- #tags? ⇒ Boolean
Constructor Details
#initialize(filename, lineno, key, content) ⇒ LERB
Returns a new instance of LERB.
144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/dev_system/subsystems/shell/shells/erb_shell.rb', line 144 def initialize filename, lineno, key, content segments = key.split("/").last.split(".") name, format = segments[0..1] if format.gsub(/[^a-z0-9]/, "") != format raise BuildError, "key '#{key}' has an invalid format '#{format}'" end super content, trim_mode: TRIM_MODE self.filename, self.lineno, @key, @name, @format = filename, lineno, key, name, format end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
142 143 144 |
# File 'lib/dev_system/subsystems/shell/shells/erb_shell.rb', line 142 def format @format end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
142 143 144 |
# File 'lib/dev_system/subsystems/shell/shells/erb_shell.rb', line 142 def key @key end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
142 143 144 |
# File 'lib/dev_system/subsystems/shell/shells/erb_shell.rb', line 142 def name @name end |
Class Method Details
._load(erbs, filename, views_type) ⇒ Object
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/dev_system/subsystems/shell/shells/erb_shell.rb', line 52 def self._load erbs, filename, views_type is_eof = views_type == :eof is_adjacent = views_type == :adjacent is_nested = views_type == :nested is_erb = filename.end_with? ".erb" is_ignoring_ruby = is_eof is_accepting_views = is_eof || is_adjacent puts puts "LERB filename: #{filename}" puts Liza::Unit.stick :red, "LERB views_type: :#{views_type}" puts "LERB is_eof: #{is_eof}" puts "LERB is_adjacent: #{is_adjacent}" puts "LERB is_nested: #{is_nested}" puts "LERB is_erb: #{is_erb}" puts "LERB is_ignoring_ruby: #{is_ignoring_ruby}" puts "LERB is_accepting_views: #{is_accepting_views}" current_lineno = 0 current_content = "" current_key = DEFAULT_KEY if is_nested current_key = filename.split("/").last.split(".")[-3..-1].join(".") puts "LERB declare: #{current_key} | because nested" end File.readlines(filename).each.with_index do |line, lineno| is_line_end = line == "__END__\n" # stop ignoring ruby lines if line is __END__ # move to next line if ignoring ruby lines if is_ignoring_ruby puts "LERB ignore: #{lineno}: #{line[0..-2]}" if is_line_end is_ignoring_ruby = false is_accepting_views = true current_lineno = lineno + 1 puts "LERB declare: #{current_key} | current" if current_key end next end if is_accepting_views && line[0..6] == "# view " _load_into erbs, filename, current_lineno, current_key, current_content current_key = line[7..-1].strip current_lineno = lineno + 1 current_content = "" puts "LERB declare: #{current_key} | #{lineno}: #{line[0..-2]}" else current_content += line puts "LERB keeping: #{lineno}: #{line[0..-2]}" end if is_line_end puts "LERB warning: #{lineno}: #{line[0..-2]} found! No longer accepting views" is_accepting_views = false end end _load_into erbs, filename, current_lineno, current_key, current_content erbs end |
._load_into(erbs, filename, lineno, key, content) ⇒ Object
120 121 122 123 124 125 126 127 128 |
# File 'lib/dev_system/subsystems/shell/shells/erb_shell.rb', line 120 def self._load_into erbs, filename, lineno, key, content return unless key return unless key.end_with? "erb" return if content.strip.empty? content += "\n" if content[-1] != "\n" erbs.push new filename, lineno, key, content end |
.load(path_radical) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/dev_system/subsystems/shell/shells/erb_shell.rb', line 27 def self.load path_radical erbs = [] "#{path_radical}.rb".tap do |filename| _load erbs, filename, :eof end Dir.glob("#{path_radical}.rb.*.erb").each do |filename| _load erbs, filename, :adjacent end Dir.glob("#{path_radical}/*.*.erb").each do |filename| _load erbs, filename, :nested end # puts "#{erbs.size} erbs" erbs.each do |h| puts "key: #{h.key}" end erbs end |
.puts(string = nil) ⇒ Object
output
19 20 21 |
# File 'lib/dev_system/subsystems/shell/shells/erb_shell.rb', line 19 def self.puts string=nil super if $LERB_VERBOSE end |
Instance Method Details
#result(the_binding, receiver = :unset) ⇒ Object
result
158 159 160 161 162 163 164 |
# File 'lib/dev_system/subsystems/shell/shells/erb_shell.rb', line 158 def result the_binding, receiver=:unset super the_binding rescue NameError => e raise unless e.receiver == receiver = "ERB template for a #{e.receiver.class} instance could not find method '#{e.name}'" raise ExecutionError, , [e.backtrace[0]] end |
#tags? ⇒ Boolean
134 135 136 |
# File 'lib/dev_system/subsystems/shell/shells/erb_shell.rb', line 134 def TAG_FORMATS.include? format end |