Module: Pancake

Extended by:
Middleware
Defined in:
lib/pancake/logger.rb,
lib/pancake.rb,
lib/pancake/paths.rb,
lib/pancake/errors.rb,
lib/pancake/master.rb,
lib/pancake/router.rb,
lib/pancake/constants.rb,
lib/pancake/middleware.rb,
lib/pancake/mime_types.rb,
lib/pancake/mixins/url.rb,
lib/pancake/stack/stack.rb,
lib/pancake/stack/router.rb,
lib/pancake/test/helpers.rb,
lib/pancake/configuration.rb,
lib/pancake/mixins/render.rb,
lib/pancake/test/matchers.rb,
lib/pancake/mixins/publish.rb,
lib/pancake/hooks/on_inherit.rb,
lib/pancake/middlewares/logger.rb,
lib/pancake/middlewares/static.rb,
lib/pancake/mixins/stack_helper.rb,
lib/pancake/stack/configuration.rb,
lib/pancake/mixins/request_helper.rb,
lib/pancake/mixins/render/template.rb,
lib/pancake/mixins/response_helper.rb,
lib/pancake/mixins/render/view_context.rb,
lib/pancake/mixins/publish/action_options.rb,
lib/pancake/hooks/inheritable_inner_classes.rb

Overview

require “time” # httpdate

Public Pancake Logger API

To replace an existing logger with a new one:

Pancake::Logger.set_log(log{String, IO},level{Symbol, String})

Available logging levels are

Pancake::Logger::{ Fatal, Error, Warn, Info, Debug }

Logging via:

Pancake.logger.fatal(message<String>,&block)
Pancake.logger.error(message<String>,&block)
Pancake.logger.warn(message<String>,&block)
Pancake.logger.info(message<String>,&block)
Pancake.logger.debug(message<String>,&block)

Logging with autoflush:

Pancake.logger.fatal!(message<String>,&block)
Pancake.logger.error!(message<String>,&block)
Pancake.logger.warn!(message<String>,&block)
Pancake.logger.info!(message<String>,&block)
Pancake.logger.debug!(message<String>,&block)

Flush the buffer to

Pancake.logger.flush

Remove the current log object

Pancake.logger.close

Private Pancake Logger API

To initialize the logger you create a new object, proxies to set_log.

Pancake::Logger.new(log{String, IO},level{Symbol, String})

Defined Under Namespace

Modules: Constants, Errors, Hooks, Middleware, Middlewares, MimeTypes, Mixins, Paths, Test, Url Classes: Configuration, Logger, PancakeConfig, Router, Stack

Constant Summary collapse

OK_APP =

A simple rack application

lambda{|env| Rack::Response.new("OK",         200,  {"Content-Type" => "text/plain"}).finish}
MISSING_APP =
lambda{|env| Rack::Response.new("NOT FOUND",  404,  {"Content-Type" => "text/plain"}).finish}

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Middleware

build, extended, middlewares, stack, use

Class Attribute Details

._before_buildObject

Returns the value of attribute _before_build.



10
11
12
# File 'lib/pancake/master.rb', line 10

def _before_build
  @_before_build
end

._generatorsObject

Returns the value of attribute _generators.



10
11
12
# File 'lib/pancake/master.rb', line 10

def _generators
  @_generators
end

.rootObject

Returns the value of attribute root.



9
10
11
# File 'lib/pancake/master.rb', line 9

def root
  @root
end

Class Method Details

