Sha256: a7efd3a998268f28592f90dd185c728b3209a44631765dd05645c4e521566f13

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

LAYOUT = <<-HTML
<!DOCTYPE html>
<html>
<head><%= javascript_include_tag "application" %></head>
<body><%= yield %></body>
</html>
HTML

INDEX = <<-HTML
<script type="text/ruby">
puts 'hello from a script tag!'
</script>
HTML

WITH_ASSIGNMENTS = File.read "#{__dir__}/assets/javascripts/with_assignments.js.rb"

require_relative '../../app/helpers/opal_helper'

class ApplicationController < ActionController::Base
  include Rails.application.routes.url_helpers
  helper OpalHelper
  layout 'application'
  self.view_paths = [ActionView::FixtureResolver.new(
    'layouts/application.html.erb'         => LAYOUT,
    'application/index.html.erb'           => INDEX,
    'application/with_assignments.js.opal' => WITH_ASSIGNMENTS,
  )]

  def index
  end

  def with_assignments
    object = Object.new
    def object.as_json options = {}
      {contents: 'json representation'}
    end

    @number_var = 1234
    @string_var = 'hello'
    @array_var  = [1,'a']
    @hash_var   = {a: 1, b: 2}
    @object_var = object

    render type: :js, locals: { local_var: 'i am local' }
  end
end

Rails.logger = Logger.new(STDOUT) if $DEBUG

require 'opal/sprockets/version'
p rails: Rails.version, opal: Opal::VERSION, ruby: RUBY_VERSION, opal_sprockets: Opal::Sprockets::VERSION

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
opal-rails-2.0.2 test_apps/app/application_controller.rb
opal-rails-2.0.1 test_apps/app/application_controller.rb
opal-rails-2.0.0 test_apps/app/application_controller.rb