Class: Templatable::Core

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

Overview

Templatable Core

Constant Summary collapse

TEMPLATABLE_FILE =
"Templatablefile"
TEMPLATABLE_TEMPLATE =
<<-EOF
# encoding: utf-8

# output_fullpath
# output_fullpath is required
# output_fullpath allow only String
# output_fullpath's default value => "output_fullpath"
output_fullpath "output_fullpath"

# class_name
# class_name is required
# class_name allow only String
# class_name's default value => "class_name"
class_name "class_name"

TEMPLATE =<<-EOS
TODO: set your template(ERB format)
EOS

# template
# template is required
# template allow only String
# template's default value => "TODO: set your template(ERB format)"
template TEMPLATE

# placeholders
# placeholders is required
# placeholders allow only String-Array
# placeholders's default value => []
placeholders []
EOF
CLASS_TEMPLATE =
<<-EOF
# encoding: utf-8
require 'templatable'

class <%=class_name%>
  include Templatable
  template <<-EOS
<%=template%>
  EOS

<%=methods%>
end
EOF

Instance Method Summary collapse

Instance Method Details

#executeObject

generate TemplateApplayClass



62
63
64
65
66
67
68
69
70
# File 'lib/templatable_core.rb', line 62

def execute
  src = read_dsl
  dsl = Templatable::Dsl.new
  dsl.instance_eval src
  template = get_template dsl
  methods = get_methods dsl
  output_src = get_templatable_class_code(dsl.templatable.class_name.camelize, template.chop, methods)
  File.open(dsl.templatable.output_fullpath, "w:UTF-8") {|f|f.print output_src}
end

#initObject

generate Templatablefile to current directory.



57
58
59
# File 'lib/templatable_core.rb', line 57

def init
  File.open(TEMPLATABLE_FILE, "w") {|f|f.puts TEMPLATABLE_TEMPLATE}
end