Class: Siru::Theme
- Inherits:
-
Object
- Object
- Siru::Theme
- Defined in:
- lib/siru/theme.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #has_layout?(layout_name) ⇒ Boolean
-
#initialize(name) ⇒ Theme
constructor
A new instance of Theme.
- #layout_path(layout_name) ⇒ Object
- #render_layout(layout_name, variables = {}) ⇒ Object
- #static_files ⇒ Object
Constructor Details
#initialize(name) ⇒ Theme
Returns a new instance of Theme.
5 6 7 8 |
# File 'lib/siru/theme.rb', line 5 def initialize(name) @name = name @path = find_theme_path(name) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/siru/theme.rb', line 3 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/siru/theme.rb', line 3 def path @path end |
Instance Method Details
#has_layout?(layout_name) ⇒ Boolean
20 21 22 |
# File 'lib/siru/theme.rb', line 20 def has_layout?(layout_name) !layout_path(layout_name).nil? end |
#layout_path(layout_name) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/siru/theme.rb', line 10 def layout_path(layout_name) if File.exist?(File.join(@path, 'layouts', "#{layout_name}.liquid")) File.join(@path, 'layouts', "#{layout_name}.liquid") else # Fall back to built-in theme builtin_path = File.join(__dir__, '..', '..', 'themes', @name, 'layouts', "#{layout_name}.liquid") File.exist?(builtin_path) ? builtin_path : nil end end |
#render_layout(layout_name, variables = {}) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/siru/theme.rb', line 24 def render_layout(layout_name, variables = {}) path = layout_path(layout_name) return '' unless path template = Liquid::Template.parse(File.read(path)) template.render(variables) end |
#static_files ⇒ Object
32 33 34 35 36 37 |
# File 'lib/siru/theme.rb', line 32 def static_files static_path = File.join(@path, 'static') return [] unless Dir.exist?(static_path) Dir.glob(File.join(static_path, '**', '*')).select { |f| File.file?(f) } end |