Class: Flatrack

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::Autoload
Defined in:
lib/flatrack.rb,
lib/flatrack/cli.rb,
lib/flatrack/site.rb,
lib/flatrack/view.rb,
lib/flatrack/request.rb,
lib/flatrack/version.rb,
lib/flatrack/response.rb,
lib/flatrack/template.rb,
lib/flatrack/template/rb.rb,
lib/flatrack/template/html.rb,
lib/flatrack/template/erubis.rb,
lib/flatrack/view/tag_helper.rb,
lib/flatrack/asset_extensions.rb,
lib/flatrack/view/link_helper.rb,
lib/flatrack/view/output_buffer.rb,
lib/flatrack/view/render_helper.rb,
lib/flatrack/view/capture_helper.rb,
lib/flatrack/view/request_helper.rb,
lib/flatrack/template/erubis/handler.rb

Overview

Version

Defined Under Namespace

Modules: AssetExtensions, Site Classes: CLI, Request, Response, Template, View

Constant Summary collapse

TemplateNotFound =
Class.new StandardError
FileNotFound =
Class.new StandardError
FORMATS =
{}
VERSION =
'1.3.1'

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.gem_rootString (readonly)

The root of the flatrack gem

Returns:

  • (String)


34
35
36
# File 'lib/flatrack.rb', line 34

def gem_root
  File.expand_path File.join __FILE__, '..'
end

.site_rootString (readonly)

The site root

Returns:

  • (String)


41
42
43
# File 'lib/flatrack.rb', line 41

def site_root
  File.expand_path Dir.pwd
end

Instance Attribute Details

#assetsSprockets::Environment (readonly)

The flatrack sprockets environment

Returns:

  • (Sprockets::Environment)


72
73
74
75
76
77
78
79
80
81
# File 'lib/flatrack.rb', line 72

def assets
  @assets ||= begin
    Sprockets::Environment.new.tap do |environment|
      environment.append_path 'assets/images'
      environment.append_path 'assets/javascripts'
      environment.append_path 'assets/stylesheets'
      environment.context_class.class_eval { include AssetExtensions }
    end
  end
end

Class Method Details

.reset!Object

Reset the state of flatrack and its configuration



46
47
48
# File 'lib/flatrack.rb', line 46

def reset!
  @delegate_instance = nil
end

Instance Method Details

#config {|Flatrack| ... } ⇒ Flatrack

Configure the flatrack instance

Yields:

  • (Flatrack)

    configuration for the flatrack instance

Returns:



64
65
66
67
# File 'lib/flatrack.rb', line 64

def config(&block)
  yield self
  self
end

#middlewareObject

The middleware stack for flatrack



91
92
93
# File 'lib/flatrack.rb', line 91

def middleware
  @middleware ||= []
end

#register_format(ext, mime) ⇒ Object

register a format extension by its mime type

Parameters:

  • ext (String)

    the extension

  • mime (String)

    the mime type



86
87
88
# File 'lib/flatrack.rb', line 86

def register_format(ext, mime)
  FORMATS[ext.to_s] = mime
end

#use(middleware, options = nil) ⇒ Object

Insert a rack middleware at the end of the stack

Parameters:

  • middleware (Class)

    the middleware class

  • options (Hash) (defaults to: nil)

    the options for the middleware



98
99
100
# File 'lib/flatrack.rb', line 98

def use(middleware, options = nil)
  self.middleware << [middleware, options].compact
end