class Juli::Macro::TemplateBase

Base class for HTML template related macros.

Derived class can provide HTML template replacement with minimum implementation. Please see Wikipedia case as an example.

Constants

DEFAULT_TEMPLATE

Public Class Methods

conf_template() click to toggle source
# File lib/juli/macro/template_base.rb, line 10
def self.conf_template
  ''
end

Public Instance Methods

conf_key() click to toggle source

return key string used for conf-key

Please overwrite this method if it is not just underscore-ed.

# File lib/juli/macro/template_base.rb, line 17
def conf_key
  Juli::Util::underscore(self.class.to_s)
end
place_holder() click to toggle source

return string used to be replaced with %{…} in conf string.

Please overwrite this method if it is not just underscore-ed.

# File lib/juli/macro/template_base.rb, line 34
def place_holder
  conf_key
end
run(*args) click to toggle source
# File lib/juli/macro/template_base.rb, line 38
def run(*args)
  template = conf[conf_key]
  template.gsub("%{#{place_holder}}", args[0])
end
set_conf_default(conf) click to toggle source

set default value in conf if no .juli/conf defined.

Please overwrite this method when this implementation is not your case.

# File lib/juli/macro/template_base.rb, line 25
def set_conf_default(conf)
  if !conf[conf_key]
    conf[conf_key] = self.class::DEFAULT_TEMPLATE
  end
end