Class: Layout

Inherits:
Object
  • Object
show all
Defined in:
app/models/layout.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Layout

Returns a new instance of Layout.



29
30
31
# File 'app/models/layout.rb', line 29

def initialize(name)
  @name = name
end

Class Method Details

.allObject



2
3
4
5
6
7
# File 'app/models/layout.rb', line 2

def self.all
  files.map do |layout|
    layout = layout.split('/').last.gsub(file_extension, '')
    [layout.titleize, layout]
  end
end

.file_extensionObject



21
22
23
# File 'app/models/layout.rb', line 21

def self.file_extension
  '.html.erb'
end

.filesObject



9
10
11
12
13
14
15
16
17
18
19
# File 'app/models/layout.rb', line 9

def self.files
  files = []
  SlicesController.view_paths.each do |resolver|
    next if ignore_layout?(resolver.to_path)
    query = File.join(resolver, 'layouts', "*#{file_extension}")
    files.concat(Dir.glob(query))
  end
  files.reject do |file|
    file.include?('admin.html.erb')
  end.uniq.sort
end

.ignore_layout?(layout) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'app/models/layout.rb', line 25

def self.ignore_layout?(layout)
  layout.include?(Slices.gem_path) && Rails.root.to_s != Slices.gem_path
end

Instance Method Details

#containersObject



39
40
41
42
# File 'app/models/layout.rb', line 39

def containers
  parser = Slices::ContainerParser.new(path)
  parser.parse
end

#pathObject



33
34
35
36
37
# File 'app/models/layout.rb', line 33

def path
  self.class.files.select do |path|
    path.split('/').last == @name + self.class.file_extension
  end.first
end