Sha256: 8c13fac9487060acf1a5993582231e7ea6d81d5e510c46374375b49703d389de

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

require 'sequel'
require 'sqlite3'
require 'sprockets'
require 'ballonizer'

path_rake_to_app = 'examples/ballonizer_app/'

db_name = 'test.db'
db_path = "#{path_rake_to_app}#{db_name}"
db_uri = "sqlite://#{db_path}"

html_name = 'index.html'
html = File.read("#{path_rake_to_app}#{html_name}")

ballonizer = Ballonizer.new(db_uri, {
  create_tables_if_none: true,
  form_handler_url: '/request_handler',
  add_required_css: true,
  css_asset_path_for_link: '/assets',
  add_required_js_libs_for_edition: true,
  js_asset_path_for_link: '/assets'
})

app = Rack::Builder.new do
  map '/' do 
    run(lambda do | env |
      # the url is needed to make relative paths to images absolute
      request = Rack::Request.new(env)
      ballonized_page = ballonizer.ballonize_page(html, request.url)

      [200, {}, [ballonized_page]]
    end)
  end

  map '/assets' do
    run Ballonizer.assets_app
  end

  map '/request_handler' do
    run(lambda do | env |
      begin
        ballonizer.process_submit(env)
        [200, {}, ['your changes are made with success']]
      rescue Ballonizer::SubmitError => e
        [200, {}, [e.message]]
      end
    end)
  end
end

run app

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ballonizer-0.2.4 examples/ballonizer_app/config.ru
ballonizer-0.2.3 examples/ballonizer_app/config.ru
ballonizer-0.2.2 examples/ballonizer_app/config.ru