Class: Rad::Template
- Defined in:
- lib/rad/template/_require.rb,
lib/rad/template/_template.rb
Defined Under Namespace
Classes: Context, RelativePathResolver
Instance Attribute Summary collapse
-
#prefixes ⇒ Object
Returns the value of attribute prefixes.
-
#relative_path_resolver ⇒ Object
Returns the value of attribute relative_path_resolver.
Instance Method Summary collapse
- #basic_render(options, &block) ⇒ Object
- #directory_name ⇒ Object
- #exist?(tname, options = {}) ⇒ Boolean
- #find_file(tname, prefixes, format, exact_format, directories) ⇒ Object
-
#initialize ⇒ Template
constructor
A new instance of Template.
- #parse_arguments(*args) ⇒ Object
- #paths ⇒ Object
- #read(tname, options = {}) ⇒ Object
- #render(*args, &block) ⇒ Object
Constructor Details
#initialize ⇒ Template
Returns a new instance of Template.
7 8 9 |
# File 'lib/rad/template/_template.rb', line 7 def initialize @relative_path_resolver = RelativePathResolver.new end |
Instance Attribute Details
#prefixes ⇒ Object
Returns the value of attribute prefixes.
4 5 6 |
# File 'lib/rad/template/_template.rb', line 4 def prefixes @prefixes end |
#relative_path_resolver ⇒ Object
Returns the value of attribute relative_path_resolver.
4 5 6 |
# File 'lib/rad/template/_template.rb', line 4 def relative_path_resolver @relative_path_resolver end |
Instance Method Details
#basic_render(options, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rad/template/_template.rb', line 25 def basic_render , &block with_context do |context| context.content_block ||= block with_scope , context do |scope| file = ( [:file] || find_template([:template], .merge(scope)) || ([:if_not_exist] && find_template([:if_not_exist], .merge(scope))) || raise("no template '#{[:template]}'!") ) scope[:current_dir] = dirname(file) template = create_tilt_template file result = with_template context, template do render_template template, context, , &context.content_block end return result, context end end end |
#directory_name ⇒ Object
80 |
# File 'lib/rad/template/_template.rb', line 80 def directory_name; "" end |
#exist?(tname, options = {}) ⇒ Boolean
16 17 18 |
# File 'lib/rad/template/_template.rb', line 16 def exist? tname, = {} !!find_template(tname, ) end |
#find_file(tname, prefixes, format, exact_format, directories) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rad/template/_template.rb', line 61 def find_file tname, prefixes, format, exact_format, directories prefixes = prefixes || self.prefixes prefixes.each do |prefix| tname = template_name_with_prefix("#{directory_name}#{tname}", prefix) file = if tname.include? '.' _find_file(tname, directories) || _find_file("#{tname}.*", directories) else if format _find_file("#{tname}.#{format}.*", directories) or _find_file("#{tname}.*", directories, exact_format) else _find_file("#{tname}.*", directories) end end return file if file end return nil end |
#parse_arguments(*args) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rad/template/_template.rb', line 50 def parse_arguments *args = args. if args.size == 1 [:template] = args.first else raise "Invalid input" if args.size != 0 end end |
#paths ⇒ Object
82 |
# File 'lib/rad/template/_template.rb', line 82 def paths; @paths ||= [] end |
#read(tname, options = {}) ⇒ Object
20 21 22 23 |
# File 'lib/rad/template/_template.rb', line 20 def read tname, = {} file = find_template(tname, ) || raise("no template '#{tname}'!") File.read file end |
#render(*args, &block) ⇒ Object
11 12 13 14 |
# File 'lib/rad/template/_template.rb', line 11 def render *args, &block result, context = basic_render(parse_arguments(*args), &block) result end |