| 1 |
|
| 2 |
|
| 3 |
class Mustache |
| 4 |
|
| 5 |
def initialize_settings |
| 6 |
@template = nil |
| 7 |
@template_path = nil |
| 8 |
@template_extension = nil |
| 9 |
@template_name = nil |
| 10 |
@template_file = nil |
| 11 |
@raise_on_context_miss = nil |
| 12 |
end |
| 13 |
|
| 14 |
def self.initialize_settings |
| 15 |
@template = nil |
| 16 |
@template_path = nil |
| 17 |
@template_extension = nil |
| 18 |
@template_name = nil |
| 19 |
@template_file = nil |
| 20 |
@raise_on_context_miss = nil |
| 21 |
end |
| 22 |
|
| 23 |
initialize_settings |
| 24 |
|
| 25 |
def self.inherited(subclass) |
| 26 |
subclass.initialize_settings |
| 27 |
end |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
def self.template_path |
| 40 |
@template_path ||= inheritable_config_for :template_path, '.' |
| 41 |
end |
| 42 |
|
| 43 |
def self.template_path=(path) |
| 44 |
@template_path = File.expand_path(path) |
| 45 |
@template = nil |
| 46 |
end |
| 47 |
|
| 48 |
def template_path |
| 49 |
@template_path ||= self.class.template_path |
| 50 |
end |
| 51 |
alias_method :path, :template_path |
| 52 |
|
| 53 |
def template_path=(path) |
| 54 |
@template_path = File.expand_path(path) |
| 55 |
@template = nil |
| 56 |
end |
| 57 |
|
| 58 |
|
| 59 |
def self.path |
| 60 |
template_path |
| 61 |
end |
| 62 |
|
| 63 |
|
| 64 |
def self.path=(path) |
| 65 |
self.template_path = path |
| 66 |
end |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
def self.template_extension |
| 76 |
@template_extension ||= inheritable_config_for :template_extension, 'mustache' |
| 77 |
end |
| 78 |
|
| 79 |
def self.template_extension=(template_extension) |
| 80 |
@template_extension = template_extension |
| 81 |
@template = nil |
| 82 |
end |
| 83 |
|
| 84 |
def template_extension |
| 85 |
@template_extension ||= self.class.template_extension |
| 86 |
end |
| 87 |
|
| 88 |
def template_extension=(template_extension) |
| 89 |
@template_extension = template_extension |
| 90 |
@template = nil |
| 91 |
end |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
def self.template_name |
| 109 |
@template_name || underscore |
| 110 |
end |
| 111 |
|
| 112 |
def self.template_name=(template_name) |
| 113 |
@template_name = template_name |
| 114 |
@template = nil |
| 115 |
end |
| 116 |
|
| 117 |
def template_name |
| 118 |
@template_name ||= self.class.template_name |
| 119 |
end |
| 120 |
|
| 121 |
def template_name=(template_name) |
| 122 |
@template_name = template_name |
| 123 |
@template = nil |
| 124 |
end |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
def self.template_file |
| 135 |
@template_file || "#{path}/#{template_name}.#{template_extension}" |
| 136 |
end |
| 137 |
|
| 138 |
def self.template_file=(template_file) |
| 139 |
@template_file = template_file |
| 140 |
@template = nil |
| 141 |
end |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
def template_file |
| 146 |
@template_file || "#{path}/#{template_name}.#{template_extension}" |
| 147 |
end |
| 148 |
|
| 149 |
def template_file=(template_file) |
| 150 |
@template_file = template_file |
| 151 |
@template = nil |
| 152 |
end |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
def self.template |
| 165 |
@template ||= templateify(File.read(template_file)) |
| 166 |
end |
| 167 |
|
| 168 |
def self.template=(template) |
| 169 |
@template = templateify(template) |
| 170 |
end |
| 171 |
|
| 172 |
|
| 173 |
def template |
| 174 |
return @template if @template |
| 175 |
|
| 176 |
|
| 177 |
if @template_path || @template_extension || @template_name || @template_file |
| 178 |
@template = templateify(File.read(template_file)) |
| 179 |
else |
| 180 |
@template = self.class.template |
| 181 |
end |
| 182 |
end |
| 183 |
|
| 184 |
def template=(template) |
| 185 |
@template = templateify(template) |
| 186 |
end |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
def self.raise_on_context_miss? |
| 201 |
@raise_on_context_miss |
| 202 |
end |
| 203 |
|
| 204 |
def self.raise_on_context_miss=(boolean) |
| 205 |
@raise_on_context_miss = boolean |
| 206 |
end |
| 207 |
|
| 208 |
|
| 209 |
def raise_on_context_miss? |
| 210 |
self.class.raise_on_context_miss? || @raise_on_context_miss |
| 211 |
end |
| 212 |
|
| 213 |
def raise_on_context_miss=(boolean) |
| 214 |
@raise_on_context_miss = boolean |
| 215 |
end |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
def self.view_namespace |
| 227 |
@view_namespace ||= inheritable_config_for(:view_namespace, Object) |
| 228 |
end |
| 229 |
|
| 230 |
def self.view_namespace=(namespace) |
| 231 |
@view_namespace = namespace |
| 232 |
end |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
def self.view_path |
| 243 |
@view_path ||= inheritable_config_for(:view_path, '.') |
| 244 |
end |
| 245 |
|
| 246 |
def self.view_path=(path) |
| 247 |
@view_path = path |
| 248 |
end |
| 249 |
end |