lib/opulent/compiler.rb in opulent-1.0.2 vs lib/opulent/compiler.rb in opulent-1.0.3

- old
+ new

@@ -3,10 +3,11 @@ require_relative 'compiler/control.rb' require_relative 'compiler/define.rb' require_relative 'compiler/eval.rb' require_relative 'compiler/filter.rb' require_relative 'compiler/node.rb' +require_relative 'compiler/require.rb' require_relative 'compiler/root.rb' require_relative 'compiler/text.rb' # @Opulent module Opulent @@ -17,18 +18,26 @@ # All node Objects (Array) must follow the next convention in order # to make parsing faster # # [:node_type, :value, :attributes, :children, :indent] # - def initialize + # @param path [String] Current file path needed for require nodes + # + def initialize(settings = {}) # Setup convention accessors @type = 0 @value = 1 @options = 2 @children = 3 @indent = 4 + # Set current compiled file + @path = File.dirname settings.delete :path + + # Extract definitions for require directives + @definitions = settings.delete :definitions + # Create the HTML Entities encoder/decoder @entities = HTMLEntities.new # Get special node types from the settings @multi_node = Settings::MultiNode @@ -50,11 +59,11 @@ @block_stack = [] end # Compile input nodes, replace them with their definitions and # - # @param root [Array] Root node containing all document nodes + # @param root_node [Array] Root node containing all document nodes # @param context [Context] Context holding environment variables # def compile(root_node, context) # Compiler generated code @code = "" @@ -119,9 +128,11 @@ "Please use a Hash to extend attributes." when :filter_registered "The \"#{data[0]}\" filter could not be recognized by Opulent." when :filter_load "The gem required for the \"#{data[0]}\" filter is not installed. You can install it by running:\n\n#{data[1]}" + when :require + "The required file #{data[0]} does not exist or an incorrect path has been specified." end # Reconstruct lines to display where errors occur fail "\n\nOpulent " + Logger.red("[Runtime Error]") + "\n---\n" + "A runtime error has been encountered when building the compiled node tree.\n" +