Class: Rayo::Config

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

Defined Under Namespace

Classes: Domain, Format

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rayo/config.rb', line 17

def initialize
  @languages = ['en']
  @page_exts = ['.yml']

  @formats = {}
  @domains = []

  @tagger = Object.new
  @tagger.extend Rayo::Taggable

  # Default tags
  add_tags Rayo::Tags::PropertyTags
  add_tags Rayo::Tags::ContentTags
  add_tags Rayo::Tags::NavigationTags

  # Default format
  @default_format = 'html'
end

Instance Attribute Details

#cache_dirObject

Returns the value of attribute cache_dir.



9
10
11
# File 'lib/rayo/config.rb', line 9

def cache_dir
  @cache_dir
end

#content_dirObject

Returns the value of attribute content_dir.



8
9
10
# File 'lib/rayo/config.rb', line 8

def content_dir
  @content_dir
end

#default_domainObject

Returns the value of attribute default_domain.



15
16
17
# File 'lib/rayo/config.rb', line 15

def default_domain
  @default_domain
end

#default_formatObject

Returns the value of attribute default_format.



14
15
16
# File 'lib/rayo/config.rb', line 14

def default_format
  @default_format
end

#languagesObject

Returns the value of attribute languages.



11
12
13
# File 'lib/rayo/config.rb', line 11

def languages
  @languages
end

#page_extsObject

Returns the value of attribute page_exts.



12
13
14
# File 'lib/rayo/config.rb', line 12

def page_exts
  @page_exts
end

Instance Method Details

#add_domain(name, exp = nil) ⇒ Object

Add domain

Parameters:

  • domain (String)

    name

  • host (Regexp, String)

    pattern



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

def add_domain( name, exp = nil )
  @domains << Rayo::Config::Domain.new( self, name, exp )
end

#add_filter(from, to = nil, &filter) ⇒ Object

Add filter

Parameters:

  • renderable (String, Symbol)

    file extension

  • requested (String, Symbol)

    content format

  • filter (Proc)

    proc which accepts source and return it in processed form



65
66
67
# File 'lib/rayo/config.rb', line 65

def add_filter( from, to = nil, &filter )
  format( to ).add_filter( from, &filter )
end

#add_tags(tag_module) ⇒ Object

Add tags defined in module

Parameters:

  • module (Module)

    defining tags to use



39
40
41
# File 'lib/rayo/config.rb', line 39

def add_tags( tag_module )
  @tagger.extend tag_module
end

#create_taggerObject

Create new object containing all defined tags



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

def create_tagger
  @tagger.clone
end

#directory(content_type) ⇒ Object



56
57
58
# File 'lib/rayo/config.rb', line 56

def directory( content_type )
  File.join( @content_dir, content_type.to_s )
end

#domain(host) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/rayo/config.rb', line 75

def domain( host )
  if @domains.empty?
    self # No multidomain support
  else
    @domains.find { |domain| domain.matches? host } || @domains.find { |domain| domain.name == @default_domain }
  end
end

#format(name = nil) ⇒ Object



69
70
71
72
73
# File 'lib/rayo/config.rb', line 69

def format( name = nil )
  name ||= default_format

  @formats[name.to_s] ||= Rayo::Config::Format.new name
end