Module: Sinatra::DynamicMatic

Defined in:
lib/sinatra/dynamicmatic.rb,
lib/sinatra/dynamicmatic/middleware.rb

Defined Under Namespace

Classes: Middleware

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sinatra/dynamicmatic.rb', line 7

def self.registered(app)
  app.set :lock, true
  app.set :public, Proc.new {app.root && File.join(app.root, 'site')}

  # If we're in development, don't serve the StaticMatic files statically.
  # Instead, render them dynamically, as with `staticmatic preview`.
  app.use Middleware if app.environment == :development

  configuration = StaticMatic::Configuration.new

  config_file = "#{app.root}/src/configuration.rb"

  if File.exists?(config_file)
    config = File.read(config_file)
    eval(config)
  end

  staticmatic = StaticMatic::Base.new(app.root, configuration)
  app.set :_staticmatic, staticmatic

  Dir[File.join(app._staticmatic.src_dir, "layouts", "*.haml")].each do |layout|
    name = layout[/([^\/]*)\.haml$/, 1].to_sym
    haml = File.read(layout)
    app.template(name) {haml}
    app.layout {haml} if name == :application
  end

  before do
    @staticmatic = staticmatic
    staticmatic.instance_variable_set('@current_page', request.path_info)
  end
end

Instance Method Details

#staticmaticObject



40
41
42
# File 'lib/sinatra/dynamicmatic.rb', line 40

def staticmatic
  _staticmatic
end