Sha256: 0a6d2681be4352cf8f44ed9663bc24d7d7cbc579be114f5f11e28faa0ffee888

Contents?: true

Size: 1.16 KB

Versions: 6

Compression:

Stored size: 1.16 KB

Contents

require 'sinatra/base'
require 'active_support'
require 'sinatra_more'
require 'haml'

class MarkupDemo < Sinatra::Base
  register SinatraMore::MarkupPlugin

  configure do
    set :root, File.dirname(__FILE__)
  end
  
  get '/:engine/:file' do
    show(params[:engine], params[:file].to_sym)
  end

  helpers do
    # show :erb, :index
    # show :haml, :index
    def show(kind, template)
      eval("#{kind.to_s} #{template.to_sym.inspect}")
    end
    
    def captured_content(&block)
      content_html = capture_html(&block)
      "<p>#{content_html}</p>"
    end
    
    def concat_in_p(content_html)
      concat_content "<p>#{content_html}</p>"
    end
    
    def ruby_not_template_block
      determine_block_is_template('ruby') do
        content_tag(:span, "This not a template block")
      end
    end
    
    def determine_block_is_template(name, &block)
      if block_given?
        concat_content "<p class='is_template'>The #{name} block passed in is a template</p>" if block_is_template?(block)
      else
        concat_content "<p class='is_template'>The #{name} block passed in is a template</p>" if block_is_template?(block)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sinatra_more-0.1.5 test/fixtures/markup_app/app.rb
sinatra_more-0.1.4 test/fixtures/markup_app/app.rb
sinatra_more-0.1.3 test/fixtures/markup_app/app.rb
sinatra_more-0.1.2 test/fixtures/markup_app/app.rb
sinatra_more-0.1.1 test/fixtures/markup_app/app.rb
sinatra_more-0.1.0 test/fixtures/markup_app/app.rb