class Aladdin::App

Sinatra app that serves the lesson preview. Should be able to use this in a config.ru file or as middleware. Authors should launch the app using the bin/aladdin executable.

Private Class Methods

configure_assets() click to toggle source

Configures path to static assets in the public folder. @return [void]

# File lib/aladdin/app.rb, line 33
def configure_assets
  set :public_folder, Aladdin::PATHS.public
  set :static_paths, Proc.new { Aladdin.config[:static_paths] }
end
configure_markdown() click to toggle source

Registers redcarpet2 and configures aladdin’s markdown renderer. @return [void]

# File lib/aladdin/app.rb, line 40
def configure_markdown
  Tilt.register Spirit::Tilt::Template, *%w(markdown mkd md)
  set :markdown, layout: :layout, layout_engine: :haml
  set :haml,     escape_html: true, format: :html5
end
configure_views() click to toggle source

Configures path to the views, with different paths for different file types. @return [void]

# File lib/aladdin/app.rb, line 21
def configure_views
  helpers do
    def find_template(views, name, engine, &block)
      _, dir = views.detect { |k,v| engine == Tilt[k] }
      dir ||= views[:default]
      super(dir, name, engine, &block)
    end
  end
end
find_template(views, name, engine, &block) click to toggle source
Calls superclass method
# File lib/aladdin/app.rb, line 23
def find_template(views, name, engine, &block)
  _, dir = views.detect { |k,v| engine == Tilt[k] }
  dir ||= views[:default]
  super(dir, name, engine, &block)
end

Public Instance Methods

render_or_pass() { || ... } click to toggle source

Calls the given block and invokes pass on error.

# File lib/aladdin/app.rb, line 49
def render_or_pass(&block)
  begin yield
  rescue Exception => e
    logger.error e.message
    pass
  end
end