Class: Jzip::Engine::Template
- Inherits:
-
Struct
- Object
- Struct
- Jzip::Engine::Template
- Includes:
- Support::Notifier
- Defined in:
- lib/jzip/engine/template.rb
Constant Summary collapse
- @@instances =
{}
Instance Attribute Summary collapse
-
#source ⇒ Object
Returns the value of attribute source.
-
#target ⇒ Object
Returns the value of attribute target.
-
#target_file ⇒ Object
readonly
Returns the value of attribute target_file.
-
#template ⇒ Object
Returns the value of attribute template.
Class Method Summary collapse
Instance Method Summary collapse
- #code ⇒ Object
-
#initialize(*args) ⇒ Template
constructor
A new instance of Template.
- #outdated? ⇒ Boolean
- #parse ⇒ Object
- #partial? ⇒ Boolean
Methods included from Support::Notifier
Constructor Details
#initialize(*args) ⇒ Template
Returns a new instance of Template.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jzip/engine/template.rb', line 20 def initialize(*args) super @file_name = File.basename(self.template, ".jz") + ".js" @target_dir = File.dirname File.join(self.target, self.template.gsub(self.source, "")) if partial? @target_dir.gsub! Engine.root_dir, Engine.tmp_dir end @target_file = File.join @target_dir, @file_name scan_template end |
Instance Attribute Details
#source ⇒ Object
Returns the value of attribute source
5 6 7 |
# File 'lib/jzip/engine/template.rb', line 5 def source @source end |
#target ⇒ Object
Returns the value of attribute target
5 6 7 |
# File 'lib/jzip/engine/template.rb', line 5 def target @target end |
#target_file ⇒ Object (readonly)
Returns the value of attribute target_file.
10 11 12 |
# File 'lib/jzip/engine/template.rb', line 10 def target_file @target_file end |
#template ⇒ Object
Returns the value of attribute template
5 6 7 |
# File 'lib/jzip/engine/template.rb', line 5 def template @template end |
Class Method Details
.build(*args) ⇒ Object
16 17 18 |
# File 'lib/jzip/engine/template.rb', line 16 def self.build(*args) @@instances[args.first] ||= self.new(*args) end |
.clear_instances ⇒ Object
12 13 14 |
# File 'lib/jzip/engine/template.rb', line 12 def self.clear_instances @@instances.clear end |
Instance Method Details
#code ⇒ Object
53 54 55 |
# File 'lib/jzip/engine/template.rb', line 53 def code parse end |
#outdated? ⇒ Boolean
57 58 59 60 61 |
# File 'lib/jzip/engine/template.rb', line 57 def outdated? return true if missing? notify "Outdated '#{self.template}'" if result = File.mtime(@target_file) < File.mtime(self.template) result end |
#parse ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/jzip/engine/template.rb', line 33 def parse unless requires_parsing? notify "Skipping '#{self.template}'" else notify "Parsing '#{self.template}'" @code = @segments.collect do |segment| segment.is_a?(Requirement) ? segment.code : segment.join("") end. join("\n\n"). gsub(/^\s*$\n{2,}/, "\n"). strip.insert(0, "\n").insert(-1, "\n") write_file end @code ||= File.read(@target_file) end |
#partial? ⇒ Boolean
63 64 65 |
# File 'lib/jzip/engine/template.rb', line 63 def partial? !!@file_name.match(REG_EXPS[:partial]) end |