Class: Juli::Macro::TemplateBase

Inherits:
Base
  • Object
show all
Defined in:
lib/juli/macro/template_base.rb

Overview

Base class for HTML template related macros.

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

Direct Known Subclasses

Amazon, Jmap, Wikipedia

Constant Summary collapse

DEFAULT_TEMPLATE =
''

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#after_root, #initialize, #on_root

Methods included from Util

#camelize, conf, find_template, in_filename, juli_repo, mkdir, out_filename, str_limit, str_trim, to_wikiname, underscore, usage, visitor, visitor_list

Constructor Details

This class inherits a constructor from Juli::Macro::Base

Class Method Details

.conf_templateObject



10
11
12
# File 'lib/juli/macro/template_base.rb', line 10

def self.conf_template
  ''
end

Instance Method Details

#conf_keyObject

return key string used for conf-key

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



17
18
19
# File 'lib/juli/macro/template_base.rb', line 17

def conf_key
  Juli::Util::underscore(self.class.to_s)
end

#place_holderObject

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

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



34
35
36
# File 'lib/juli/macro/template_base.rb', line 34

def place_holder
  conf_key
end

#run(*args) ⇒ Object



38
39
40
41
# 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) ⇒ Object

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

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



25
26
27
28
29
# 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