Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 193
- Log:
First stage commit of Typo 4.1, modified for the ROOL site.
Includes all local modifications but a final pass needs to be
made to delete any files left over from earlier Typo versions
that shouldn't be here anymore. See the 'tags' section of the
repository for a clean Typo 4.1 tree.Note that symlinks to shared files in the RISC OS Open theme
directory have been deliberately included this time around; I
decided that on balance it was better to leave them in as
placeholders, since unlike symlinks in app/views/shared, the
Typo theme structure is not a standard Rails concept.
- Author:
- rool
- Date:
- Wed Apr 04 18:51:02 +0100 2007
- Size:
- 4405 Bytes
1 | require File.dirname(__FILE__) + '/engine' |
2 | require 'rubygems' |
3 | require 'active_support' |
4 | require 'action_view' |
5 | |
6 | module Haml |
7 | # This class interfaces with ActionView |
8 | # to make Haml usable as a Ruby on Rails plugin. |
9 | # It usually shouldn't need to be used by end users. |
10 | # Just in case, though, here's what you might do to render |
11 | # <tt>templates/index.haml</tt>: |
12 | # |
13 | # ActionView::Base.register_template_handler("haml", Haml::Template) |
14 | # base = ActionView::Base.new("templates") |
15 | # base.render("index") |
16 | # |
17 | # Or, if you want to really get into the nitty-gritty: |
18 | # |
19 | # base = ActionView::Base.new |
20 | # template = Haml::Template.new(base) |
21 | # template.render("templates/index.haml") |
22 | # |
23 | class Template |
24 | |
25 | class << self |
26 | @@options = {} |
27 | |
28 | # Gets various options for HAML. See REFERENCE for details. |
29 | def options |
30 | @@options |
31 | end |
32 | |
33 | # Sets various options for HAML. See REFERENCE for details. |
34 | def options=(value) |
35 | @@options = value |
36 | end |
37 | end |
38 | |
39 | # Creates a new Haml::Template object that uses <tt>view</tt> |
40 | # to render its templates. |
41 | def initialize(view) |
42 | @view = view |
43 | @@precompiled_templates ||= {} |
44 | end |
45 | |
46 | # Renders the file at the location <tt>template</tt>, |
47 | # with <tt>local_assigns</tt> available as local variables within the template. |
48 | # Returns the result as a string. |
49 | def render(template, local_assigns={}) |
50 | unless @view.instance_variable_get("@assigns_added") |
51 | assigns = @view.assigns.dup |
52 | |
53 | # Get inside the view object's world |
54 | @view.instance_eval do |
55 | # Set all the instance variables |
56 | assigns.each do |key,val| |
57 | instance_variable_set "@#{key}", val |
58 | end |
59 | end |
60 | |
61 | @view.instance_variable_set("@assigns_added", true) |
62 | end |
63 | |
64 | options = @@options.dup |
65 | locals = options[:locals] || {} |
66 | locals.merge! local_assigns |
67 | options[:locals] = locals |
68 | |
69 | if @view.haml_inline |
70 | engine = Haml::Engine.new(template, options) |
71 | elsif @precompiled = get_precompiled(template) |
72 | options[:precompiled] ||= @precompiled |
73 | engine = Haml::Engine.new("", options) |
74 | else |
75 | engine = Haml::Engine.new(File.read(template), options) |
76 | set_precompiled(template, engine.precompiled) |
77 | end |
78 | |
79 | yield_proc = @view.instance_eval do |
80 | proc { |*name| instance_variable_get("@content_for_#{name.first || 'layout'}") } |
81 | end |
82 | |
83 | engine.to_html(@view) { |*args| yield_proc.call(*args) } |
84 | |
85 | end |
86 | |
87 | private |
88 | |
89 | # Gets the cached, precompiled version of the template at location <tt>filename</tt> |
90 | # as a string. |
91 | def get_precompiled(filename) |
92 | # Do we have it on file? Is it new enough? |
93 | if (precompiled, precompiled_on = @@precompiled_templates[filename]) && |
94 | (precompiled_on == File.mtime(filename).to_i) |
95 | precompiled |
96 | end |
97 | end |
98 | |
99 | # Sets the cached, precompiled version of the template at location <tt>filename</tt> |
100 | # to <tt>precompiled</tt>. |
101 | def set_precompiled(filename, precompiled) |
102 | @@precompiled_templates[filename] = [precompiled, File.mtime(filename).to_i] |
103 | end |
104 | end |
105 | end |
106 | |
107 | # This module refers to the ActionView module that's part of Ruby on Rails. |
108 | # Haml can be used as an alternate templating engine for it, |
109 | # and includes several modifications to make it more Haml-friendly. |
110 | # The documentation can be found |
111 | # here[http://rubyonrails.org/api/classes/ActionView/Base.html]. |
112 | module ActionView |
113 | class Base # :nodoc: |
114 | attr :haml_filename, true |
115 | attr :haml_inline |
116 | |
117 | alias_method :haml_old_render_file, :render_file |
118 | def render_file(template_path, use_full_path = true, local_assigns = {}) |
119 | @haml_filename = File.basename(template_path) |
120 | haml_old_render_file(template_path, use_full_path, local_assigns) |
121 | end |
122 | |
123 | alias_method :read_template_file_old, :read_template_file |
124 | def read_template_file(template_path, extension) |
125 | if extension =~ /haml/i |
126 | template_path |
127 | else |
128 | read_template_file_old(template_path, extension) |
129 | end |
130 | end |
131 | |
132 | alias_method :render_template_old, :render_template |
133 | def render_template(template_extension, template, file_path = nil, local_assigns = {}) |
134 | @haml_inline = !template.nil? |
135 | render_template_old(template_extension, template, file_path, local_assigns) |
136 | end |
137 | end |
138 | end |