Class: Adocsite::Templates
- Inherits:
-
Object
- Object
- Adocsite::Templates
- Defined in:
- lib/adocsite/templates.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#images ⇒ Object
readonly
Returns the value of attribute images.
-
#includes ⇒ Object
readonly
Returns the value of attribute includes.
-
#layouts ⇒ Object
readonly
Returns the value of attribute layouts.
-
#literals ⇒ Object
readonly
Returns the value of attribute literals.
-
#partials ⇒ Object
readonly
Returns the value of attribute partials.
-
#scripts ⇒ Object
readonly
Returns the value of attribute scripts.
-
#styles ⇒ Object
readonly
Returns the value of attribute styles.
Instance Method Summary collapse
- #get_include(include_name) ⇒ Object
- #get_layout(layout_name = "default") ⇒ Object
- #get_literal(literal_name) ⇒ Object
- #get_partial(partial_name) ⇒ Object
-
#initialize ⇒ Templates
constructor
A new instance of Templates.
- #load_assets ⇒ Object
Constructor Details
#initialize ⇒ Templates
Returns a new instance of Templates.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/adocsite/templates.rb', line 4 def initialize = {:remove_whitespace => true} # files to copy @styles = Array.new @scripts = Array.new @images = Array.new @files = Array.new # theme template files # hashmap keys are template names without .haml extension and values are full paths # literal names are full file names (without path portion) and values are full paths @layouts = Hash.new @partials = Hash.new @includes = Hash.new @literals = Hash.new end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
3 4 5 |
# File 'lib/adocsite/templates.rb', line 3 def files @files end |
#images ⇒ Object (readonly)
Returns the value of attribute images.
3 4 5 |
# File 'lib/adocsite/templates.rb', line 3 def images @images end |
#includes ⇒ Object (readonly)
Returns the value of attribute includes.
3 4 5 |
# File 'lib/adocsite/templates.rb', line 3 def includes @includes end |
#layouts ⇒ Object (readonly)
Returns the value of attribute layouts.
3 4 5 |
# File 'lib/adocsite/templates.rb', line 3 def layouts @layouts end |
#literals ⇒ Object (readonly)
Returns the value of attribute literals.
3 4 5 |
# File 'lib/adocsite/templates.rb', line 3 def literals @literals end |
#partials ⇒ Object (readonly)
Returns the value of attribute partials.
3 4 5 |
# File 'lib/adocsite/templates.rb', line 3 def partials @partials end |
#scripts ⇒ Object (readonly)
Returns the value of attribute scripts.
3 4 5 |
# File 'lib/adocsite/templates.rb', line 3 def scripts @scripts end |
#styles ⇒ Object (readonly)
Returns the value of attribute styles.
3 4 5 |
# File 'lib/adocsite/templates.rb', line 3 def styles @styles end |
Instance Method Details
#get_include(include_name) ⇒ Object
69 70 71 72 73 |
# File 'lib/adocsite/templates.rb', line 69 def get_include(include_name) include_tpl = @includes[include_name] tpl = Tilt.new(include_tpl, ) return tpl end |
#get_layout(layout_name = "default") ⇒ Object
82 83 84 85 86 |
# File 'lib/adocsite/templates.rb', line 82 def get_layout(layout_name = "default") layout_tpl = @layouts[layout_name] tpl = Tilt.new(layout_tpl, ) return tpl end |
#get_literal(literal_name) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/adocsite/templates.rb', line 75 def get_literal(literal_name) literal_tpl = @literals[literal_name] # literals are not processed, they are literals tpl = File.read(literal_tpl) return tpl end |
#get_partial(partial_name) ⇒ Object
63 64 65 66 67 |
# File 'lib/adocsite/templates.rb', line 63 def get_partial(partial_name) partial_tpl = @partials[partial_name] tpl = Tilt.new(partial_tpl, ) return tpl end |
#load_assets ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/adocsite/templates.rb', line 25 def load_assets all_files = find_all_files templates = all_files.select {|path| path.end_with?(*Adocsite::config[:TEMPLATES])} @styles = all_files.select {|path| path.end_with?(*Adocsite::config[:STYLES])} @scripts = all_files.select {|path| path.end_with?(*Adocsite::config[:SCRIPTS])} @images = all_files.select {|path| path.end_with?(*Adocsite::config[:IMAGES])} @files = all_files - @images - @scripts - @styles - templates # loads layouts, partials, includes and literals into hashmaps. # hashmap keys are template names without .haml extension and values are full paths # literal names are full file names (without path portion) and values are full paths theme_location = File.join(Adocsite::config[:TEMPLATES_FOLDER], Adocsite::config[:THEME]) layouts = templates.select {|path| path.start_with?(File.join(theme_location, "layouts")) } layouts.each {|layout| layout_name = File.basename(layout, '.*') @layouts[layout_name] = layout } partials = templates.select {|path| path.start_with?(File.join(theme_location, "partials")) } partials.each {|partial| partial_name = File.basename(partial, '.*') @partials[partial_name] = partial } includes = templates.select {|path| path.start_with?(File.join(theme_location, "includes")) } includes.each {|include| include_name = File.basename(include, '.*') @includes[include_name] = include } literals = @files.select {|path| path.start_with?(File.join(theme_location, "literals")) } literals.each {|literal| literal_name = File.basename(literal) @literals[literal_name] = literal } @files = @files - literals all_files end |