Module: Docks::Templates
- Defined in:
- lib/docks/templates.rb
Defined Under Namespace
Classes: Template
Class Method Summary collapse
- .<<(template) ⇒ Object
- .default ⇒ Object
- .default=(template) ⇒ Object
- .default_layout ⇒ Object
- .default_layout=(layout) ⇒ Object
- .demo ⇒ Object
- .demo=(template) ⇒ Object
- .fallback ⇒ Object
- .fallback=(template) ⇒ Object
- .last_template_update ⇒ Object
- .register(template, options = {}) ⇒ Object
- .search_for_template(template, options = {}) ⇒ Object
- .template_for(id) ⇒ Object
Class Method Details
.<<(template) ⇒ Object
44 45 46 |
# File 'lib/docks/templates.rb', line 44 def self.<<(template) register(template) end |
.default ⇒ Object
28 |
# File 'lib/docks/templates.rb', line 28 def self.default; @default_template end |
.default=(template) ⇒ Object
30 |
# File 'lib/docks/templates.rb', line 30 def self.default=(template); @default_template = Template.new(template) end |
.default_layout ⇒ Object
33 |
# File 'lib/docks/templates.rb', line 33 def self.default_layout; @default_layout end |
.default_layout=(layout) ⇒ Object
34 |
# File 'lib/docks/templates.rb', line 34 def self.default_layout=(layout); @default_layout = layout end |
.demo ⇒ Object
25 |
# File 'lib/docks/templates.rb', line 25 def self.demo; @demo_template end |
.demo=(template) ⇒ Object
26 |
# File 'lib/docks/templates.rb', line 26 def self.demo=(template); @demo_template = Template.new(template, layout: "demo") end |
.fallback ⇒ Object
29 |
# File 'lib/docks/templates.rb', line 29 def self.fallback; default end |
.fallback=(template) ⇒ Object
31 |
# File 'lib/docks/templates.rb', line 31 def self.fallback=(template); self.default = template end |
.last_template_update ⇒ Object
73 74 75 76 77 78 |
# File 'lib/docks/templates.rb', line 73 def self.last_template_update @last_modified ||= begin templates = Dir[Docks.config.templates + "**/*.*"] templates.map { |template| File.mtime(template) }.sort.last end end |
.register(template, options = {}) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/docks/templates.rb', line 36 def self.register(template, = {}) if template.kind_of?(Hash) register_from_hash(template) else @templates << Template.new(template, ) end end |
.search_for_template(template, options = {}) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/docks/templates.rb', line 58 def self.search_for_template(template, = {}) return unless template.kind_of?(String) || template.kind_of?(Pathname) return template if File.exists?(template) if [:must_be].nil? in_root = loose_search_for(template) return in_root unless in_root.nil? end in_specific = loose_search_for(File.join("#{([:must_be] || :partial).to_s.sub(/s$/, '')}{s,}", template)) return in_specific unless in_specific.nil? raise Docks::NoTemplateError, "No #{[:must_be] || "template"} matching '#{template}' was found. Make sure that you have a template by that name in the '#{[:must_be].nil? ? Docks.config.asset_folders.templates : [:must_be].to_s.pluralize}' folder of your pattern library's assets (or in a subdirectory of that folder), or provide a full path to the desired file." end |
.template_for(id) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/docks/templates.rb', line 48 def self.template_for(id) id = id.name if id.kind_of?(Containers::Pattern) @templates.reverse_each do |template| return template if template.matches?(id) end fallback end |