├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── Gemfile ├── LICENSE ├── README.md ├── Rakefile ├── features ├── pluggable_js.feature ├── step_definitions │ └── pluggable_js_steps.rb └── support │ └── env.rb ├── lib ├── pluggable_js.rb └── pluggable_js │ ├── config.rb │ ├── helpers.rb │ ├── railtie.rb │ └── version.rb ├── pluggable_js.gemspec └── test └── dummy ├── README.rdoc ├── Rakefile ├── app ├── assets │ ├── images │ │ └── .keep │ ├── javascripts │ │ ├── application.js │ │ └── posts.js.coffee │ └── stylesheets │ │ └── application.css ├── controllers │ ├── application_controller.rb │ ├── concerns │ │ └── .keep │ └── pluggable_js │ │ └── posts_controller.rb ├── helpers │ └── application_helper.rb ├── mailers │ └── .keep ├── models │ ├── .keep │ └── concerns │ │ └── .keep └── views │ ├── layouts │ └── application.html.erb │ └── pluggable_js │ └── posts │ ├── index.html.erb │ └── new.html.erb ├── bin ├── bundle ├── rails └── rake ├── config.ru ├── config ├── application.rb ├── boot.rb ├── environment.rb ├── environments │ ├── development.rb │ ├── production.rb │ └── test.rb ├── initializers │ ├── backtrace_silencers.rb │ ├── filter_parameter_logging.rb │ ├── inflections.rb │ ├── mime_types.rb │ ├── pluggable_js.rb │ ├── secret_token.rb │ ├── session_store.rb │ └── wrap_parameters.rb ├── locales │ └── en.yml └── routes.rb ├── lib └── assets │ └── .keep └── public ├── 404.html ├── 422.html ├── 500.html └── favicon.ico /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.gem 3 | *.rbc 4 | .bundle 5 | .config 6 | .yardoc 7 | .ruby-gemset 8 | .ruby-version 9 | Gemfile.lock 10 | InstalledFiles 11 | _yardoc 12 | coverage 13 | doc/ 14 | lib/bundler/man 15 | pkg 16 | rdoc 17 | spec/reports 18 | test/tmp 19 | test/dummy/tmp 20 | test/dummy/log 21 | test/version_tmp 22 | tmp -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | 3 | cache: bundler 4 | 5 | sudo: false 6 | 7 | rvm: 8 | - 2.3.0 9 | - 2.2 10 | - 2.1 11 | 12 | script: xvfb-run bundle exec cucumber 13 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## v0.0.1.rc 2 | 3 | * initial release 4 | 5 | ## v0.0.1.rc2 6 | 7 | * extended readme 8 | 9 | ## v0.0.1 10 | 11 | * added tests 12 | 13 | ## v0.0.2 14 | 15 | * edited dependencies 16 | 17 | ## v0.0.3 18 | 19 | * edited rails as >= 3.1 dependency 20 | 21 | ## v0.0.4 22 | 23 | * added necessary folders to gitignore for dummy app 24 | 25 | ## v0.0.5 26 | 27 | * improved function call, left generator only for large js files 28 | 29 | ## v0.0.6 30 | 31 | * fixed function call for IE 32 | 33 | ## v1.0.0 34 | 35 | * passing data to javascript functionality 36 | 37 | ## v1.0.1 38 | 39 | * array of hashes support 40 | 41 | ## v1.0.2 42 | 43 | * array conversion for js and pjs as alias method. 44 | 45 | ## v1.0.3 46 | 47 | * removed unnecessary conditions from pluggable_js controller helper 48 | 49 | ## v2.0.0 50 | 51 | * improved namespace and data passing 52 | 53 | ## v2.0.1 54 | 55 | * refactored helpers, improved readme 56 | 57 | ## v2.0.3 58 | 59 | * turbolinks related bugfix 60 | 61 | ## v2.0.4 62 | 63 | * nested resources related bugfix 64 | 65 | ## v2.1.0 66 | 67 | * removed jquery and coffee from core dependency 68 | * removed unused generator 69 | * simplified main helper 70 | 71 | ## v2.2.0 72 | 73 | * shared data helper between view and controller 74 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in pluggable_js.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Andrey Peresleguine 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PluggableJs 2 | 3 | [![Build Status](https://travis-ci.org/peresleguine/pluggable_js.svg?branch=master)](https://travis-ci.org/peresleguine/pluggable_js) [![Gem Version](https://badge.fury.io/rb/pluggable_js.svg)](http://badge.fury.io/rb/pluggable_js) 4 | 5 | This gem provides simple functionality of loading page specific javascript and allows to pass data from a controller. It requires only Rails >= 3.1 with asset pipeline enabled. Keep desired js code in controller related files as action based functions. They will be triggered only when matching controller and action parameters and when DOM is ready. 6 | 7 | ## Installation 8 | 9 | 1. Add `gem 'pluggable_js', '~> 2.2.0'` to Gemfile and run `bundle` command to install it 10 | 2. Add `<%= javascript_pluggable_tag %>` helper to application layout file above the closing `` tag 11 | 12 | The place for the helper is important. Primarily it serves the DOM ready purpose and completely necessary if you decided to use turbolinks. 13 | 14 | ## Usage 15 | 16 | Simply define functions in your controller related file (e.g. posts.coffee) like so: 17 | 18 | ```coffeescript 19 | @['posts#index'] = (data) -> 20 | # your code goes here 21 | @['posts#new'] = (data) -> 22 | # and here 23 | ``` 24 | 25 | You may pass data to javascript function using `pluggable_js` helper in rails controller (`pjs` is an alias method). See example below: 26 | 27 | ```ruby 28 | class PostsController < ApplicationController 29 | def index 30 | pluggable_js( 31 | string: 'string', 32 | integer: 1, 33 | boolean: true, 34 | array: [1, 2, 3], 35 | hash: { a: 1, b: 2, c: 3 }, 36 | array_of_hashes: [{a: 1}, {b: 2}, {c: 3}] 37 | ) 38 | end 39 | end 40 | ``` 41 | 42 | If you feel like this logic doesn't belong to a controller, safely move it to a view. Then you can access data in posts.coffee: 43 | 44 | ```coffeescript 45 | @['posts#index'] = (data) -> 46 | console.log data.string 47 | console.log data.integer 48 | console.log data.boolean 49 | console.log data.array 50 | console.log data.hash 51 | console.log data.array_of_hashes 52 | ``` 53 | 54 | CoffeeScript used here just for the sake of simplicity. You may implement the same with plain JavaScript. 55 | 56 | ## Config 57 | 58 | Let's say you've created action `search` that renders `index` template. Most likely we still need to trigger `@['posts#index'](data)` function. In such situation you may create `config/initializers/pluggable_js.rb` and use pair actions config: 59 | 60 | ```ruby 61 | PluggableJs.config do |config| 62 | config.pair_actions = { 'search' => 'index' } 63 | end 64 | ``` 65 | 66 | `{ 'create' => 'new', 'update' => 'edit' }` is a default REST configuration. 67 | 68 | ## Upgrade 69 | 70 | * [from <= v0.0.6 to v1.0.0](https://github.com/peresleguine/pluggable_js/wiki/Upgrade-from-v0.0.6-or-less-to-v1.0.0) 71 | * [from v1.0 to v2.0](https://github.com/peresleguine/pluggable_js/wiki/Upgrade-from-v1.0-to-v2.0) 72 | * [from v2.0 to v2.1](https://github.com/peresleguine/pluggable_js/wiki/Upgrade-from-v2.0-to-v2.1) 73 | 74 | ## Development notes 75 | 76 | To run the test suite: 77 | 78 | ``` 79 | bundle exec cucumber 80 | ``` 81 | 82 | ## Sublime Text Snippet 83 | 84 | Go to `Sublime Text > Preferences > Browse Packages...` and save under `User` directory `pjs.sublime-snippet` with the following content: 85 | 86 | ```xml 87 | 88 | 90 | $0 91 | ]]> 92 | pjs 93 | source.coffee 94 | 95 | ``` 96 | 97 | Thereafter `pjs` snippet will be available in coffeescript files. 98 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | -------------------------------------------------------------------------------- /features/pluggable_js.feature: -------------------------------------------------------------------------------- 1 | Feature: PluggableJs 2 | In order to use some page specific javascript and pass some data 3 | I want to visit different pages and see appropriate content 4 | 5 | @javascript 6 | Scenario Outline: Posts List 7 | When I go to posts '' 8 | Then I should see content with '' 9 | And I should not see 'You wanna piece of me, boy?' 10 | 11 | Examples: 12 | | action | data_type | 13 | | index | string | 14 | | search | integer | 15 | | index | boolean | 16 | | search | array | 17 | | index | hash | 18 | | search | array_of_hashes | 19 | 20 | @javascript 21 | Scenario: New Post 22 | When I go to new post 23 | Then I should see 'You wanna piece of me, boy?' 24 | And I should not see 'My life for aiur.' 25 | -------------------------------------------------------------------------------- /features/step_definitions/pluggable_js_steps.rb: -------------------------------------------------------------------------------- 1 | When(/^I go to posts 'index'$/) do 2 | visit pluggable_js_posts_path 3 | end 4 | 5 | When(/^I go to posts 'search'$/) do 6 | visit search_pluggable_js_posts_path 7 | end 8 | 9 | When(/^I go to new post$/) do 10 | visit new_pluggable_js_post_path 11 | end 12 | 13 | Then(/^I should see '(.*?)'$/) do |text| 14 | expect(page).to have_content(text) 15 | end 16 | 17 | And(/^I should not see '(.*?)'$/) do |text| 18 | expect(page).not_to have_content(text) 19 | end 20 | 21 | Then(/^I should see content with 'string'$/) do 22 | expect(page).to have_content('My life for aiur.') 23 | end 24 | 25 | Then(/^I should see content with 'integer'$/) do 26 | expect(page).to have_content('You have not enough minerals.') 27 | end 28 | 29 | Then(/^I should see content with 'boolean'$/) do 30 | expect(page).to have_content('Base is under attack.') 31 | end 32 | 33 | Then(/^I should see content with 'array'$/) do 34 | expect(page).to have_content('Nuclear launch detected.') 35 | end 36 | 37 | Then(/^I should see content with 'hash'$/) do 38 | expect(page).to have_content('Dragoon: Make use of me.') 39 | expect(page).to have_content('High Templar: It shall be done.') 40 | expect(page).to have_content('Archon: We burn...') 41 | end 42 | 43 | Then(/^I should see content with 'array_of_hashes'$/) do 44 | expect(page).to have_content('Scout: Awaiting command.') 45 | expect(page).to have_content('Arbiter: We feel your presence.') 46 | expect(page).to have_content('Carrier: Affirmative.') 47 | end 48 | -------------------------------------------------------------------------------- /features/support/env.rb: -------------------------------------------------------------------------------- 1 | require 'bundler' 2 | require 'coffee_script' 3 | 4 | begin 5 | Bundler.setup(:default, :development) 6 | rescue Bundler::BundlerError => e 7 | $stderr.puts e.message 8 | $stderr.puts "Run `bundle install` to install missing gems" 9 | exit e.status_code 10 | end 11 | 12 | $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib') 13 | require 'rspec/expectations' 14 | 15 | ENV["RAILS_ENV"] ||= "test" 16 | require File.expand_path("../../../test/dummy/config/environment.rb", __FILE__) 17 | ENV["RAILS_ROOT"] ||= File.dirname(__FILE__) + "../../../test/dummy" 18 | require 'cucumber/rails' 19 | 20 | require 'capybara-webkit' 21 | Capybara.javascript_driver = :webkit 22 | -------------------------------------------------------------------------------- /lib/pluggable_js.rb: -------------------------------------------------------------------------------- 1 | require 'pluggable_js/version' 2 | require 'pluggable_js/helpers' 3 | require 'pluggable_js/config' 4 | require 'pluggable_js/railtie' if defined?(Rails) 5 | 6 | module PluggableJs 7 | def self.config(&block) 8 | block.call(Config) 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/pluggable_js/config.rb: -------------------------------------------------------------------------------- 1 | module PluggableJs 2 | module Config 3 | DEFAULT_PAIR_ACTIONS = { 'create' => 'new', 'update' => 'edit' } 4 | 5 | class << self 6 | def pair_actions=(actions = {}) 7 | @pair_actions = DEFAULT_PAIR_ACTIONS.merge(actions) 8 | end 9 | 10 | def pair_actions 11 | @pair_actions ||= DEFAULT_PAIR_ACTIONS 12 | end 13 | end 14 | 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/pluggable_js/helpers.rb: -------------------------------------------------------------------------------- 1 | module PluggableJs 2 | module Helpers 3 | 4 | module Shared 5 | def pluggable_js(data) 6 | @pluggable_js_data = data.to_json 7 | end 8 | alias_method :pjs, :pluggable_js 9 | end 10 | 11 | module View 12 | include PluggableJs::Helpers::Shared 13 | 14 | def javascript_pluggable_tag 15 | controller = params[:controller] 16 | action = define_pair_action 17 | 18 | javascript_tag( 19 | "(function() { 20 | var pluggableFunction = window['#{controller}##{action}']; 21 | if (typeof(pluggableFunction) === 'function') { pluggableFunction(#{@pluggable_js_data}); } 22 | }).call();" 23 | ) 24 | end 25 | 26 | private 27 | 28 | def define_pair_action 29 | action = params[:action] 30 | if Config.pair_actions.has_key?(action) 31 | Config.pair_actions[action] 32 | else 33 | action 34 | end 35 | end 36 | 37 | end 38 | 39 | module Controller 40 | include PluggableJs::Helpers::Shared 41 | end 42 | 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /lib/pluggable_js/railtie.rb: -------------------------------------------------------------------------------- 1 | module PluggableJs 2 | class Railtie < Rails::Railtie 3 | initializer 'pluggable_js.helpers' do 4 | ActionView::Base.send :include, Helpers::View 5 | ActionController::Base.send :include, Helpers::Controller 6 | end 7 | end 8 | end -------------------------------------------------------------------------------- /lib/pluggable_js/version.rb: -------------------------------------------------------------------------------- 1 | module PluggableJs 2 | VERSION = '2.2.0' 3 | end 4 | -------------------------------------------------------------------------------- /pluggable_js.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'pluggable_js/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = 'pluggable_js' 8 | spec.version = PluggableJs::VERSION 9 | spec.authors = ['Andrey Peresleguine'] 10 | spec.email = ['peresleguine@gmail.com'] 11 | spec.description = %q{Page-specific javascript for Rails applications with the ability of passing data.} 12 | spec.summary = %q{Page-specific javascript for Rails.} 13 | spec.homepage = 'https://github.com/peresleguine/pluggable_js' 14 | spec.license = 'MIT' 15 | 16 | spec.files = `git ls-files`.split($/) 17 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 18 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 19 | spec.require_paths = ['lib'] 20 | 21 | spec.add_dependency 'rails', '>= 3.1' 22 | 23 | spec.add_development_dependency 'bundler', '~> 1.3' 24 | spec.add_development_dependency 'cucumber-rails', '~> 1.4.2' 25 | spec.add_development_dependency 'rspec-expectations', '~> 3.4.0' 26 | spec.add_development_dependency 'capybara-webkit', '~> 1.5.0' 27 | spec.add_development_dependency 'turbolinks', '~> 2.5.0' 28 | spec.add_development_dependency 'jquery-rails', '~> 4.0.0' 29 | spec.add_development_dependency 'coffee-rails', '~> 4.1.0' 30 | end 31 | -------------------------------------------------------------------------------- /test/dummy/README.rdoc: -------------------------------------------------------------------------------- 1 | == README 2 | 3 | This README would normally document whatever steps are necessary to get the 4 | application up and running. 5 | 6 | Things you may want to cover: 7 | 8 | * Ruby version 9 | 10 | * System dependencies 11 | 12 | * Configuration 13 | 14 | * Database creation 15 | 16 | * Database initialization 17 | 18 | * How to run the test suite 19 | 20 | * Services (job queues, cache servers, search engines, etc.) 21 | 22 | * Deployment instructions 23 | 24 | * ... 25 | 26 | 27 | Please feel free to use a different markup language if you do not plan to run 28 | rake doc:app. 29 | -------------------------------------------------------------------------------- /test/dummy/Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require File.expand_path('../config/application', __FILE__) 5 | 6 | Dummy::Application.load_tasks 7 | -------------------------------------------------------------------------------- /test/dummy/app/assets/images/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peresleguine/pluggable_js/93305bf355aebec39de681c059aa8eb941e856f4/test/dummy/app/assets/images/.keep -------------------------------------------------------------------------------- /test/dummy/app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // compiled file. 9 | // 10 | // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details 11 | // about supported directives. 12 | // 13 | //= require jquery 14 | //= require turbolinks 15 | //= require_directory 16 | -------------------------------------------------------------------------------- /test/dummy/app/assets/javascripts/posts.js.coffee: -------------------------------------------------------------------------------- 1 | @['pluggable_js/posts#index'] = (data) -> 2 | $('.protoss-quotes').append("

