Sha256: 51a587e034e0f5360edb34521bcd4b42762d062a8b9e4931482a3729cc97f614

Contents?: true

Size: 672 Bytes

Versions: 2

Compression:

Stored size: 672 Bytes

Contents

# Example usage:
#
#   sinatra.rb:
#
#     require 'ruby2js/sinatra'
#     get '/test.js' do
#       ruby2js :test
#     end
#
#   views/test.rb:
#
#     alert 'Hello World!'
#
# Using an optional filter:
#
#   require 'ruby2js/filter/functions'

require 'sinatra'
require 'ruby2js'

class Ruby2JSTemplate < Tilt::Template
  self.default_mime_type = 'application/javascript'

  def prepare
  end

  def evaluate(scope, locals, &block)
    @output ||= Ruby2JS.convert(data)
  end

  def allows_script?
    false
  end
end

Tilt.register 'rb', Ruby2JSTemplate

helpers do
  def ruby2js(*args)
    content_type 'application/javascript'
    render('rb', *args).to_s
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby2js-5.0.1 lib/ruby2js/sinatra.rb
ruby2js-5.0.0 lib/ruby2js/sinatra.rb