Class: Toto::Site
Defined Under Namespace
Classes: Context
Instance Method Summary collapse
- #/ ⇒ Object
- #article(route) ⇒ Object
- #go(route, type = :html) ⇒ Object
- #index(type = :html) ⇒ Object
-
#initialize(config) ⇒ Site
constructor
A new instance of Site.
- #is_root?(path) ⇒ Boolean
Methods included from PageHelpers
#archives, #articles, #import, #root, #title
Methods included from ConfigHelpers
Constructor Details
#initialize(config) ⇒ Site
Returns a new instance of Site.
100 101 102 |
# File 'lib/toto.rb', line 100 def initialize config @config = config end |
Instance Method Details
#/ ⇒ Object
118 119 120 |
# File 'lib/toto.rb', line 118 def / self[:root] end |
#article(route) ⇒ Object
114 115 116 |
# File 'lib/toto.rb', line 114 def article route Article.new("#{Paths[:articles]}/#{route}.#{self[:ext]}", @config).load end |
#go(route, type = :html) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/toto.rb', line 126 def go route, type = :html route << self./ if route.empty? type, path = type =~ /html|xml|json/ ? type.to_sym : :html, route.join('/') context = lambda do |data, page| Context.new(data, @config, path).render(page, type) end body, status = if Context.new.respond_to?(:"to_#{type}") if route.first =~ /\d{4}/ case route.size when 1..3 route.pop if route.last == 'archives' context[{:archives => archives(route * '/')}, :archives] when 4 context[article(route.last), :article] else http 400 end elsif is_root?(path) context[send(@config[:root], type), path.to_sym] elsif (repo = @config[:github][:repos].grep(/#{path}/).first) && !@config[:github][:user].empty? context[Repo.new(repo, @config), :repo] else context[{}, path.to_sym] end else http 400 end rescue Errno::ENOENT => e return :body => http(404).first, :type => :html, :status => 404 else return :body => body || "", :type => type, :status => status || 200 end |
#index(type = :html) ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'lib/toto.rb', line 104 def index type = :html case type when :html {:articles => articles, :archives => archives } when :xml, :json return :articles => articles else return {} end end |
#is_root?(path) ⇒ Boolean
122 123 124 |
# File 'lib/toto.rb', line 122 def is_root?(path) path == '/' end |