Class: Walrus::Grammar::ImportDirective
- Inherits:
-
Directive
- Object
- Directive
- Walrus::Grammar::ImportDirective
- Defined in:
- lib/walrus/grammar/import_directive.rb
Instance Method Summary collapse
-
#compile(options = {}) ⇒ Object
Returns an OpenStruct encapsulating information about the receiver for use by the compiler.
Instance Method Details
#compile(options = {}) ⇒ Object
Returns an OpenStruct encapsulating information about the receiver for use by the compiler
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/walrus/grammar/import_directive.rb', line 31 def compile = {} info = OpenStruct.new path = Pathname.new @class_name.lexeme.to_s if path.absolute? # it will work just fine as it is info.class_name = path.basename.to_s.to_class_name info.require_line = "require '#{path.to_s}'" else dir, base = path.split info.class_name = base.to_s.to_class_name if dir.to_s == '.' # desired template is in the same directory info.require_line = "require File.join(File.dirname(__FILE__), '#{base.to_s}').to_s" else # desired template is in a relative directory info.require_line = "require File.join(File.dirname(__FILE__), '#{dir.to_s}', '#{base.to_s}').to_s" end end info end |