Class: Blogster::TemplatesParser

Inherits:
Object
  • Object
show all
Defined in:
lib/blogster/templates_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dirs) ⇒ TemplatesParser

Returns a new instance of TemplatesParser.



5
6
7
# File 'lib/blogster/templates_parser.rb', line 5

def initialize(dirs)
  @dirs = dirs
end

Instance Attribute Details

#dirsObject (readonly)

Returns the value of attribute dirs.



3
4
5
# File 'lib/blogster/templates_parser.rb', line 3

def dirs
  @dirs
end

Instance Method Details

#folder_files(dir) ⇒ Object



24
25
26
# File 'lib/blogster/templates_parser.rb', line 24

def folder_files(dir)
  Dir[File.join(dir, '*')]
end

#get_page_from_dir(dir) ⇒ Object



20
21
22
# File 'lib/blogster/templates_parser.rb', line 20

def get_page_from_dir(dir)
  dir.split('/').last.delete('_')
end

#parse_template_path(path) ⇒ Object



28
29
30
31
32
# File 'lib/blogster/templates_parser.rb', line 28

def parse_template_path(path)
  *template_path, name = path.split('/')
  template_path = File.join(*template_path)
  [template_path, name]
end

#to_templatesObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/blogster/templates_parser.rb', line 9

def to_templates
  dirs.each do |dir|
    page = get_page_from_dir(dir)
    templates[page] = folder_files(dir).map do |path|
      template_path, name = parse_template_path(path)
      new_template(template_path, name)
    end
  end
  templates
end