Module: Sinatra::Soxer
- Defined in:
- lib/soxer/main.rb
Overview
Soxer, the web publishing tool.
Soxer is a Sinatra module that adds additional methods to sinatra routes. These methods allow for route-to-yaml-file mapping in order to serve a set files from disk with minimal effort. By clever use of views and/or templating Soxer makes for a simple and effective web site creation tool. You can get more information about Soxer, including the latest version at soxer.mutsu.org
Author: Toni Anzlovar (toniformalibre.si) Copyright: Copyright © 1010 Toni Anzlovar, www.formalibre.si License: Distributed under the GPL licence. www.gnu.org/licenses/gpl.html
Defined Under Namespace
Modules: Helpers Classes: FileReader, UrlReader
Class Method Summary collapse
Class Method Details
.registered(app) ⇒ Object
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/soxer/main.rb', line 312 def self.registered(app) if app.settings.root then app.set :origin, File.join(app.settings.root, 'content') unless app.settings.respond_to? 'content' app.set :public, File.join(app.settings.root, 'public') unless app.settings.respond_to? 'public' app.set :views, File.join(app.settings.root, 'views') unless app.settings.respond_to? 'views' app.set :log, File.join(app.settings.root, 'log') unless app.settings.respond_to? 'log' end app.helpers Soxer::Helpers app.mime_type :otf, 'application/x-font-TrueType' app.mime_type :ttf, 'application/x-font-TrueType' app.mime_type :eot, 'application/vnd.ms-fontobject' app.get("/sitemap.xml") { sitemap } app.get %r{(.*\.([^.]*))$} do content_type "text/html", :charset => "utf-8" url = params[:captures][0] type = params[:captures][1] file = File.join app.settings.origin, url case type when 'yaml' then throw :halt, [404, "Document not found"] when /^jpg|png|pdf|doc|docx|xls|xlsx|pdf|ttf|otf$/i then send_file(file, :disposition => nil) if File.exist? file throw :halt, [404, "Document not found"]if !File.exist? file when /^css$/i then content_type "text/css", :charset => "utf-8" sass url.sub('.'+type, '').to_sym when 'atom' then content_type "application/atom+xml", :charset => "utf-8" page = get_page url layout = File.read File.join( File.dirname(__FILE__), 'views', 'atom_layout.haml' ) haml page['content'], :layout => layout, :format => :xhtml, :locals => { :page => page } when 'rss' then 'RSS is not supported yet' else throw :halt, [404, "Document not found"] end end app.get '*/?' do content_type "text/html", :charset => "utf-8" page = get_page page.layout ||= 'layout' page.layout == 'false' ? layout = false : layout = page.layout.to_sym haml page.content, :layout => layout, :locals => { :page => page } end end |