Class: Emmett::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/emmett/configuration.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#index_pageObject

Returns the value of attribute index_page.



9
10
11
# File 'lib/emmett/configuration.rb', line 9

def index_page
  @index_page
end

#json_pathObject

Returns the value of attribute json_path.



9
10
11
# File 'lib/emmett/configuration.rb', line 9

def json_path
  @json_path
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/emmett/configuration.rb', line 9

def name
  @name
end

#output_dirObject

Returns the value of attribute output_dir.



9
10
11
# File 'lib/emmett/configuration.rb', line 9

def output_dir
  @output_dir
end

#section_dirObject

Returns the value of attribute section_dir.



9
10
11
# File 'lib/emmett/configuration.rb', line 9

def section_dir
  @section_dir
end

#templateObject

Returns the value of attribute template.



9
10
11
# File 'lib/emmett/configuration.rb', line 9

def template
  @template
end

Instance Method Details

#from_jsonObject



32
33
34
# File 'lib/emmett/configuration.rb', line 32

def from_json
  @json_config ||= JSON.parse(File.read(json_path))
end

#to_templateObject



36
37
38
# File 'lib/emmett/configuration.rb', line 36

def to_template
  @template_instance ||= Template[template]
end

#verify!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/emmett/configuration.rb', line 11

def verify!
  errors = []
  if json_path && File.exist?(json_path)
    title = from_json['title']
    self.name = title if title
  else
    errors << "The json path does not exist (Given #{json_path.inspect})"
  end
  errors << "You must set the name attribute for emmett" if !name
  errors << "You must set the template attribute for emmett" if !template
  errors << "The index_page file must exist" unless index_page && File.exist?(index_page)
  errors << "The section_dir directory must exist" unless section_dir && File.directory?(section_dir)
  errors << "The output_dir must be set" unless output_dir
  errors << "The specified template does not exist" unless to_template
  if errors.any?
    message = "Your configuration is invalid:\n"
    errors.each { |e| message << "* #{e}\n" }
    raise Error.new(message)
  end
end