Class: ActiveadminSelleoCms::Layout
- Inherits:
-
Object
- Object
- ActiveadminSelleoCms::Layout
- Defined in:
- app/models/activeadmin_selleo_cms/layout.rb
Defined Under Namespace
Classes: Section
Class Method Summary collapse
Instance Method Summary collapse
- #find_section(name) ⇒ Object
-
#initialize(path) ⇒ Layout
constructor
A new instance of Layout.
- #section_names ⇒ Object
- #sections ⇒ Object
Constructor Details
#initialize(path) ⇒ Layout
Returns a new instance of Layout.
5 6 7 8 9 |
# File 'app/models/activeadmin_selleo_cms/layout.rb', line 5 def initialize(path) @path = path @file = File.read(path) @doc = Nokogiri::HTML(@file) end |
Class Method Details
.all ⇒ Object
34 35 36 |
# File 'app/models/activeadmin_selleo_cms/layout.rb', line 34 def all Dir.glob(File.join(Rails.root, 'app/views/layouts/[a-z]*html.erb')).map{|l| l.split('/').last.split('.').first } end |
.find(name) ⇒ Object
26 27 28 29 30 31 32 |
# File 'app/models/activeadmin_selleo_cms/layout.rb', line 26 def find(name) begin Layout.new(Dir.glob(File.join(Rails.root, "app/views/layouts/#{name}.html.erb")).first) rescue nil end end |
Instance Method Details
#find_section(name) ⇒ Object
21 22 23 |
# File 'app/models/activeadmin_selleo_cms/layout.rb', line 21 def find_section(name) sections.detect{|section| section.name == name} end |
#section_names ⇒ Object
11 12 13 |
# File 'app/models/activeadmin_selleo_cms/layout.rb', line 11 def section_names @section_names ||= sections.map(&:name) end |
#sections ⇒ Object
15 16 17 18 19 |
# File 'app/models/activeadmin_selleo_cms/layout.rb', line 15 def sections @sections ||= @doc.css('section[name]').map do |node| Section.new(node) end end |