#{data.zealot_quote}

") 3 | $('.protoss-quotes').append('

You have not enough minerals.

' if data.minerals_size < 1000) 4 | $('.protoss-quotes').append('

Base is under attack.

') if data.base_is_under_attack 5 | $('.protoss-quotes').append("

#{data.alert.join(' ')}

") 6 | for key, value of data.ground_units_quotes 7 | $('.protoss-quotes').append("

#{key}: #{value}

") 8 | for unit in data.air_units_quotes 9 | for key, value of unit 10 | $('.protoss-quotes').append("

#{key}: #{value}

") 11 | 12 | @['pluggable_js/posts#new'] = (data) -> 13 | $('.terran-quotes').append("

#{data.marine_quote}

") 14 | -------------------------------------------------------------------------------- /test/dummy/app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the top of the 9 | * compiled file, but it's generally better to create a new file per style scope. 10 | * 11 | *= require_self 12 | *= require_tree . 13 | */ 14 | -------------------------------------------------------------------------------- /test/dummy/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | # Prevent CSRF attacks by raising an exception. 3 | # For APIs, you may want to use :null_session instead. 4 | protect_from_forgery with: :exception 5 | end 6 | -------------------------------------------------------------------------------- /test/dummy/app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peresleguine/pluggable_js/93305bf355aebec39de681c059aa8eb941e856f4/test/dummy/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /test/dummy/app/controllers/pluggable_js/posts_controller.rb: -------------------------------------------------------------------------------- 1 | module PluggableJs 2 | class PostsController < ApplicationController 3 | 4 | def index 5 | end 6 | 7 | def search 8 | render :index 9 | end 10 | 11 | def new 12 | pjs(marine_quote: 'You wanna piece of me, boy?') 13 | end 14 | 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /test/dummy/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /test/dummy/app/mailers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peresleguine/pluggable_js/93305bf355aebec39de681c059aa8eb941e856f4/test/dummy/app/mailers/.keep -------------------------------------------------------------------------------- /test/dummy/app/models/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peresleguine/pluggable_js/93305bf355aebec39de681c059aa8eb941e856f4/test/dummy/app/models/.keep -------------------------------------------------------------------------------- /test/dummy/app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peresleguine/pluggable_js/93305bf355aebec39de681c059aa8eb941e856f4/test/dummy/app/models/concerns/.keep -------------------------------------------------------------------------------- /test/dummy/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dummy 5 | <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> 6 | <%= javascript_include_tag "application", "data-turbolinks-track" => true %> 7 | <%= csrf_meta_tags %> 8 | 9 | 10 | <%= yield %> 11 | <%= javascript_pluggable_tag %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/dummy/app/views/pluggable_js/posts/index.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 | <%= link_to 'New post', new_pluggable_js_post_path %> 5 | 6 | <% pluggable_js( 7 | zealot_quote: 'My life for aiur.', 8 | minerals_size: 999, 9 | base_is_under_attack: true, 10 | alert: ['Nuclear', 'launch', 'detected.'], 11 | ground_units_quotes: { 'Dragoon' => 'Make use of me.', 'High Templar' => 'It shall be done.', 'Archon' => 'We burn...' }, 12 | air_units_quotes: [{'Scout' => 'Awaiting command.'}, {'Arbiter' => 'We feel your presence.'}, {'Carrier' => 'Affirmative.'}] 13 | ) %> 14 | -------------------------------------------------------------------------------- /test/dummy/app/views/pluggable_js/posts/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 | <%= link_to 'Posts', root_path %> 5 | -------------------------------------------------------------------------------- /test/dummy/bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /test/dummy/bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path('../../config/application', __FILE__) 3 | require_relative '../config/boot' 4 | require 'rails/commands' 5 | -------------------------------------------------------------------------------- /test/dummy/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative '../config/boot' 3 | require 'rake' 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /test/dummy/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Rails.application 5 | -------------------------------------------------------------------------------- /test/dummy/config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | require 'action_controller/railtie' 4 | require 'sprockets/railtie' 5 | 6 | Bundler.require(*Rails.groups) 7 | require 'pluggable_js' 8 | require 'jquery-rails' 9 | require 'turbolinks' 10 | 11 | module Dummy 12 | class Application < Rails::Application 13 | # Settings in config/environments/* take precedence over those specified here. 14 | # Application configuration should go into files in config/initializers 15 | # -- all .rb files in that directory are automatically loaded. 16 | 17 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 18 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 19 | # config.time_zone = 'Central Time (US & Canada)' 20 | 21 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 22 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 23 | # config.i18n.default_locale = :de 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /test/dummy/config/boot.rb: -------------------------------------------------------------------------------- 1 | # Set up gems listed in the Gemfile. 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) 3 | 4 | require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) 5 | $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__) 6 | -------------------------------------------------------------------------------- /test/dummy/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the Rails application. 5 | Dummy::Application.initialize! 6 | -------------------------------------------------------------------------------- /test/dummy/config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Do not eager load code on boot. 10 | config.eager_load = false 11 | 12 | # Show full error reports and disable caching. 13 | config.consider_all_requests_local = true 14 | config.action_controller.perform_caching = false 15 | 16 | # Print deprecation notices to the Rails logger. 17 | config.active_support.deprecation = :log 18 | 19 | # Debug mode disables concatenation and preprocessing of assets. 20 | # This option may cause significant delays in view rendering with a large 21 | # number of complex assets. 22 | config.assets.debug = true 23 | end 24 | -------------------------------------------------------------------------------- /test/dummy/config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # Code is not reloaded between requests. 5 | config.cache_classes = true 6 | 7 | # Eager load code on boot. This eager loads most of Rails and 8 | # your application in memory, allowing both thread web servers 9 | # and those relying on copy on write to perform better. 10 | # Rake tasks automatically ignore this option for performance. 11 | config.eager_load = true 12 | 13 | # Full error reports are disabled and caching is turned on. 14 | config.consider_all_requests_local = false 15 | config.action_controller.perform_caching = true 16 | 17 | # Enable Rack::Cache to put a simple HTTP cache in front of your application 18 | # Add `rack-cache` to your Gemfile before enabling this. 19 | # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. 20 | # config.action_dispatch.rack_cache = true 21 | 22 | # Disable Rails's static asset server (Apache or nginx will already do this). 23 | config.serve_static_files = false 24 | 25 | # Compress JavaScripts and CSS. 26 | config.assets.js_compressor = :uglifier 27 | # config.assets.css_compressor = :sass 28 | 29 | # Do not fallback to assets pipeline if a precompiled asset is missed. 30 | config.assets.compile = false 31 | 32 | # Generate digests for assets URLs. 33 | config.assets.digest = true 34 | 35 | # Version of your assets, change this if you want to expire all your assets. 36 | config.assets.version = '1.0' 37 | 38 | # Specifies the header that your server uses for sending files. 39 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache 40 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx 41 | 42 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 43 | # config.force_ssl = true 44 | 45 | # Set to :debug to see everything in the log. 46 | config.log_level = :info 47 | 48 | # Prepend all log lines with the following tags. 49 | # config.log_tags = [ :subdomain, :uuid ] 50 | 51 | # Use a different logger for distributed setups. 52 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 53 | 54 | # Use a different cache store in production. 55 | # config.cache_store = :mem_cache_store 56 | 57 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 58 | # config.action_controller.asset_host = "http://assets.example.com" 59 | 60 | # Precompile additional assets. 61 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. 62 | # config.assets.precompile += %w( search.js ) 63 | 64 | # Ignore bad email addresses and do not raise email delivery errors. 65 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 66 | # config.action_mailer.raise_delivery_errors = false 67 | 68 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 69 | # the I18n.default_locale when a translation can not be found). 70 | config.i18n.fallbacks = true 71 | 72 | # Send deprecation notices to registered listeners. 73 | config.active_support.deprecation = :notify 74 | 75 | # Disable automatic flushing of the log to improve performance. 76 | # config.autoflush_log = false 77 | 78 | # Use default logging formatter so that PID and timestamp are not suppressed. 79 | config.log_formatter = ::Logger::Formatter.new 80 | 81 | config.assets.precompile += %w(pluggable/*) 82 | end 83 | -------------------------------------------------------------------------------- /test/dummy/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Do not eager load code on boot. This avoids loading your whole application 11 | # just for the purpose of running a single test. If you are using a tool that 12 | # preloads Rails for running tests, you may have to set it to true. 13 | config.eager_load = false 14 | 15 | # Configure static asset server for tests with Cache-Control for performance. 16 | config.serve_static_files = true 17 | config.static_cache_control = "public, max-age=3600" 18 | 19 | # Show full error reports and disable caching. 20 | config.consider_all_requests_local = true 21 | config.action_controller.perform_caching = false 22 | 23 | # Raise exceptions instead of rendering exception templates. 24 | config.action_dispatch.show_exceptions = false 25 | 26 | # Disable request forgery protection in test environment. 27 | config.action_controller.allow_forgery_protection = false 28 | 29 | # Print deprecation notices to the stderr. 30 | config.active_support.deprecation = :stderr 31 | end 32 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [:password] 5 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, '\1en' 8 | # inflect.singular /^(ox)en/i, '\1' 9 | # inflect.irregular 'person', 'people' 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym 'RESTful' 16 | # end 17 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | # Mime::Type.register_alias "text/html", :iphone 6 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/pluggable_js.rb: -------------------------------------------------------------------------------- 1 | PluggableJs.config do |config| 2 | config.pair_actions = { 'search' => 'index' } 3 | end -------------------------------------------------------------------------------- /test/dummy/config/initializers/secret_token.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key is used for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | 6 | # Make sure the secret is at least 30 characters and all random, 7 | # no regular words or you'll be exposed to dictionary attacks. 8 | # You can use `rake secret` to generate a secure secret key. 9 | 10 | # Make sure your secret_key_base is kept private 11 | # if you're sharing your code publicly. 12 | Dummy::Application.config.secret_key_base = 'd277c81b129a9301a37cb2f38781cf6853ab1191fd6d6703f4c2f1e8b557ac9d9b7d0ddf8f13056ace7a6d651b081a2c0139199b01660c5e7fe2479ffecb948f' 13 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Dummy::Application.config.session_store :cookie_store, key: '_dummy_session' 4 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] if respond_to?(:wrap_parameters) 9 | end 10 | 11 | # To enable root element in JSON for ActiveRecord objects. 12 | # ActiveSupport.on_load(:active_record) do 13 | # self.include_root_in_json = true 14 | # end 15 | -------------------------------------------------------------------------------- /test/dummy/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # To learn more, please read the Rails Internationalization guide 20 | # available at http://guides.rubyonrails.org/i18n.html. 21 | 22 | en: 23 | hello: "Hello world" 24 | -------------------------------------------------------------------------------- /test/dummy/config/routes.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.routes.draw do 2 | root 'pluggable_js/posts#index' 3 | 4 | namespace :pluggable_js do 5 | resources :posts, only: [:index, :new] do 6 | collection do 7 | get :search 8 | end 9 | end 10 | end 11 | 12 | end 13 | -------------------------------------------------------------------------------- /test/dummy/lib/assets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peresleguine/pluggable_js/93305bf355aebec39de681c059aa8eb941e856f4/test/dummy/lib/assets/.keep -------------------------------------------------------------------------------- /test/dummy/public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 48 | 49 | 50 | 51 | 52 |
53 |

The page you were looking for doesn't exist.

54 |

You may have mistyped the address or the page may have moved.

55 |
56 |

If you are the application owner check the logs for more information.

57 | 58 | 59 | -------------------------------------------------------------------------------- /test/dummy/public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 48 | 49 | 50 | 51 | 52 |
53 |

The change you wanted was rejected.

54 |

Maybe you tried to change something you didn't have access to.

55 |
56 |

If you are the application owner check the logs for more information.

57 | 58 | 59 | -------------------------------------------------------------------------------- /test/dummy/public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 48 | 49 | 50 | 51 | 52 |
53 |

We're sorry, but something went wrong.

54 |
55 |

If you are the application owner check the logs for more information.

56 | 57 | 58 | -------------------------------------------------------------------------------- /test/dummy/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peresleguine/pluggable_js/93305bf355aebec39de681c059aa8eb941e856f4/test/dummy/public/favicon.ico --------------------------------------------------------------------------------