Sha256: 2f996247777393c5c60575bfa4cb91c8f838ad940a38c3138ff9d4e9114fe55f

Contents?: true

Size: 1.04 KB

Versions: 7

Compression:

Stored size: 1.04 KB

Contents

# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use Opal in this file: http://opalrb.org/
#
#
# Here's an example view class for your controller:
#
<% if namespaced? -%>
#= require opal
#= require <%= namespaced_file_path %>

<% end -%>
<% module_namespacing do -%>
class <%= controller_class_name %>View
  def initialize(selector = 'body.controller-<%= controller_class_name.underscore %>', parent = Element)
    @element = parent.find(selector)
    setup
  end
  attr_reader :element

  def setup
    # Put here the setup for the view behavior
    say_hello_when_a_link_is_clicked
  end

  def say_hello_when_a_link_is_clicked
    all_links.on :click do |event|
      # Use prevent_default to stop default behavior (as you would do in jQuery)
      # event.prevent_default

      puts "Hello! (You just clicked on a link: #{event.current_target.text})"
    end
  end


  private

  def all_links
    @all_links ||= element.find('a')
  end
end
<% end -%>

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
opal-rails-0.9.0 lib/rails/generators/opal/assets/templates/javascript.js.rb
opal-rails-0.8.1 lib/rails/generators/opal/assets/templates/javascript.js.rb
opal-rails-0.8.0 lib/rails/generators/opal/assets/templates/javascript.js.rb
opal-rails-0.8.0.rc1 lib/rails/generators/opal/assets/templates/javascript.js.rb
opal-rails-0.7.0 lib/rails/generators/opal/assets/templates/javascript.js.rb
opal-rails-0.7.0.beta2 lib/rails/generators/opal/assets/templates/javascript.js.rb
opal-rails-0.7.0.beta1 lib/rails/generators/opal/assets/templates/javascript.js.rb