Module: Ferb::ClassMethods
- Defined in:
- lib/ferb.rb
Overview
Inner module holding the actual methods to be added to the class
Instance Method Summary collapse
-
#add_timestamp(path, time) ⇒ Object
Record file timestamps.
-
#def_template(signature, args) ⇒ Object
Defines a template function as an instance method.
-
#file_timestamps ⇒ Object
Hash of file timestamps.
-
#should_reload?(path) ⇒ Boolean
Test file timestamps.
-
#template_root ⇒ Object
Returns the root in the file system where ERB templates can be found.
-
#template_root=(location) ⇒ Object
Sets the root in the file system where ERB templates can be found.
Instance Method Details
#add_timestamp(path, time) ⇒ Object
Record file timestamps
174 175 176 |
# File 'lib/ferb.rb', line 174 def (path, time) self.[path.to_s] = time end |
#def_template(signature, args) ⇒ Object
Defines a template function as an instance method. Creates the method directly on the class.
Arguments:
<tt>signature</tt> - (string) The complete signature including parameters
<tt>body</tt> - (string) The body of the functionusing ERB syntax
Example:
def_template(“hello_world(message)”,“<%= message %>”)
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/ferb.rb', line 215 def def_template(signature,args) if args.is_a?(String) internal_func = Ferb.construct_internal_function_def(signature,args) external_func = Ferb.construct_function_def(signature,args) module_eval(internal_func) module_eval(external_func) elsif args.is_a?(Hash) args = { :template_root => template_root}.merge(args) template = Ferb.load_template(args) (args[:full_path], args[:timestamp]) internal_func = Ferb.construct_internal_function_def(signature,template) external_func = Ferb.construct_function_def(signature,template,args) module_eval(internal_func) module_eval(external_func) end end |
#file_timestamps ⇒ Object
Hash of file timestamps
166 167 168 169 170 171 |
# File 'lib/ferb.rb', line 166 def unless defined?() = {} end end |
#should_reload?(path) ⇒ Boolean
Test file timestamps
179 180 181 182 183 184 185 186 187 |
# File 'lib/ferb.rb', line 179 def should_reload?(path) time = Pathname.new(path.to_s).mtime ts = self.[path] if ts and (ts >= time) return false; else return true end end |
#template_root ⇒ Object
Returns the root in the file system where ERB templates can be found
190 191 192 193 194 195 |
# File 'lib/ferb.rb', line 190 def template_root if !defined?(@template_root) @template_root = Pathname.new(File.(File.dirname(__FILE__))) end @template_root end |
#template_root=(location) ⇒ Object
Sets the root in the file system where ERB templates can be found
198 199 200 |
# File 'lib/ferb.rb', line 198 def template_root=(location) @template_root = Pathname.new(File.(location.to_s)) end |