Class: WLang::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/wlang/command.rb

Overview

wlang – templating engine

SYNOPSIS

Usage: wlang [options] TEMPLATE [ATTR1 VALUE1 ATTR2 VALUE2]

OPTIONS: #summarized_options

DESCRIPTION

This command invokes the wlang templating engine on TEMPLATE and flushes the
rendering result on standard output.

Commandline template data can be passed through ATTR and VALUE arguments.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Command

Returns a new instance of Command.



30
31
32
33
34
35
36
37
38
39
# File 'lib/wlang/command.rb', line 30

def initialize(*args)
  require 'wlang/html'
  super
  @output = nil
  @yaml_front_matter = true
  @ast = false
  @compiling_options = {}
  @context = {}
  @dialect = WLang::Html
end

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast.



23
24
25
# File 'lib/wlang/command.rb', line 23

def ast
  @ast
end

#compiling_optionsObject (readonly)

Returns the value of attribute compiling_options.



24
25
26
# File 'lib/wlang/command.rb', line 24

def compiling_options
  @compiling_options
end

#contextObject (readonly)

Returns the value of attribute context.



25
26
27
# File 'lib/wlang/command.rb', line 25

def context
  @context
end

#dialectObject (readonly)

Returns the value of attribute dialect.



26
27
28
# File 'lib/wlang/command.rb', line 26

def dialect
  @dialect
end

#outputObject (readonly)

Returns the value of attribute output.



21
22
23
# File 'lib/wlang/command.rb', line 21

def output
  @output
end

#templateObject (readonly)

Returns the value of attribute template.



28
29
30
# File 'lib/wlang/command.rb', line 28

def template
  @template
end

#tpl_fileObject (readonly)

Returns the value of attribute tpl_file.



27
28
29
# File 'lib/wlang/command.rb', line 27

def tpl_file
  @tpl_file
end

#yaml_front_matterObject (readonly)

Returns the value of attribute yaml_front_matter.



22
23
24
# File 'lib/wlang/command.rb', line 22

def yaml_front_matter
  @yaml_front_matter
end

Instance Method Details

#execute(argv) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/wlang/command.rb', line 63

def execute(argv)
  install(argv)

  if @ast
    begin
      require 'awesome_print'
      ap @template.to_ast
    rescue LoadError
      puts "HINT: install the 'awesome_print' gem for pretty output!"
      puts @template.to_ast.inspect
    end
  end

  with_output do |output|
    @template.render(@context, output)
  end
end