.base_url_for(app_name, opts = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pancake/router.rb', line 20

def self.base_url_for(app_name, opts={})
  config = Pancake.configuration.configs(app_name)
  the_router = if config && config.router
    config.router
  elsif app_name.respond_to?(:router)
    raise Pancake::Errors::UnknownRouter
  end
  the_router.respond_to?(:base_url) ?
    the_router.base_url(opts) :
    "/"
end

.before_build(&blk) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/pancake/master.rb', line 12

def before_build(&blk)
  unless _before_build
    self._before_build = []
  end
  _before_build << blk if blk
  _before_build
end

.configurationObject

Configuration



115
116
117
# File 'lib/pancake/configuration.rb', line 115

def self.configuration
  @configuration ||= PancakeConfig.new
end

.default_base_template(opts = {}) ⇒ Object

provides access to the default base template via the Pancake.master_templates object

See Also:



151
152
153
154
# File 'lib/pancake/master.rb', line 151

def default_base_template(opts = {})
  raise "Master Templates not set" unless master_templates
  master_templates.template(master_templates.base_template_name)
end

.default_error_handling!Object



106
107
108
# File 'lib/pancake/master.rb', line 106

def default_error_handling!
  @handle_errors = nil
end

.envString

Provides the environment for the currently running pancake

Returns:

  • (String)

    The currently running environment

Author:

  • Daniel Neighman



67
68
69
# File 'lib/pancake/master.rb', line 67

def env
  ENV['RACK_ENV'] ||= "development"
end

.generators(&blk) ⇒ Object



20
21
22
23
24
# File 'lib/pancake/master.rb', line 20

def generators(&blk)
  self._generators = [] unless _generators
  _generators << blk if blk
  _generators
end

.get_root(file, *args) ⇒ String

A helper method to get the expanded directory name of a __FILE__

Returns:

  • (String)

    an expanded version of file

Author:

  • Daniel Neighman



76
77
78
# File 'lib/pancake/master.rb', line 76

def get_root(file, *args)
  File.expand_path(File.join(File.dirname(file), *args))
end

.handle_errors!(*args) ⇒ Object



81
82
83
84
85
86
87
88
89
# File 'lib/pancake/master.rb', line 81

def handle_errors!(*args)
  @handle_errors = begin
    if args.size > 1
      args.flatten
    else
      args.first
    end
  end
end

.handle_errors?Boolean

Returns:

  • (Boolean)


91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/pancake/master.rb', line 91

def handle_errors?
  if @handle_errors.nil?
    !(Pancake.env == "development")
  else
    case @handle_errors
    when Array
      @handle_errors.include?(Pancake.env)
    when TrueClass, FalseClass
      @handle_errors
    when String
      Pancake.env == @handle_errors
    end
  end
end

.load_generators!Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pancake/master.rb', line 26

def load_generators!
  return if @load_generators
  @load_generators = true
  generators.each{|b| b.call}

  # load any global generator files
  highest = {}
  Gem.find_files("pancake/generators/global.rb").sort.reverse.each do |f|
    f =~ /gems\/([^\/]+?)-(\d\.[^\/]+?)\/lib\/pancake/
    highest[$1] ||= begin
      require f
      f
    end
  end
end

.loggerObject



110
111
112
# File 'lib/pancake/master.rb', line 110

def logger
  @logger ||= Pancake::Logger.new
end

.logger=(logr) ⇒ Object



114
115
116
# File 'lib/pancake/master.rb', line 114

def logger=(logr)
  @logger = logr
end

.master_stackObject

The stack to use as the master stack. Can be nil! The master stack is assumed to be the stack that is the controlling stack for the group of pancake stacks



121
122
123
# File 'lib/pancake/master.rb', line 121

def master_stack
  @master_stack
end

.master_stack=(stack) ⇒ Object

set the master stack. This also sets the master_templates as this stack if that hasn’t yet been set.

See Also:



128
129
130
131
# File 'lib/pancake/master.rb', line 128

def master_stack=(stack)
  self.master_templates ||= stack
  @master_stack = stack
end

.master_templatesObject

Used as the definitive source of shared templates for the whole pancake graph. Allows different stacks to share the same templates

See Also:



137
138
139
# File 'lib/pancake/master.rb', line 137

def master_templates
  @master_templates
end

.master_templates=(stack) ⇒ Object

Set the master templates to control the default templates for the stack

See Also:



144
145
146
# File 'lib/pancake/master.rb', line 144

def master_templates=(stack)
  @master_templates = stack
end

.reset_configurationObject



119
120
121
# File 'lib/pancake/configuration.rb', line 119

def self.reset_configuration
  @configuration = nil
end

.start(opts = {}, &block) ⇒ Object

Start Pancake. This provides a full pancake stack to use inside a rack application

Examples:

Starting a pancake stack

Pancake.start(:root => "/path/to/root"){ MyApp # App to use}

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :root (String)

    The root of the pancake stack

Author:

  • Daniel Neighman



52
53
54
55
56
57
58
59
60
# File 'lib/pancake/master.rb', line 52

def start(opts = {}, &block)
  self.root = opts[:root] || Dir.pwd

  # Build Pancake
  the_app = instance_eval(&block)
  before_build.each{|blk| blk.call}

  Pancake::Middleware.build(the_app, middlewares)
end

.url(app_name, name_or_opts, opts = {}) ⇒ Object

Generate a url for any pancake configuration that has a router

Examples:

Pancake.url(UserManamgent, :login) # => "/users/login"


8
9
10
11
12
13
14
15
16
17
18
# File 'lib/pancake/router.rb', line 8

def self.url(app_name, name_or_opts, opts = {})
  config = Pancake.configuration.configs(app_name)
  the_router = if config && config.router
    config.router
  elsif app_name.respond_to?(:router)
    app_name.router
  else
    raise Pancake::Errors::UnknownRouter
  end
  the_router.url(name_or_opts, opts)
end