Module: Rad::Template
- Defined in:
- lib/rad/template/template.rb
Constant Summary collapse
- DIRECTORY_NAME =
DIRECTORY_NAME = “/views”
""
Class Method Summary collapse
- .basic_render(options, &block) ⇒ Object
- .exist?(tname, options = {}) ⇒ Boolean
- .parse_arguments(*args) ⇒ Object
- .paths ⇒ Object
- .read(tname, options = {}) ⇒ Object
- .render(*args, &block) ⇒ Object
-
.render_layout(*args) ⇒ Object
def render_and_return_context *args, &block basic_render(*parse_arguments(*args), &block) end.
- .template_name_with_prefix(tname, prefix) ⇒ Object
Class Method Details
.basic_render(options, &block) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rad/template/template.rb', line 72 def basic_render , &block = .clone.to_openobject with_context do |context| context.content_block ||= block with_scope , context do |scope| unless file = .file file = find_template .template!, calculate_prefixes(), scope.format, exact_format?(), scope.current_dir raise "No template '#{.template!}'!" unless file end scope.current_dir = dirname(file) template = create_tilt_template file result = with_template context, template do render_template template, , &context.content_block end return result, context end end end |
.exist?(tname, options = {}) ⇒ Boolean
42 43 44 45 |
# File 'lib/rad/template/template.rb', line 42 def exist? tname, = {} = .to_openobject !!find_template(tname, calculate_prefixes(), .format, exact_format?(), .current_dir) end |
.parse_arguments(*args) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rad/template/template.rb', line 61 def parse_arguments *args = args..to_openobject if args.size == 1 .template = args.first else raise "Invalid input" if args.size != 0 end end |
.paths ⇒ Object
7 |
# File 'lib/rad/template/template.rb', line 7 def paths; @paths ||= [] end |
.read(tname, options = {}) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/rad/template/template.rb', line 47 def read tname, = {} = .to_openobject file = find_template tname, calculate_prefixes(), .format, exact_format?(), .current_dir raise "No template '#{tname}'!" unless file File.read file end |
.render(*args, &block) ⇒ Object
15 16 17 18 |
# File 'lib/rad/template/template.rb', line 15 def render *args, &block result, context = basic_render(parse_arguments(*args), &block) result end |
.render_layout(*args) ⇒ Object
def render_and_return_context *args, &block
basic_render(*parse_arguments(*args), &block)
end
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rad/template/template.rb', line 24 def render_layout *args = parse_arguments(*args) .must.include :content .must.include :context result, context = basic_render do |*args| if args.empty? .content else args.size.must_be == 1 variable_name = args.first.to_s self.context.content_variables[variable_name] end end result end |
.template_name_with_prefix(tname, prefix) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/rad/template/template.rb', line 54 def template_name_with_prefix tname, prefix index = tname.rindex('/') index = index ? index + 1 : 0 tname = tname.clone tname.insert index, prefix end |