class Eggshell::Bundles::Basic::CoreMacros
These macros are highly recommended to always be part of an instance of the processor.
dl.
- {{!}}
-
sets default parameter values (block parameters) so that they don't have to be
specified for every block instance.
- {{raw}}
-
passes all block lines up into output chain. Macros are assembled before being
outputted.
- {{pipe}}
-
allows blocks to pipe into the adjacent block
{{process}} always dynamic processing of content. This allows previous macros to build up a document dynamically.
Constants
- CAP_OUT
Public Class Methods
make_include_paths(inc, opts)
click to toggle source
# File lib/eggshell/bundles/basics.rb, line 756 def self.make_include_paths(inc, opts) checks = [] if inc[0] != '/' if opts[:include_paths] opts[:include_paths].each do |root| checks << "#{root}/#{inc}" end # @todo if :include_root, expand path and check that it's under the root, otherwise, sandbox end else # sandboxed root include if opts[:include_root] checks << "#{opts[:include_root]}#{inc}" else checks << inc end end checks end
Public Instance Methods
collection_type(macro)
click to toggle source
# File lib/eggshell/bundles/basics.rb, line 671 def collection_type(macro) macro == 'raw' ? MH::COLLECT_RAW_MACRO : MH::COLLECT_NORMAL end
do_include(paths, buff, call_depth, opts = {})
click to toggle source
# File lib/eggshell/bundles/basics.rb, line 729 def do_include(paths, buff, call_depth, opts = {}) paths = [paths] if !paths.is_a?(Array) # @todo check all include paths? paths.each do |inc| inc = inc.line if inc.is_a?(Eggshell::Line) inc = @eggshell.expand_expr(inc.strip) CoreMacros.make_include_paths(inc, @vars).each do |inc| if File.exists?(inc) lines = IO.readlines(inc, $/, opts) @vars[:include_stack] << inc begin buff << @eggshell.process(lines, 0, call_depth + 1) @eggshell._debug("include: 200 #{inc}") rescue => ex @eggshell._error("include: 500 #{inc}: #{ex.message}#{ex.backtrace.join("\n\t")}") end @vars[:include_stack].pop break else @eggshell._warn("include: 404 #{inc}") end end end end
process(name, args, lines, out, call_depth = 0)
click to toggle source
# File lib/eggshell/bundles/basics.rb, line 675 def process(name, args, lines, out, call_depth = 0) if name == '=' || name == 'var' # @todo expand args[0]? if args[0] val = nil if args[1].is_a?(Array) && args[1][0].is_a?(Symbol) val = @eggshell.expr_eval(args[1]) else val = args[1] end @eggshell.vars[args[0]] = val end elsif name == '!' block_name = args[0] block_params = args[1] set_block_params(block_name, block_params) if block_name elsif name == 'process' elsif name == 'capture' var = args[0] || CAP_OUT captured = @eggshell.assemble(lines, call_depth + 1) captured = @eggshell.expand_expr(captured) @eggshell.vars[var] = captured elsif name == 'include' paths = args[0] opts = args[1] || {} if opts['encoding'] opts[:encoding] = opts['encoding'] else opts[:encoding] = 'utf-8' end if lines && lines.length > 0 paths = lines end do_include(paths, out, call_depth, opts) elsif name == 'raw' lines.each do |unit| if unit.is_a?(Array) if unit[0] == :block unit[Eggshell::ParseTree::IDX_LINES].each do |line| out << line.to_s end else out << @eggshell.assemble(unit, call_depth + 1) end else out << unit end end elsif name == 'pipe' out << @eggshell.assemble(lines, call_depth + 1) end end
set_processor(proc, opts = nil)
click to toggle source
# File lib/eggshell/bundles/basics.rb, line 651 def set_processor(proc, opts = nil) opts = {} if !opts @opts = opts @eggshell = proc @eggshell.add_macro_handler(self, '=', 'var', '!', 'process', 'capture', 'raw', 'pipe') @eggshell.add_macro_handler(self, 'include') if !@opts['macro.include.off'] @vars = @eggshell.vars @vars[:include_stack] = [] if opts['include.options'] opts['include.options'].each do |k,v| @vars[k.to_sym] = v end end if @vars[:include_paths].length == 0 @vars[:include_paths] = [Dir.getwd] end end