Class: Brite::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/brite/config.rb

Overview

Configuration

Constant Summary collapse

CONFIG_FILE =

Configuration file name glob.

'{.brite,brite.yml,brite.yaml}'
DEFAULT_URL =

Default URL, which is just for testing purposes.

'http://0.0.0.0:3000'
DEFAULT_STENCIL =

Default stencil.

'erb'
DEFAULT_FORMAT =

Default format.

nil
DEFAULT_PAGE_LAYOUT =

Default page layout file name (less ‘.layout` extension).

'page'
DEFAULT_POST_LAYOUT =

Default post layout file name (less ‘.layout` extension).

'post'
DEFAULT_PAGE_ROUTE =

Default page route (‘:path`).

':path'
DEFAULT_POST_ROUTE =

Default post route (‘:path`).

':path'
DEFAULT_AUTHOR =

Default author for pages and posts.

'Anonymous'
DEFAULT_LAYOUT_PATH =

Default location of layouts.

['assets/layouts']
DEFAULT_PARTIAL_PATH =

Default location of partials.

['assets/partials']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location = nil) ⇒ Config

New instance of Config.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/brite/config.rb', line 82

def initialize(location=nil)
  @location     = location || Dir.pwd
  @file         = Dir.glob(File.join(@location, CONFIG_FILE)).first

  @url          = DEFAULT_URL
  @stencil      = DEFAULT_STENCIL
  @format       = DEFAULT_FORMAT

  @page_layout  = DEFAULT_PAGE_LAYOUT
  @post_layout  = DEFAULT_POST_LAYOUT

  @page_route   = DEFAULT_PAGE_ROUTE
  @post_route   = DEFAULT_POST_ROUTE

  @author       = DEFAULT_AUTHOR

  @layout_path  = DEFAULT_LAYOUT_PATH
  @partial_path = DEFAULT_PARTIAL_PATH

  @custom      = {}

  configure
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(s, v = nil, *a, &b) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/brite/config.rb', line 172

def method_missing(s, v=nil, *a, &b)
  s = s.to_s
  case s
  when /=$/
    @custom[s.chomp('=')] = v
  else
    if @custom.key?(s)
      @custom[s]
    else
      super(s.to_sym, v, *a, &b)
    end
  end
end

Instance Attribute Details

#authorObject

Default author.



73
74
75
# File 'lib/brite/config.rb', line 73

def author
  @author
end

#fileObject (readonly)

Configuration file.



47
48
49
# File 'lib/brite/config.rb', line 47

def file
  @file
end

#formatObject

Default section markup format.



58
59
60
# File 'lib/brite/config.rb', line 58

def format
  @format
end

#layout_pathObject

Paths to look for layouts.



76
77
78
# File 'lib/brite/config.rb', line 76

def layout_path
  @layout_path
end

#locationObject (readonly)

Location of brite project files. By necessity the configuration file will be located in this directory.



44
45
46
# File 'lib/brite/config.rb', line 44

def location
  @location
end

#page_layoutObject

Default page layout file name (less extension).



61
62
63
# File 'lib/brite/config.rb', line 61

def page_layout
  @page_layout
end

#page_routeObject

Default page route.



67
68
69
# File 'lib/brite/config.rb', line 67

def page_route
  @page_route
end

#partial_pathObject

Paths to look for layouts.



79
80
81
# File 'lib/brite/config.rb', line 79

def partial_path
  @partial_path
end

#post_layoutObject

Default post layout file name (less extension).



64
65
66
# File 'lib/brite/config.rb', line 64

def post_layout
  @post_layout
end

#post_routeObject

Default post route.



70
71
72
# File 'lib/brite/config.rb', line 70

def post_route
  @post_route
end

#stencilObject

Defaut section template engine.



55
56
57
# File 'lib/brite/config.rb', line 55

def stencil
  @stencil
end

#urlObject

Site’s absolute URL. Where possible links are relative, but it is not alwasy possible. So a URL should ALWAYS be provided for the site.



52
53
54
# File 'lib/brite/config.rb', line 52

def url
  @url
end

Instance Method Details

#configureObject

Load configuration file.



109
110
111
112
113
114
115
116
# File 'lib/brite/config.rb', line 109

def configure
  if file
    data = YAML.load(File.new(file))
    data.each do |k,v|
      __send__("#{k}=", v)
    end
  end
end

#pom=(set) ⇒ Object Also known as: gemdo=

TODO:

Will become GemDo in future ?

Provide access to POM.



158
159
160
161
162
163
164
165
166
# File 'lib/brite/config.rb', line 158

def pom=(set)
  return unless set
  require 'pom'
  Brite::Context.class_eval do
    def project
      @project ||= POM::Project.new
    end
  end
end