mousetrap-rails-1.4.6/0000755000076400007640000000000012546466474013727 5ustar pravipravimousetrap-rails-1.4.6/spec/0000755000076400007640000000000012546466474014661 5ustar pravipravimousetrap-rails-1.4.6/spec/spec_helper.rb0000644000076400007640000000313312546466474017477 0ustar pravipravi# This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../dummy/config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' require 'genspec' require 'coveralls' Coveralls.wear! # Require gem generators Dir[Rails.root.join("../../lib/generators/mousetrap/**/*_generator.rb")].each {|f| require f} # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} RSpec.configure do |config| # ## Mock Framework # # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: # # config.mock_with :mocha # config.mock_with :flexmock # config.mock_with :rr # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures # config.fixture_path = "#{::Rails.root}/spec/fixtures" # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false # instead of true. config.use_transactional_fixtures = false # If true, the base class of anonymous controllers will be inferred # automatically. This will be the default behavior in future versions of # rspec-rails. config.infer_base_class_for_anonymous_controllers = false # Run specs in random order to surface order dependencies. If you find an # order dependency and want to debug it, you can fix the order by providing # the seed, which is printed after each run. # --seed 1234 config.order = "random" end mousetrap-rails-1.4.6/spec/dummy/0000755000076400007640000000000012546466474016014 5ustar pravipravimousetrap-rails-1.4.6/spec/dummy/.rspec0000644000076400007640000000001012546466474017120 0ustar pravipravi--color mousetrap-rails-1.4.6/spec/dummy/README.rdoc0000644000076400007640000002177012546466474017631 0ustar pravipravi== Welcome to Rails Rails is a web-application framework that includes everything needed to create database-backed web applications according to the Model-View-Control pattern. This pattern splits the view (also called the presentation) into "dumb" templates that are primarily responsible for inserting pre-built data in between HTML tags. The model contains the "smart" domain objects (such as Account, Product, Person, Post) that holds all the business logic and knows how to persist themselves to a database. The controller handles the incoming requests (such as Save New Account, Update Product, Show Post) by manipulating the model and directing data to the view. In Rails, the model is handled by what's called an object-relational mapping layer entitled Active Record. This layer allows you to present the data from database rows as objects and embellish these data objects with business logic methods. You can read more about Active Record in link:files/vendor/rails/activerecord/README.html. The controller and view are handled by the Action Pack, which handles both layers by its two parts: Action View and Action Controller. These two layers are bundled in a single package due to their heavy interdependence. This is unlike the relationship between the Active Record and Action Pack that is much more separate. Each of these packages can be used independently outside of Rails. You can read more about Action Pack in link:files/vendor/rails/actionpack/README.html. == Getting Started 1. At the command prompt, create a new Rails application: rails new myapp (where myapp is the application name) 2. Change directory to myapp and start the web server: cd myapp; rails server (run with --help for options) 3. Go to http://localhost:3000/ and you'll see: "Welcome aboard: You're riding Ruby on Rails!" 4. Follow the guidelines to start developing your application. You can find the following resources handy: * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html * Ruby on Rails Tutorial Book: http://www.railstutorial.org/ == Debugging Rails Sometimes your application goes wrong. Fortunately there are a lot of tools that will help you debug it and get it back on the rails. First area to check is the application log files. Have "tail -f" commands running on the server.log and development.log. Rails will automatically display debugging and runtime information to these files. Debugging info will also be shown in the browser on requests from 127.0.0.1. You can also log your own messages directly into the log file from your code using the Ruby logger class from inside your controllers. Example: class WeblogController < ActionController::Base def destroy @weblog = Weblog.find(params[:id]) @weblog.destroy logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!") end end The result will be a message in your log file along the lines of: Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1! More information on how to use the logger is at http://www.ruby-doc.org/core/ Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are several books available online as well: * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe) * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide) These two books will bring you up to speed on the Ruby language and also on programming in general. == Debugger Debugger support is available through the debugger command when you start your Mongrel or WEBrick server with --debugger. This means that you can break out of execution at any point in the code, investigate and change the model, and then, resume execution! You need to install ruby-debug to run the server in debugging mode. With gems, use sudo gem install ruby-debug. Example: class WeblogController < ActionController::Base def index @posts = Post.all debugger end end So the controller will accept the action, run the first line, then present you with a IRB prompt in the server window. Here you can do things like: >> @posts.inspect => "[#nil, "body"=>nil, "id"=>"1"}>, #"Rails", "body"=>"Only ten..", "id"=>"2"}>]" >> @posts.first.title = "hello from a debugger" => "hello from a debugger" ...and even better, you can examine how your runtime objects actually work: >> f = @posts.first => #nil, "body"=>nil, "id"=>"1"}> >> f. Display all 152 possibilities? (y or n) Finally, when you're ready to resume execution, you can enter "cont". == Console The console is a Ruby shell, which allows you to interact with your application's domain model. Here you'll have all parts of the application configured, just like it is when the application is running. You can inspect domain models, change values, and save to the database. Starting the script without arguments will launch it in the development environment. To start the console, run rails console from the application directory. Options: * Passing the -s, --sandbox argument will rollback any modifications made to the database. * Passing an environment name as an argument will load the corresponding environment. Example: rails console production. To reload your controllers and models after launching the console run reload! More information about irb can be found at: link:http://www.rubycentral.org/pickaxe/irb.html == dbconsole You can go to the command line of your database directly through rails dbconsole. You would be connected to the database with the credentials defined in database.yml. Starting the script without arguments will connect you to the development database. Passing an argument will connect you to a different database, like rails dbconsole production. Currently works for MySQL, PostgreSQL and SQLite 3. == Description of Contents The default directory structure of a generated Ruby on Rails application: |-- app | |-- assets | |-- images | |-- javascripts | `-- stylesheets | |-- controllers | |-- helpers | |-- mailers | |-- models | `-- views | `-- layouts |-- config | |-- environments | |-- initializers | `-- locales |-- db |-- doc |-- lib | `-- tasks |-- log |-- public |-- script |-- test | |-- fixtures | |-- functional | |-- integration | |-- performance | `-- unit |-- tmp | |-- cache | |-- pids | |-- sessions | `-- sockets `-- vendor |-- assets `-- stylesheets `-- plugins app Holds all the code that's specific to this particular application. app/assets Contains subdirectories for images, stylesheets, and JavaScript files. app/controllers Holds controllers that should be named like weblogs_controller.rb for automated URL mapping. All controllers should descend from ApplicationController which itself descends from ActionController::Base. app/models Holds models that should be named like post.rb. Models descend from ActiveRecord::Base by default. app/views Holds the template files for the view that should be named like weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby syntax by default. app/views/layouts Holds the template files for layouts to be used with views. This models the common header/footer method of wrapping views. In your views, define a layout using the layout :default and create a file named default.html.erb. Inside default.html.erb, call <% yield %> to render the view using this layout. app/helpers Holds view helpers that should be named like weblogs_helper.rb. These are generated for you automatically when using generators for controllers. Helpers can be used to wrap functionality for your views into methods. config Configuration files for the Rails environment, the routing map, the database, and other dependencies. db Contains the database schema in schema.rb. db/migrate contains all the sequence of Migrations for your schema. doc This directory is where your application documentation will be stored when generated using rake doc:app lib Application specific libraries. Basically, any kind of custom code that doesn't belong under controllers, models, or helpers. This directory is in the load path. public The directory available for the web server. Also contains the dispatchers and the default HTML files. This should be set as the DOCUMENT_ROOT of your web server. script Helper scripts for automation and generation. test Unit and functional tests along with fixtures. When using the rails generate command, template test files will be generated for you and placed in this directory. vendor External libraries that the application depends on. Also includes the plugins subdirectory. If the app has frozen rails, those gems also go here, under vendor/rails/. This directory is in the load path. mousetrap-rails-1.4.6/spec/dummy/db/0000755000076400007640000000000012546466474016401 5ustar pravipravimousetrap-rails-1.4.6/spec/dummy/db/test.sqlite30000644000076400007640000000000012546466474020654 0ustar pravipravimousetrap-rails-1.4.6/spec/dummy/log/0000755000076400007640000000000012546466474016575 5ustar pravipravimousetrap-rails-1.4.6/spec/dummy/log/.gitkeep0000644000076400007640000000000012546466474020214 0ustar pravipravimousetrap-rails-1.4.6/spec/dummy/log/development.log0000644000076400007640000000000012546466474021610 0ustar pravipravimousetrap-rails-1.4.6/spec/dummy/config/0000755000076400007640000000000012546466474017261 5ustar pravipravimousetrap-rails-1.4.6/spec/dummy/config/environment.rb0000644000076400007640000000022512546466474022151 0ustar pravipravi# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application Dummy::Application.initialize! mousetrap-rails-1.4.6/spec/dummy/config/locales/0000755000076400007640000000000012546466474020703 5ustar pravipravimousetrap-rails-1.4.6/spec/dummy/config/locales/en.yml0000644000076400007640000000032612546466474022031 0ustar pravipravi# Sample localization file for English. Add more files in this directory for other locales. # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. en: hello: "Hello world" mousetrap-rails-1.4.6/spec/dummy/config/environments/0000755000076400007640000000000012546466474022010 5ustar pravipravimousetrap-rails-1.4.6/spec/dummy/config/environments/test.rb0000644000076400007640000000276512546466474023326 0ustar pravipraviDummy::Application.configure do # Settings specified here will take precedence over those in config/application.rb # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data there! config.cache_classes = true # Configure static asset server for tests with Cache-Control for performance config.serve_static_assets = true config.static_cache_control = "public, max-age=3600" # Log error messages when you accidentally call methods on nil config.whiny_nils = true # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false # Raise exceptions instead of rendering exception templates config.action_dispatch.show_exceptions = false # Disable request forgery protection in test environment config.action_controller.allow_forgery_protection = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test # Raise exception on mass assignment protection for Active Record models config.active_record.mass_assignment_sanitizer = :strict # Print deprecation notices to the stderr config.active_support.deprecation = :stderr end mousetrap-rails-1.4.6/spec/dummy/config/environments/production.rb0000644000076400007640000000465712546466474024537 0ustar pravipraviDummy::Application.configure do # Settings specified here will take precedence over those in config/application.rb # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turned on config.consider_all_requests_local = false config.action_controller.perform_caching = true # Disable Rails's static asset server (Apache or nginx will already do this) config.serve_static_assets = false # Compress JavaScripts and CSS config.assets.compress = true # Don't fallback to assets pipeline if a precompiled asset is missed config.assets.compile = false # Generate digests for assets URLs config.assets.digest = true # Defaults to nil and saved in location specified by config.assets.prefix # config.assets.manifest = YOUR_PATH # Specifies the header that your server uses for sending files # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true # See everything in the log (default is :info) # config.log_level = :debug # Prepend all log lines with the following tags # config.log_tags = [ :subdomain, :uuid ] # Use a different logger for distributed setups # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) # Use a different cache store in production # config.cache_store = :mem_cache_store # Enable serving of images, stylesheets, and JavaScripts from an asset server # config.action_controller.asset_host = "http://assets.example.com" # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) # config.assets.precompile += %w( search.js ) # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false # Enable threaded mode # config.threadsafe! # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation can not be found) config.i18n.fallbacks = true # Send deprecation notices to registered listeners config.active_support.deprecation = :notify # Log the query plan for queries taking more than this (works # with SQLite, MySQL, and PostgreSQL) # config.active_record.auto_explain_threshold_in_seconds = 0.5 end mousetrap-rails-1.4.6/spec/dummy/config/environments/development.rb0000644000076400007640000000253412546466474024663 0ustar pravipraviDummy::Application.configure do # Settings specified here will take precedence over those in config/application.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. config.cache_classes = false # Log error messages when you accidentally call methods on nil. config.whiny_nils = true # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = false # Print deprecation notices to the Rails logger config.active_support.deprecation = :log # Only use best-standards-support built into browsers config.action_dispatch.best_standards_support = :builtin # Raise exception on mass assignment protection for Active Record models config.active_record.mass_assignment_sanitizer = :strict # Log the query plan for queries taking more than this (works # with SQLite, MySQL, and PostgreSQL) config.active_record.auto_explain_threshold_in_seconds = 0.5 # Do not compress assets config.assets.compress = false # Expands the lines which load the assets config.assets.debug = true end mousetrap-rails-1.4.6/spec/dummy/config/boot.rb0000644000076400007640000000035312546466474020552 0ustar pravipravirequire 'rubygems' gemfile = File.expand_path('../../../../Gemfile', __FILE__) if File.exist?(gemfile) ENV['BUNDLE_GEMFILE'] = gemfile require 'bundler' Bundler.setup end $:.unshift File.expand_path('../../../../lib', __FILE__)mousetrap-rails-1.4.6/spec/dummy/config/initializers/0000755000076400007640000000000012546466474021767 5ustar pravipravimousetrap-rails-1.4.6/spec/dummy/config/initializers/session_store.rb0000644000076400007640000000062712546466474025220 0ustar pravipravi# Be sure to restart your server when you modify this file. Dummy::Application.config.session_store :cookie_store, key: '_dummy_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information # (create the session table with "rails generate session_migration") # Dummy::Application.config.session_store :active_record_store mousetrap-rails-1.4.6/spec/dummy/config/initializers/mime_types.rb0000644000076400007640000000031512546466474024466 0ustar pravipravi# Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf # Mime::Type.register_alias "text/html", :iphone mousetrap-rails-1.4.6/spec/dummy/config/initializers/secret_token.rb0000644000076400007640000000076012546466474025004 0ustar pravipravi# Be sure to restart your server when you modify this file. # Your secret key for verifying the integrity of signed cookies. # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. Dummy::Application.config.secret_token = '16930c8df0e323d059e1801bc59c7674266cd15aac547bcfed32712b162293623eecfad27b19413062914302b1b6ba96ade16d15c5e59bdb3e43e7b1c1bf48a9' mousetrap-rails-1.4.6/spec/dummy/config/initializers/inflections.rb0000644000076400007640000000102512546466474024627 0ustar pravipravi# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format # (all these examples are active by default): # ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' # inflect.uncountable %w( fish sheep ) # end # # These inflection rules are supported but not enabled by default: # ActiveSupport::Inflector.inflections do |inflect| # inflect.acronym 'RESTful' # end mousetrap-rails-1.4.6/spec/dummy/config/initializers/wrap_parameters.rb0000644000076400007640000000072112546466474025510 0ustar pravipravi# Be sure to restart your server when you modify this file. # # This file contains settings for ActionController::ParamsWrapper which # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do wrap_parameters format: [:json] end # Disable root element in JSON by default. ActiveSupport.on_load(:active_record) do self.include_root_in_json = false end mousetrap-rails-1.4.6/spec/dummy/config/initializers/backtrace_silencers.rb0000644000076400007640000000062412546466474026304 0ustar pravipravi# Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. # Rails.backtrace_cleaner.remove_silencers! mousetrap-rails-1.4.6/spec/dummy/config/database.yml0000644000076400007640000000110012546466474021540 0ustar pravipravi# SQLite version 3.x # gem install sqlite3 # # Ensure the SQLite 3 gem is defined in your Gemfile # gem 'sqlite3' development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000 # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: adapter: sqlite3 database: db/test.sqlite3 pool: 5 timeout: 5000 production: adapter: sqlite3 database: db/production.sqlite3 pool: 5 timeout: 5000 mousetrap-rails-1.4.6/spec/dummy/config/routes.rb0000644000076400007640000000337412546466474021136 0ustar pravipraviDummy::Application.routes.draw do # The priority is based upon order of creation: # first created -> highest priority. # Sample of regular route: # match 'products/:id' => 'catalog#view' # Keep in mind you can assign values other than :controller and :action # Sample of named route: # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase # This route can be invoked with purchase_url(:id => product.id) # Sample resource route (maps HTTP verbs to controller actions automatically): # resources :products # Sample resource route with options: # resources :products do # member do # get 'short' # post 'toggle' # end # # collection do # get 'sold' # end # end # Sample resource route with sub-resources: # resources :products do # resources :comments, :sales # resource :seller # end # Sample resource route with more complex sub-resources # resources :products do # resources :comments # resources :sales do # get 'recent', :on => :collection # end # end # Sample resource route within a namespace: # namespace :admin do # # Directs /admin/products/* to Admin::ProductsController # # (app/controllers/admin/products_controller.rb) # resources :products # end # You can have the root of your site routed with "root" # just remember to delete public/index.html. # root :to => 'welcome#index' # See how all your routes lay out with "rake routes" # This is a legacy wild controller route that's not recommended for RESTful applications. # Note: This route will make all actions in every controller accessible via GET requests. # match ':controller(/:action(/:id))(.:format)' end mousetrap-rails-1.4.6/spec/dummy/config/application.rb0000644000076400007640000000532612546466474022117 0ustar pravipravirequire File.expand_path('../boot', __FILE__) # Pick the frameworks you want: require "active_record/railtie" require "action_controller/railtie" require "action_mailer/railtie" require "active_resource/railtie" require "sprockets/railtie" # require "rails/test_unit/railtie" Bundler.require require "mousetrap-rails" module Dummy class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. # Custom directories with classes and modules you want to be autoloadable. # config.autoload_paths += %W(#{config.root}/extras) # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named. # config.plugins = [ :exception_notification, :ssl_requirement, :all ] # Activate observers that should always be running. # config.active_record.observers = :cacher, :garbage_collector, :forum_observer # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. # config.time_zone = 'Central Time (US & Canada)' # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.default_locale = :de # Configure the default encoding used in templates for Ruby 1.9. config.encoding = "utf-8" # Configure sensitive parameters which will be filtered from the log file. config.filter_parameters += [:password] # Enable escaping HTML in JSON. config.active_support.escape_html_entities_in_json = true # Use SQL instead of Active Record's schema dumper when creating the database. # This is necessary if your schema can't be completely dumped by the schema dumper, # like if you have constraints or database-specific column types # config.active_record.schema_format = :sql # Enforce whitelist mode for mass assignment. # This will create an empty whitelist of attributes available for mass-assignment for all models # in your app. As such, your models will need to explicitly whitelist or blacklist accessible # parameters by using an attr_accessible or attr_protected declaration. config.active_record.whitelist_attributes = true # Enable the asset pipeline config.assets.enabled = true # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.0' end end mousetrap-rails-1.4.6/spec/dummy/script/0000755000076400007640000000000012546466474017320 5ustar pravipravimousetrap-rails-1.4.6/spec/dummy/script/rails0000755000076400007640000000044712546466474020365 0ustar pravipravi#!/usr/bin/env ruby # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. APP_PATH = File.expand_path('../../config/application', __FILE__) require File.expand_path('../../config/boot', __FILE__) require 'rails/commands' mousetrap-rails-1.4.6/spec/dummy/public/0000755000076400007640000000000012546466474017272 5ustar pravipravimousetrap-rails-1.4.6/spec/dummy/public/422.html0000644000076400007640000000130712546466474020470 0ustar pravipravi The change you wanted was rejected (422)

The change you wanted was rejected.

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

mousetrap-rails-1.4.6/spec/dummy/public/500.html0000644000076400007640000000120312546466474020460 0ustar pravipravi We're sorry, but something went wrong (500)

We're sorry, but something went wrong.

mousetrap-rails-1.4.6/spec/dummy/public/favicon.ico0000644000076400007640000000000012546466474021401 0ustar pravipravimousetrap-rails-1.4.6/spec/dummy/public/404.html0000644000076400007640000000133012546466474020464 0ustar pravipravi The page you were looking for doesn't exist (404)

The page you were looking for doesn't exist.

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

mousetrap-rails-1.4.6/spec/dummy/config.ru0000644000076400007640000000023312546466474017627 0ustar pravipravi# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Dummy::Application mousetrap-rails-1.4.6/spec/dummy/app/0000755000076400007640000000000012546466474016574 5ustar pravipravimousetrap-rails-1.4.6/spec/dummy/app/assets/0000755000076400007640000000000012546466474020076 5ustar pravipravimousetrap-rails-1.4.6/spec/dummy/app/assets/stylesheets/0000755000076400007640000000000012546466474022452 5ustar pravipravimousetrap-rails-1.4.6/spec/dummy/app/assets/stylesheets/application.css0000644000076400007640000000104212546466474025464 0ustar pravipravi/* * This is a manifest file that'll be compiled into application.css, which will include all the files * listed below. * * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. * * You're free to add application-wide styles to this file and they'll appear at the top of the * compiled file, but it's generally better to create a new file per style scope. * *= require_self *= require_tree . */ mousetrap-rails-1.4.6/spec/dummy/app/assets/javascripts/0000755000076400007640000000000012546466474022427 5ustar pravipravimousetrap-rails-1.4.6/spec/dummy/app/assets/javascripts/application.js0000644000076400007640000000120112546466474025262 0ustar pravipravi// This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // the compiled file. // // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD // GO AFTER THE REQUIRES BELOW. // //= require jquery //= require jquery_ujs //= require_tree . mousetrap-rails-1.4.6/spec/dummy/app/helpers/0000755000076400007640000000000012546466474020236 5ustar pravipravimousetrap-rails-1.4.6/spec/dummy/app/helpers/application_helper.rb0000644000076400007640000000003512546466474024423 0ustar pravipravimodule ApplicationHelper end mousetrap-rails-1.4.6/spec/dummy/app/mailers/0000755000076400007640000000000012546466474020230 5ustar pravipravimousetrap-rails-1.4.6/spec/dummy/app/mailers/.gitkeep0000644000076400007640000000000012546466474021647 0ustar pravipravimousetrap-rails-1.4.6/spec/dummy/app/models/0000755000076400007640000000000012546466474020057 5ustar pravipravimousetrap-rails-1.4.6/spec/dummy/app/models/.gitkeep0000644000076400007640000000000012546466474021476 0ustar pravipravimousetrap-rails-1.4.6/spec/dummy/app/views/0000755000076400007640000000000012546466474017731 5ustar pravipravimousetrap-rails-1.4.6/spec/dummy/app/views/layouts/0000755000076400007640000000000012546466474021431 5ustar pravipravimousetrap-rails-1.4.6/spec/dummy/app/views/layouts/application.html.erb0000644000076400007640000000035012546466474025367 0ustar pravipravi Dummy <%= stylesheet_link_tag "application", :media => "all" %> <%= javascript_include_tag "application" %> <%= csrf_meta_tags %> <%= yield %> mousetrap-rails-1.4.6/spec/dummy/app/controllers/0000755000076400007640000000000012546466474021142 5ustar pravipravimousetrap-rails-1.4.6/spec/dummy/app/controllers/application_controller.rb0000644000076400007640000000012012546466474026226 0ustar pravipraviclass ApplicationController < ActionController::Base protect_from_forgery end mousetrap-rails-1.4.6/spec/dummy/lib/0000755000076400007640000000000012546466474016562 5ustar pravipravimousetrap-rails-1.4.6/spec/dummy/lib/assets/0000755000076400007640000000000012546466474020064 5ustar pravipravimousetrap-rails-1.4.6/spec/dummy/lib/assets/.gitkeep0000644000076400007640000000000012546466474021503 0ustar pravipravimousetrap-rails-1.4.6/spec/dummy/Rakefile0000644000076400007640000000041612546466474017462 0ustar pravipravi#!/usr/bin/env rake # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require File.expand_path('../config/application', __FILE__) Dummy::Application.load_tasks mousetrap-rails-1.4.6/spec/generators/0000755000076400007640000000000012546466474017032 5ustar pravipravimousetrap-rails-1.4.6/spec/generators/install_generator_spec.rb0000644000076400007640000000137612546466474024114 0ustar pravipravirequire 'spec_helper' describe Mousetrap::Generators::InstallGenerator do context "with mousetrap:install" do it "should generate keybindings.js.coffee file" do subject.should generate("app/assets/javascripts/keybindings.js.coffee") { |content| content.should =~ /Mousetrap\.bind/ } end it "should inject require mousetrap into application.js" do subject.should generate("app/assets/javascripts/application.js") { |content| content.should =~ /\/\/= require mousetrap\n/ } end it "should inject require mousetrap into application.css" do subject.should generate("app/assets/stylesheets/application.css") { |content| content.should =~ /\s\*= require mousetrap\n/ } end end end mousetrap-rails-1.4.6/LICENSE.md0000644000076400007640000000323112546466474015332 0ustar pravipravi### Gem mousetrap-rails Copyright (c) 2012—2013 Nick Kugaevsky Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ### Original Moustrap javascript library Copyright 2012 Craig Campbell Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. mousetrap-rails-1.4.6/gem-public_cert.pem0000644000076400007640000000222012546466474017467 0ustar pravipravi-----BEGIN CERTIFICATE----- MIIDMDCCAhigAwIBAgIBADANBgkqhkiG9w0BAQUFADA+MQ0wCwYDVQQDDARuaWNr MRkwFwYKCZImiZPyLGQBGRYJa3VnYWV2c2t5MRIwEAYKCZImiZPyLGQBGRYCcnUw HhcNMTMwMTMxMTgxMjMwWhcNMTQwMTMxMTgxMjMwWjA+MQ0wCwYDVQQDDARuaWNr MRkwFwYKCZImiZPyLGQBGRYJa3VnYWV2c2t5MRIwEAYKCZImiZPyLGQBGRYCcnUw ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC3SS01rsI5N3EUG3bSnfI2 pr4Exx9gKCBS5IxV7Ot+pQ2psIiWoenaS4fS2fsmvle92ClEx3NbUqnxxGDES0Eb FkNHyAH9VwO36vS0loNv/Ox2sSaleUNV3JdvcP1Gm3xGtn9KWNcpuAwPfMl5BSYg K4WU8zIkbLlwmrO6h85IYZrDwqghb6OCOwhb56d4byjoJE25brUxETxGVdsuVCDr EQroS+D2BiMAEdwJcn/PepMx3lt+teZrjUoei5UXIcnZ28UYSnmXjXnkySlPXzRV siLwUMAgGu665huUE5S8idW7ohSHTJv/kH98BoiWi7gi9HFMz4OJMMeR5rZk76Ql AgMBAAGjOTA3MAkGA1UdEwQCMAAwHQYDVR0OBBYEFCdIKkB9lZ+com0wLBhLQDWe YnbvMAsGA1UdDwQEAwIEsDANBgkqhkiG9w0BAQUFAAOCAQEANOubFddpzMXJflPv vXXnWXYvZK2etSxzwewXXOhcbzwSxdU0T4NbKcrlhlFbjUDh/xF4Qzc1dB9OFG9r ffIUKv0JtEyGM/mOaISsNp+oYUlXxXLNOsX8LT1r+337tQ627GoX/Z0RL5u8Mz6Q KZUJhGQKNnIp6Rkz6sp4Zh2aqTLt8BDEA86kO+0v4LaVLqFEmLTypf7C568RTYlm N8LaREQMM5YdvCIYWs5C6iNRVaDhT8bkuWNhtBis0H7YFAfsW1rn9np8OQ7nY2az 8dNQrBlKzc/RLwGGFT1gjzVlIb7/xtNdMdJQ6JwyljSJ70PbKAAzgBRdDLPt9BWt 3AH9mw== -----END CERTIFICATE----- mousetrap-rails-1.4.6/.travis.yml0000644000076400007640000000017012546466474016036 0ustar pravipravilanguage: ruby rvm: - 1.9.2 - 1.9.3 - 2.0.0 - rbx-2.0.0 - rbx-2.1.0 - rbx-2.1.1 - rbx-2.2.0 - rbx-2.2.1 mousetrap-rails-1.4.6/vendor/0000755000076400007640000000000012546466474015224 5ustar pravipravimousetrap-rails-1.4.6/vendor/assets/0000755000076400007640000000000012546466474016526 5ustar pravipravimousetrap-rails-1.4.6/vendor/assets/javascripts/0000755000076400007640000000000012546466474021057 5ustar pravipravimousetrap-rails-1.4.6/vendor/assets/javascripts/mousetrap/0000755000076400007640000000000012546466474023076 5ustar pravipravimousetrap-rails-1.4.6/vendor/assets/javascripts/mousetrap/plugins.js0000644000076400007640000000016712546466474025121 0ustar pravipravi//= require mousetrap/dictionary //= require mousetrap/global //= require mousetrap/pause //= require mousetrap/record mousetrap-rails-1.4.6/vendor/assets/javascripts/mousetrap/dictionary.js0000644000076400007640000000167412546466474025611 0ustar pravipravi/** * Overwrites default Mousetrap.bind method to optionally accept * an object to bind multiple key events in a single call * * You can pass it in like: * * Mousetrap.bind({ * 'a': function() { console.log('a'); }, * 'b': function() { console.log('b'); } * }); * * And can optionally pass in 'keypress', 'keydown', or 'keyup' * as a second argument * */ /* global Mousetrap:true */ Mousetrap = (function(Mousetrap) { var self = Mousetrap, _oldBind = self.bind, args; self.bind = function() { args = arguments; // normal call if (typeof args[0] == 'string' || args[0] instanceof Array) { return _oldBind(args[0], args[1], args[2]); } // object passed in for (var key in args[0]) { if (args[0].hasOwnProperty(key)) { _oldBind(key, args[0][key], args[1]); } } }; return self; }) (Mousetrap); mousetrap-rails-1.4.6/vendor/assets/javascripts/mousetrap/pause.js0000644000076400007640000000124612546466474024554 0ustar pravipravi/** * adds a pause and unpause method to Mousetrap * this allows you to enable or disable keyboard shortcuts * without having to reset Mousetrap and rebind everything */ /* global Mousetrap:true */ Mousetrap = (function(Mousetrap) { var self = Mousetrap, _originalStopCallback = self.stopCallback, enabled = true; self.stopCallback = function(e, element, combo) { if (!enabled) { return true; } return _originalStopCallback(e, element, combo); }; self.pause = function() { enabled = false; }; self.unpause = function() { enabled = true; }; return self; }) (Mousetrap); mousetrap-rails-1.4.6/vendor/assets/javascripts/mousetrap/global.js0000644000076400007640000000173312546466474024700 0ustar pravipravi/** * adds a bindGlobal method to Mousetrap that allows you to * bind specific keyboard shortcuts that will still work * inside a text input field * * usage: * Mousetrap.bindGlobal('ctrl+s', _saveChanges); */ /* global Mousetrap:true */ Mousetrap = (function(Mousetrap) { var _globalCallbacks = {}, _originalStopCallback = Mousetrap.stopCallback; Mousetrap.stopCallback = function(e, element, combo, sequence) { if (_globalCallbacks[combo] || _globalCallbacks[sequence]) { return false; } return _originalStopCallback(e, element, combo); }; Mousetrap.bindGlobal = function(keys, callback, action) { Mousetrap.bind(keys, callback, action); if (keys instanceof Array) { for (var i = 0; i < keys.length; i++) { _globalCallbacks[keys[i]] = true; } return; } _globalCallbacks[keys] = true; }; return Mousetrap; }) (Mousetrap); mousetrap-rails-1.4.6/vendor/assets/javascripts/mousetrap/record.js0000644000076400007640000001203212546466474024710 0ustar pravipravi/** * This extension allows you to record a sequence using Mousetrap. * * @author Dan Tao */ (function(Mousetrap) { /** * the sequence currently being recorded * * @type {Array} */ var _recordedSequence = [], /** * a callback to invoke after recording a sequence * * @type {Function|null} */ _recordedSequenceCallback = null, /** * a list of all of the keys currently held down * * @type {Array} */ _currentRecordedKeys = [], /** * temporary state where we remember if we've already captured a * character key in the current combo * * @type {boolean} */ _recordedCharacterKey = false, /** * a handle for the timer of the current recording * * @type {null|number} */ _recordTimer = null, /** * the original handleKey method to override when Mousetrap.record() is * called * * @type {Function} */ _origHandleKey = Mousetrap.handleKey; /** * handles a character key event * * @param {string} character * @param {Array} modifiers * @param {Event} e * @returns void */ function _handleKey(character, modifiers, e) { // remember this character if we're currently recording a sequence if (e.type == 'keydown') { if (character.length === 1 && _recordedCharacterKey) { _recordCurrentCombo(); } for (i = 0; i < modifiers.length; ++i) { _recordKey(modifiers[i]); } _recordKey(character); // once a key is released, all keys that were held down at the time // count as a keypress } else if (e.type == 'keyup' && _currentRecordedKeys.length > 0) { _recordCurrentCombo(); } } /** * marks a character key as held down while recording a sequence * * @param {string} key * @returns void */ function _recordKey(key) { var i; // one-off implementation of Array.indexOf, since IE6-9 don't support it for (i = 0; i < _currentRecordedKeys.length; ++i) { if (_currentRecordedKeys[i] === key) { return; } } _currentRecordedKeys.push(key); if (key.length === 1) { _recordedCharacterKey = true; } } /** * marks whatever key combination that's been recorded so far as finished * and gets ready for the next combo * * @returns void */ function _recordCurrentCombo() { _recordedSequence.push(_currentRecordedKeys); _currentRecordedKeys = []; _recordedCharacterKey = false; _restartRecordTimer(); } /** * ensures each combo in a sequence is in a predictable order and formats * key combos to be '+'-delimited * * modifies the sequence in-place * * @param {Array} sequence * @returns void */ function _normalizeSequence(sequence) { var i; for (i = 0; i < sequence.length; ++i) { sequence[i].sort(function(x, y) { // modifier keys always come first, in alphabetical order if (x.length > 1 && y.length === 1) { return -1; } else if (x.length === 1 && y.length > 1) { return 1; } // character keys come next (list should contain no duplicates, // so no need for equality check) return x > y ? 1 : -1; }); sequence[i] = sequence[i].join('+'); } } /** * finishes the current recording, passes the recorded sequence to the stored * callback, and sets Mousetrap.handleKey back to its original function * * @returns void */ function _finishRecording() { if (_recordedSequenceCallback) { _normalizeSequence(_recordedSequence); _recordedSequenceCallback(_recordedSequence); } // reset all recorded state _recordedSequence = []; _recordedSequenceCallback = null; _currentRecordedKeys = []; Mousetrap.handleKey = _origHandleKey; } /** * called to set a 1 second timeout on the current recording * * this is so after each key press in the sequence the recording will wait for * 1 more second before executing the callback * * @returns void */ function _restartRecordTimer() { clearTimeout(_recordTimer); _recordTimer = setTimeout(_finishRecording, 1000); } /** * records the next sequence and passes it to a callback once it's * completed * * @param {Function} callback * @returns void */ Mousetrap.record = function(callback) { Mousetrap.handleKey = _handleKey; _recordedSequenceCallback = callback; }; })(Mousetrap); mousetrap-rails-1.4.6/vendor/assets/javascripts/mousetrap.js0000644000076400007640000007161012546466474023441 0ustar pravipravi/*global define:false */ /** * Copyright 2013 Craig Campbell * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Mousetrap is a simple keyboard shortcut library for Javascript with * no external dependencies * * @version 1.4.6 * @url craig.is/killing/mice */ (function(window, document, undefined) { /** * mapping of special keycodes to their corresponding keys * * everything in this dictionary cannot use keypress events * so it has to be here to map to the correct keycodes for * keyup/keydown events * * @type {Object} */ var _MAP = { 8: 'backspace', 9: 'tab', 13: 'enter', 16: 'shift', 17: 'ctrl', 18: 'alt', 20: 'capslock', 27: 'esc', 32: 'space', 33: 'pageup', 34: 'pagedown', 35: 'end', 36: 'home', 37: 'left', 38: 'up', 39: 'right', 40: 'down', 45: 'ins', 46: 'del', 91: 'meta', 93: 'meta', 224: 'meta' }, /** * mapping for special characters so they can support * * this dictionary is only used incase you want to bind a * keyup or keydown event to one of these keys * * @type {Object} */ _KEYCODE_MAP = { 106: '*', 107: '+', 109: '-', 110: '.', 111 : '/', 186: ';', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`', 219: '[', 220: '\\', 221: ']', 222: '\'' }, /** * this is a mapping of keys that require shift on a US keypad * back to the non shift equivelents * * this is so you can use keyup events with these keys * * note that this will only work reliably on US keyboards * * @type {Object} */ _SHIFT_MAP = { '~': '`', '!': '1', '@': '2', '#': '3', '$': '4', '%': '5', '^': '6', '&': '7', '*': '8', '(': '9', ')': '0', '_': '-', '+': '=', ':': ';', '\"': '\'', '<': ',', '>': '.', '?': '/', '|': '\\' }, /** * this is a list of special strings you can use to map * to modifier keys when you specify your keyboard shortcuts * * @type {Object} */ _SPECIAL_ALIASES = { 'option': 'alt', 'command': 'meta', 'return': 'enter', 'escape': 'esc', 'mod': /Mac|iPod|iPhone|iPad/.test(navigator.platform) ? 'meta' : 'ctrl' }, /** * variable to store the flipped version of _MAP from above * needed to check if we should use keypress or not when no action * is specified * * @type {Object|undefined} */ _REVERSE_MAP, /** * a list of all the callbacks setup via Mousetrap.bind() * * @type {Object} */ _callbacks = {}, /** * direct map of string combinations to callbacks used for trigger() * * @type {Object} */ _directMap = {}, /** * keeps track of what level each sequence is at since multiple * sequences can start out with the same sequence * * @type {Object} */ _sequenceLevels = {}, /** * variable to store the setTimeout call * * @type {null|number} */ _resetTimer, /** * temporary state where we will ignore the next keyup * * @type {boolean|string} */ _ignoreNextKeyup = false, /** * temporary state where we will ignore the next keypress * * @type {boolean} */ _ignoreNextKeypress = false, /** * are we currently inside of a sequence? * type of action ("keyup" or "keydown" or "keypress") or false * * @type {boolean|string} */ _nextExpectedAction = false; /** * loop through the f keys, f1 to f19 and add them to the map * programatically */ for (var i = 1; i < 20; ++i) { _MAP[111 + i] = 'f' + i; } /** * loop through to map numbers on the numeric keypad */ for (i = 0; i <= 9; ++i) { _MAP[i + 96] = i; } /** * cross browser add event method * * @param {Element|HTMLDocument} object * @param {string} type * @param {Function} callback * @returns void */ function _addEvent(object, type, callback) { if (object.addEventListener) { object.addEventListener(type, callback, false); return; } object.attachEvent('on' + type, callback); } /** * takes the event and returns the key character * * @param {Event} e * @return {string} */ function _characterFromEvent(e) { // for keypress events we should return the character as is if (e.type == 'keypress') { var character = String.fromCharCode(e.which); // if the shift key is not pressed then it is safe to assume // that we want the character to be lowercase. this means if // you accidentally have caps lock on then your key bindings // will continue to work // // the only side effect that might not be desired is if you // bind something like 'A' cause you want to trigger an // event when capital A is pressed caps lock will no longer // trigger the event. shift+a will though. if (!e.shiftKey) { character = character.toLowerCase(); } return character; } // for non keypress events the special maps are needed if (_MAP[e.which]) { return _MAP[e.which]; } if (_KEYCODE_MAP[e.which]) { return _KEYCODE_MAP[e.which]; } // if it is not in the special map // with keydown and keyup events the character seems to always // come in as an uppercase character whether you are pressing shift // or not. we should make sure it is always lowercase for comparisons return String.fromCharCode(e.which).toLowerCase(); } /** * checks if two arrays are equal * * @param {Array} modifiers1 * @param {Array} modifiers2 * @returns {boolean} */ function _modifiersMatch(modifiers1, modifiers2) { return modifiers1.sort().join(',') === modifiers2.sort().join(','); } /** * resets all sequence counters except for the ones passed in * * @param {Object} doNotReset * @returns void */ function _resetSequences(doNotReset) { doNotReset = doNotReset || {}; var activeSequences = false, key; for (key in _sequenceLevels) { if (doNotReset[key]) { activeSequences = true; continue; } _sequenceLevels[key] = 0; } if (!activeSequences) { _nextExpectedAction = false; } } /** * finds all callbacks that match based on the keycode, modifiers, * and action * * @param {string} character * @param {Array} modifiers * @param {Event|Object} e * @param {string=} sequenceName - name of the sequence we are looking for * @param {string=} combination * @param {number=} level * @returns {Array} */ function _getMatches(character, modifiers, e, sequenceName, combination, level) { var i, callback, matches = [], action = e.type; // if there are no events related to this keycode if (!_callbacks[character]) { return []; } // if a modifier key is coming up on its own we should allow it if (action == 'keyup' && _isModifier(character)) { modifiers = [character]; } // loop through all callbacks for the key that was pressed // and see if any of them match for (i = 0; i < _callbacks[character].length; ++i) { callback = _callbacks[character][i]; // if a sequence name is not specified, but this is a sequence at // the wrong level then move onto the next match if (!sequenceName && callback.seq && _sequenceLevels[callback.seq] != callback.level) { continue; } // if the action we are looking for doesn't match the action we got // then we should keep going if (action != callback.action) { continue; } // if this is a keypress event and the meta key and control key // are not pressed that means that we need to only look at the // character, otherwise check the modifiers as well // // chrome will not fire a keypress if meta or control is down // safari will fire a keypress if meta or meta+shift is down // firefox will fire a keypress if meta or control is down if ((action == 'keypress' && !e.metaKey && !e.ctrlKey) || _modifiersMatch(modifiers, callback.modifiers)) { // when you bind a combination or sequence a second time it // should overwrite the first one. if a sequenceName or // combination is specified in this call it does just that // // @todo make deleting its own method? var deleteCombo = !sequenceName && callback.combo == combination; var deleteSequence = sequenceName && callback.seq == sequenceName && callback.level == level; if (deleteCombo || deleteSequence) { _callbacks[character].splice(i, 1); } matches.push(callback); } } return matches; } /** * takes a key event and figures out what the modifiers are * * @param {Event} e * @returns {Array} */ function _eventModifiers(e) { var modifiers = []; if (e.shiftKey) { modifiers.push('shift'); } if (e.altKey) { modifiers.push('alt'); } if (e.ctrlKey) { modifiers.push('ctrl'); } if (e.metaKey) { modifiers.push('meta'); } return modifiers; } /** * prevents default for this event * * @param {Event} e * @returns void */ function _preventDefault(e) { if (e.preventDefault) { e.preventDefault(); return; } e.returnValue = false; } /** * stops propogation for this event * * @param {Event} e * @returns void */ function _stopPropagation(e) { if (e.stopPropagation) { e.stopPropagation(); return; } e.cancelBubble = true; } /** * actually calls the callback function * * if your callback function returns false this will use the jquery * convention - prevent default and stop propogation on the event * * @param {Function} callback * @param {Event} e * @returns void */ function _fireCallback(callback, e, combo, sequence) { // if this event should not happen stop here if (Mousetrap.stopCallback(e, e.target || e.srcElement, combo, sequence)) { return; } if (callback(e, combo) === false) { _preventDefault(e); _stopPropagation(e); } } /** * handles a character key event * * @param {string} character * @param {Array} modifiers * @param {Event} e * @returns void */ function _handleKey(character, modifiers, e) { var callbacks = _getMatches(character, modifiers, e), i, doNotReset = {}, maxLevel = 0, processedSequenceCallback = false; // Calculate the maxLevel for sequences so we can only execute the longest callback sequence for (i = 0; i < callbacks.length; ++i) { if (callbacks[i].seq) { maxLevel = Math.max(maxLevel, callbacks[i].level); } } // loop through matching callbacks for this key event for (i = 0; i < callbacks.length; ++i) { // fire for all sequence callbacks // this is because if for example you have multiple sequences // bound such as "g i" and "g t" they both need to fire the // callback for matching g cause otherwise you can only ever // match the first one if (callbacks[i].seq) { // only fire callbacks for the maxLevel to prevent // subsequences from also firing // // for example 'a option b' should not cause 'option b' to fire // even though 'option b' is part of the other sequence // // any sequences that do not match here will be discarded // below by the _resetSequences call if (callbacks[i].level != maxLevel) { continue; } processedSequenceCallback = true; // keep a list of which sequences were matches for later doNotReset[callbacks[i].seq] = 1; _fireCallback(callbacks[i].callback, e, callbacks[i].combo, callbacks[i].seq); continue; } // if there were no sequence matches but we are still here // that means this is a regular match so we should fire that if (!processedSequenceCallback) { _fireCallback(callbacks[i].callback, e, callbacks[i].combo); } } // if the key you pressed matches the type of sequence without // being a modifier (ie "keyup" or "keypress") then we should // reset all sequences that were not matched by this event // // this is so, for example, if you have the sequence "h a t" and you // type "h e a r t" it does not match. in this case the "e" will // cause the sequence to reset // // modifier keys are ignored because you can have a sequence // that contains modifiers such as "enter ctrl+space" and in most // cases the modifier key will be pressed before the next key // // also if you have a sequence such as "ctrl+b a" then pressing the // "b" key will trigger a "keypress" and a "keydown" // // the "keydown" is expected when there is a modifier, but the // "keypress" ends up matching the _nextExpectedAction since it occurs // after and that causes the sequence to reset // // we ignore keypresses in a sequence that directly follow a keydown // for the same character var ignoreThisKeypress = e.type == 'keypress' && _ignoreNextKeypress; if (e.type == _nextExpectedAction && !_isModifier(character) && !ignoreThisKeypress) { _resetSequences(doNotReset); } _ignoreNextKeypress = processedSequenceCallback && e.type == 'keydown'; } /** * handles a keydown event * * @param {Event} e * @returns void */ function _handleKeyEvent(e) { // normalize e.which for key events // @see http://stackoverflow.com/questions/4285627/javascript-keycode-vs-charcode-utter-confusion if (typeof e.which !== 'number') { e.which = e.keyCode; } var character = _characterFromEvent(e); // no character found then stop if (!character) { return; } // need to use === for the character check because the character can be 0 if (e.type == 'keyup' && _ignoreNextKeyup === character) { _ignoreNextKeyup = false; return; } Mousetrap.handleKey(character, _eventModifiers(e), e); } /** * determines if the keycode specified is a modifier key or not * * @param {string} key * @returns {boolean} */ function _isModifier(key) { return key == 'shift' || key == 'ctrl' || key == 'alt' || key == 'meta'; } /** * called to set a 1 second timeout on the specified sequence * * this is so after each key press in the sequence you have 1 second * to press the next key before you have to start over * * @returns void */ function _resetSequenceTimer() { clearTimeout(_resetTimer); _resetTimer = setTimeout(_resetSequences, 1000); } /** * reverses the map lookup so that we can look for specific keys * to see what can and can't use keypress * * @return {Object} */ function _getReverseMap() { if (!_REVERSE_MAP) { _REVERSE_MAP = {}; for (var key in _MAP) { // pull out the numeric keypad from here cause keypress should // be able to detect the keys from the character if (key > 95 && key < 112) { continue; } if (_MAP.hasOwnProperty(key)) { _REVERSE_MAP[_MAP[key]] = key; } } } return _REVERSE_MAP; } /** * picks the best action based on the key combination * * @param {string} key - character for key * @param {Array} modifiers * @param {string=} action passed in */ function _pickBestAction(key, modifiers, action) { // if no action was picked in we should try to pick the one // that we think would work best for this key if (!action) { action = _getReverseMap()[key] ? 'keydown' : 'keypress'; } // modifier keys don't work as expected with keypress, // switch to keydown if (action == 'keypress' && modifiers.length) { action = 'keydown'; } return action; } /** * binds a key sequence to an event * * @param {string} combo - combo specified in bind call * @param {Array} keys * @param {Function} callback * @param {string=} action * @returns void */ function _bindSequence(combo, keys, callback, action) { // start off by adding a sequence level record for this combination // and setting the level to 0 _sequenceLevels[combo] = 0; /** * callback to increase the sequence level for this sequence and reset * all other sequences that were active * * @param {string} nextAction * @returns {Function} */ function _increaseSequence(nextAction) { return function() { _nextExpectedAction = nextAction; ++_sequenceLevels[combo]; _resetSequenceTimer(); }; } /** * wraps the specified callback inside of another function in order * to reset all sequence counters as soon as this sequence is done * * @param {Event} e * @returns void */ function _callbackAndReset(e) { _fireCallback(callback, e, combo); // we should ignore the next key up if the action is key down // or keypress. this is so if you finish a sequence and // release the key the final key will not trigger a keyup if (action !== 'keyup') { _ignoreNextKeyup = _characterFromEvent(e); } // weird race condition if a sequence ends with the key // another sequence begins with setTimeout(_resetSequences, 10); } // loop through keys one at a time and bind the appropriate callback // function. for any key leading up to the final one it should // increase the sequence. after the final, it should reset all sequences // // if an action is specified in the original bind call then that will // be used throughout. otherwise we will pass the action that the // next key in the sequence should match. this allows a sequence // to mix and match keypress and keydown events depending on which // ones are better suited to the key provided for (var i = 0; i < keys.length; ++i) { var isFinal = i + 1 === keys.length; var wrappedCallback = isFinal ? _callbackAndReset : _increaseSequence(action || _getKeyInfo(keys[i + 1]).action); _bindSingle(keys[i], wrappedCallback, action, combo, i); } } /** * Converts from a string key combination to an array * * @param {string} combination like "command+shift+l" * @return {Array} */ function _keysFromString(combination) { if (combination === '+') { return ['+']; } return combination.split('+'); } /** * Gets info for a specific key combination * * @param {string} combination key combination ("command+s" or "a" or "*") * @param {string=} action * @returns {Object} */ function _getKeyInfo(combination, action) { var keys, key, i, modifiers = []; // take the keys from this pattern and figure out what the actual // pattern is all about keys = _keysFromString(combination); for (i = 0; i < keys.length; ++i) { key = keys[i]; // normalize key names if (_SPECIAL_ALIASES[key]) { key = _SPECIAL_ALIASES[key]; } // if this is not a keypress event then we should // be smart about using shift keys // this will only work for US keyboards however if (action && action != 'keypress' && _SHIFT_MAP[key]) { key = _SHIFT_MAP[key]; modifiers.push('shift'); } // if this key is a modifier then add it to the list of modifiers if (_isModifier(key)) { modifiers.push(key); } } // depending on what the key combination is // we will try to pick the best event for it action = _pickBestAction(key, modifiers, action); return { key: key, modifiers: modifiers, action: action }; } /** * binds a single keyboard combination * * @param {string} combination * @param {Function} callback * @param {string=} action * @param {string=} sequenceName - name of sequence if part of sequence * @param {number=} level - what part of the sequence the command is * @returns void */ function _bindSingle(combination, callback, action, sequenceName, level) { // store a direct mapped reference for use with Mousetrap.trigger _directMap[combination + ':' + action] = callback; // make sure multiple spaces in a row become a single space combination = combination.replace(/\s+/g, ' '); var sequence = combination.split(' '), info; // if this pattern is a sequence of keys then run through this method // to reprocess each pattern one key at a time if (sequence.length > 1) { _bindSequence(combination, sequence, callback, action); return; } info = _getKeyInfo(combination, action); // make sure to initialize array if this is the first time // a callback is added for this key _callbacks[info.key] = _callbacks[info.key] || []; // remove an existing match if there is one _getMatches(info.key, info.modifiers, {type: info.action}, sequenceName, combination, level); // add this call back to the array // if it is a sequence put it at the beginning // if not put it at the end // // this is important because the way these are processed expects // the sequence ones to come first _callbacks[info.key][sequenceName ? 'unshift' : 'push']({ callback: callback, modifiers: info.modifiers, action: info.action, seq: sequenceName, level: level, combo: combination }); } /** * binds multiple combinations to the same callback * * @param {Array} combinations * @param {Function} callback * @param {string|undefined} action * @returns void */ function _bindMultiple(combinations, callback, action) { for (var i = 0; i < combinations.length; ++i) { _bindSingle(combinations[i], callback, action); } } // start! _addEvent(document, 'keypress', _handleKeyEvent); _addEvent(document, 'keydown', _handleKeyEvent); _addEvent(document, 'keyup', _handleKeyEvent); var Mousetrap = { /** * binds an event to mousetrap * * can be a single key, a combination of keys separated with +, * an array of keys, or a sequence of keys separated by spaces * * be sure to list the modifier keys first to make sure that the * correct key ends up getting bound (the last key in the pattern) * * @param {string|Array} keys * @param {Function} callback * @param {string=} action - 'keypress', 'keydown', or 'keyup' * @returns void */ bind: function(keys, callback, action) { keys = keys instanceof Array ? keys : [keys]; _bindMultiple(keys, callback, action); return this; }, /** * unbinds an event to mousetrap * * the unbinding sets the callback function of the specified key combo * to an empty function and deletes the corresponding key in the * _directMap dict. * * TODO: actually remove this from the _callbacks dictionary instead * of binding an empty function * * the keycombo+action has to be exactly the same as * it was defined in the bind method * * @param {string|Array} keys * @param {string} action * @returns void */ unbind: function(keys, action) { return Mousetrap.bind(keys, function() {}, action); }, /** * triggers an event that has already been bound * * @param {string} keys * @param {string=} action * @returns void */ trigger: function(keys, action) { if (_directMap[keys + ':' + action]) { _directMap[keys + ':' + action]({}, keys); } return this; }, /** * resets the library back to its initial state. this is useful * if you want to clear out the current keyboard shortcuts and bind * new ones - for example if you switch to another page * * @returns void */ reset: function() { _callbacks = {}; _directMap = {}; return this; }, /** * should we stop this event before firing off callbacks * * @param {Event} e * @param {Element} element * @return {boolean} */ stopCallback: function(e, element) { // if the element has the class "mousetrap" then no need to stop if ((' ' + element.className + ' ').indexOf(' mousetrap ') > -1) { return false; } // stop for input, select, and textarea return element.tagName == 'INPUT' || element.tagName == 'SELECT' || element.tagName == 'TEXTAREA' || element.isContentEditable; }, /** * exposes _handleKey publicly so it can be overwritten by extensions */ handleKey: _handleKey }; // expose mousetrap to the global object window.Mousetrap = Mousetrap; // expose mousetrap as an AMD module if (typeof define === 'function' && define.amd) { define(Mousetrap); } }) (window, document); mousetrap-rails-1.4.6/mousetrap-rails.gemspec0000644000076400007640000000312412546466474020423 0ustar pravipravi# -*- encoding: utf-8 -*- lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'mousetrap-rails/version' Gem::Specification.new do |gem| gem.name = "mousetrap-rails" gem.version = Mousetrap::Rails::VERSION gem.authors = "Nick Kugaevsky" gem.email = "nick@kugaevsky.ru" gem.description = %q{Mousetrap is a javascript library for handling keyboard shortcuts in your web applications. This gem integrates Mousetrap with Rails asset pipeline for easy of use.} gem.summary = %q{Integrate Mousetrap javascript library with Rails Asset Pipeline} gem.homepage = "http://kugaevsky.github.com/mousetrap-rails" gem.files = `git ls-files`.split($/) gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = ["lib"] # gem.signing_key = '/Users/nick/.ssh/gem-private_key.pem' gem.cert_chain = ['gem-public_cert.pem'] gem.add_development_dependency 'rails', '~> 3.2.12' gem.add_development_dependency 'sqlite3', '~> 1.3.5' gem.add_development_dependency 'rspec-rails', '~> 2.13.0' gem.add_development_dependency 'genspec', '~> 0.2.7' gem.add_development_dependency 'sass', '~> 3.2.1' gem.add_development_dependency 'coveralls' gem.licenses = ['MIT', 'Apache'] gem.post_install_message = < application.js *= require mousetrap # ---> application.css ``` Voila! Also you can use mousetrap plugins. Require them in your `application.js` file ```javascript //= require mousetrap/plugins # To require all plugins //= require mousetrap/dictionary # To require dictionary plugin //= require mousetrap/global # To require global plugin //= require mousetrap/pause # To require pause plugin //= require mousetrap/record # To require record plugin ``` See plugin descriptions below. ### Latest (may be unstable) version Instead of `gem 'mousetrap-rails'` add to your Gemfile ```ruby gem 'mousetrap-rails', github: 'kugaevsky/mousetrap-rails' ``` `Mousetrap-rails` versioning use `mousetrap.js` library version number. ## Usage ### Via data-attributes You can add keyboard navigation to your links by using `data-keybinding` attribute. ```haml = link_to 'Homepage', root_path, data: { keybinding: 'h' } # Press 'h' to navigate to homepage = link_to 'About', about_path, data: { keybinding: '["a", "c"]' } # Press 'a' or 'c' to navigate to about ``` You can jump to an input ```haml = text_field_tag 'Username', nil, data: { keybinding: 'u' } # Press 'u' to focus username input field ``` ### Via javascript Any javascript function can be called with mousetrap ```coffeescript Mousetrap.bind 'f', (e) -> alert 'My perfect function called' # Press 'f' to popup alert ``` ### More examples (from official guide) ```coffeescript # single keys Mousetrap.bind '4', -> alert '4 pressed!' Mousetrap.bind 'x', (-> alert 'x pressed!'), 'keyup' # combinations Mousetrap.bind 'command+shift+k', -> alert 'command+shift+k pressed!' false Mousetrap.bind ['command+k', 'ctrl+k'], -> alert 'command+k or ctrl+k pressed!' false # gmail style sequences Mousetrap.bind 'g i', -> console.log 'g i sequence pressed!' Mousetrap.bind '* a', -> console.log '* a sequence pressed!' # konami code! Mousetrap.bind 'up up down down left right left right b a enter', -> console.log 'You WIN!' ``` You can find full documentation on [Mousetrap library page](http://craig.is/killing/mice). Really, look there – there are plenty examples of using this awesome library. ### Key binding hints (experimental) You can display key binding hints near links with `data-keybinding` attribute by pressing `Alt+Shift+h`. Now it's just experimental feature for debugging purposes only. ## Plugins ### Global Bindings //= require mousetrap/global # ---> application.js This extension allows you to specify keyboard events that will work anywhere including inside textarea/input fields. ```coffeescript Mousetrap.bindGlobal 'ctrl+s', -> _save() ``` This means that a keyboard event bound using `Mousetrap.bind` will only work outside of form input fields, but using `Moustrap.bindGlobal` will work in both places. ### Bind dictionary //= require mousetrap/dictionary # ---> application.js This extension overwrites the default bind behavior and allows you to bind multiple combinations in a single bind call. Usage looks like: ```coffeescript Mousetrap.bind 'a': -> console.log('a') 'b': -> console.log('b') ``` You can optionally pass in `keypress`, `keydown` or `keyup` as a second argument. Other bind calls work the same way as they do by default. ### Pause/unpause //= require mousetrap/pause # ---> application.js This extension allows Mousetrap to be paused and unpaused without having to reset keyboard shortcuts and rebind them. ```coffeescript # stop Mousetrap events from firing Mousetrap.pause() # allow Mousetrap events to fire again Mousetrap.unpause() ``` ### Record //= require mousetrap/record # ---> application.js This extension lets you use Mousetrap to record keyboard sequences and play them back: ```slim button onclick="recordSequence()" Record ``` ```coffeescript recordSequence = () -> Mousetrap.record (sequence) -> # sequence is an array like ['ctrl+k', 'c'] alert('You pressed: ' + sequence.join(' ')) ```` [More detailed plugins description](http://craig.is/killing/mice#extensions) ## Contributing Please submit all pull requests against latest `*.wip` branch. If your pull request contains new features, you **must** include relevant tests. You can easily update mousetrap.js library via rake tasks. ```bash $ rake mousetrap:update # Update main mousetrap javascript lib and its plugins $ rake mousetrap:update:main # Update main mousetrap javascript lib $ rake mousetrap:update:plugins # Update mousetrap javascript lib plugins ``` Thanks in advance! ## Changelog All changes could be found in [CHANGELOG.md](https://github.com/kugaevsky/mousetrap-rails/blob/master/CHANGELOG.md) ## License Gosh! It's [here](https://github.com/kugaevsky/mousetrap-rails/blob/master/LICENSE.md). ## Authors * mousetrap-rails gem by [Nick Kugaevsky](http://kugaevsky.ru) and [contributors](https://github.com/kugaevsky/mousetrap-rails/graphs/contributors) * original mousetrap library by [Craig Campbell](http://craig.is/) mousetrap-rails-1.4.6/CHANGELOG.md0000644000076400007640000000200212546466474015532 0ustar pravipravi## v0.0.13.wip * update mousetrap.js to 1.4.6 * update readme * add rubinius versions in travis-ci config * add mousetrap/plugins * add mousetrap:update:plugins raketask ## v0.0.12 * minor turbolinks compatibility improvements * fix bug with numbers binding in data attributes * update mousetrap.js to 1.4.5 ## v0.0.11 * add update mousetrap.js rake task * update mousetrap.js to 1.4.4 ## v0.0.10 * update mousetrap.js to 1.4.1 * use Tubolinks.visit for navigating if Turbolinks defined ## v0.0.9 * sign gem with selfsigned certificate * update mousetrap.js to 1.3 ## v0.0.8 * update rspec-rails version development dependency * update mousetrap.js to 1.2.2 ## v0.0.7 * update mousetrap.js to 1.2.1 ## v0.0.6 * update mousetrap.js to 1.2 ## v0.0.5 * update mousetrap.js to 1.1.4 (old Firefox versions support) ## v0.0.4 * add key binding hints (experimental) ## v0.0.3 * add development dependencies * add tests for generators ## v0.0.2 * add rails generator for mousetrap ## v0.0.1 * initial release mousetrap-rails-1.4.6/app/0000755000076400007640000000000012546466474014507 5ustar pravipravimousetrap-rails-1.4.6/app/assets/0000755000076400007640000000000012546466474016011 5ustar pravipravimousetrap-rails-1.4.6/app/assets/stylesheets/0000755000076400007640000000000012546466474020365 5ustar pravipravimousetrap-rails-1.4.6/app/assets/stylesheets/mousetrap.css0000644000076400007640000000165212546466474023122 0ustar pravipravi.mt-hotkey-el { position: relative; } a[data-keybinding] .mt-hotkey-hint { display: block; float: right; position: absolute; top: -4px; right: -4px; z-index: 999; font: bold 13px/1em sans-serif; text-decoration: none; text-indent: 0; text-align: center; vertical-align: center; margin: 0; padding: 0.3ex 0.7ex; background: beige; color: black; text-shadow: 1px 1px 0 white; box-shadow: 1px 1px 0 #333333; border-radius: 5px; border: 1px solid #888888; opacity: 0.75; -webkit-transition: all 0.15s linear; -moz-transition: all 0.15s linear; -o-transition: all 0.15s linear; -ms-transition: all 0.15s linear; transition: all 0.15s linear; } a[data-keybinding] .mt-hotkey-hint:hover { background: white; opacity: 1; -webkit-transform: scale(1.25); -moz-transform: scale(1.25); -o-transform: scale(1.25); -ms-transform: scale(1.25); transform: scale(1.25); } mousetrap-rails-1.4.6/app/assets/stylesheets/mousetrap.css.sass0000644000076400007640000000216512546466474024072 0ustar pravipravi$mtFont: bold 13px/1em sans-serif $mtBackground: beige $mtColor: black $mtTextShadow: 1px 1px 0 white $mtBoxShadow: 1px 1px 0 #333 $mtOpacity: .75 @mixin transition($styles) -webkit-transition: $styles -moz-transition: $styles -o-transition: $styles -ms-transition: $styles transition: $styles @mixin transform($styles) -webkit-transform: $styles -moz-transform: $styles -o-transform: $styles -ms-transform: $styles transform: $styles .mt-hotkey-el position: relative a[data-keybinding] .mt-hotkey-hint display: block float: right position: absolute top: -4px right: -4px z-index: 999 font: $mtFont text-decoration: none text-indent: 0 text-align: center vertical-align: center margin: 0 padding: 0.3ex 0.7ex background: $mtBackground color: $mtColor text-shadow: $mtTextShadow box-shadow: $mtBoxShadow border-radius: 5px border: 1px solid #888 opacity: $mtOpacity @include transition(all .15s linear) &:hover background: white opacity: $mtOpacity + 0.25 @include transform(scale(1.20)) mousetrap-rails-1.4.6/Gemfile0000644000076400007640000000014412546466474015221 0ustar pravipravisource 'https://rubygems.org' # Specify your gem's dependencies in mousetrap-rails.gemspec gemspec mousetrap-rails-1.4.6/metadata.yml0000644000076400007640000001575212546466474016244 0ustar pravipravi--- !ruby/object:Gem::Specification name: mousetrap-rails version: !ruby/object:Gem::Version version: 1.4.6 platform: ruby authors: - Nick Kugaevsky autorequire: bindir: bin cert_chain: - gem-public_cert.pem date: 2013-11-25 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: rails requirement: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: 3.2.12 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: 3.2.12 - !ruby/object:Gem::Dependency name: sqlite3 requirement: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: 1.3.5 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: 1.3.5 - !ruby/object:Gem::Dependency name: rspec-rails requirement: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: 2.13.0 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: 2.13.0 - !ruby/object:Gem::Dependency name: genspec requirement: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: 0.2.7 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: 0.2.7 - !ruby/object:Gem::Dependency name: sass requirement: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: 3.2.1 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: 3.2.1 - !ruby/object:Gem::Dependency name: coveralls requirement: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' description: Mousetrap is a javascript library for handling keyboard shortcuts in your web applications. This gem integrates Mousetrap with Rails asset pipeline for easy of use. email: nick@kugaevsky.ru executables: [] extensions: [] extra_rdoc_files: [] files: - .gitignore - .travis.yml - CHANGELOG.md - Gemfile - LICENSE.md - README.md - Rakefile - app/assets/stylesheets/mousetrap.css - app/assets/stylesheets/mousetrap.css.sass - gem-public_cert.pem - lib/generators/mousetrap/install/USAGE - lib/generators/mousetrap/install/install_generator.rb - lib/generators/mousetrap/install/templates/application.css - lib/generators/mousetrap/install/templates/application.js - lib/generators/mousetrap/install/templates/keybindings.js.coffee - lib/mousetrap-rails.rb - lib/mousetrap-rails/engine.rb - lib/mousetrap-rails/railtie.rb - lib/mousetrap-rails/version.rb - mousetrap-rails.gemspec - spec/dummy/.rspec - spec/dummy/README.rdoc - spec/dummy/Rakefile - spec/dummy/app/assets/javascripts/application.js - spec/dummy/app/assets/stylesheets/application.css - spec/dummy/app/controllers/application_controller.rb - spec/dummy/app/helpers/application_helper.rb - spec/dummy/app/mailers/.gitkeep - spec/dummy/app/models/.gitkeep - spec/dummy/app/views/layouts/application.html.erb - spec/dummy/config.ru - spec/dummy/config/application.rb - spec/dummy/config/boot.rb - spec/dummy/config/database.yml - spec/dummy/config/environment.rb - spec/dummy/config/environments/development.rb - spec/dummy/config/environments/production.rb - spec/dummy/config/environments/test.rb - spec/dummy/config/initializers/backtrace_silencers.rb - spec/dummy/config/initializers/inflections.rb - spec/dummy/config/initializers/mime_types.rb - spec/dummy/config/initializers/secret_token.rb - spec/dummy/config/initializers/session_store.rb - spec/dummy/config/initializers/wrap_parameters.rb - spec/dummy/config/locales/en.yml - spec/dummy/config/routes.rb - spec/dummy/db/test.sqlite3 - spec/dummy/lib/assets/.gitkeep - spec/dummy/log/.gitkeep - spec/dummy/log/development.log - spec/dummy/public/404.html - spec/dummy/public/422.html - spec/dummy/public/500.html - spec/dummy/public/favicon.ico - spec/dummy/script/rails - spec/generators/install_generator_spec.rb - spec/spec_helper.rb - vendor/assets/javascripts/mousetrap.js - vendor/assets/javascripts/mousetrap/dictionary.js - vendor/assets/javascripts/mousetrap/global.js - vendor/assets/javascripts/mousetrap/pause.js - vendor/assets/javascripts/mousetrap/plugins.js - vendor/assets/javascripts/mousetrap/record.js homepage: http://kugaevsky.github.com/mousetrap-rails licenses: - MIT - Apache metadata: {} post_install_message: "\n\e[33mRemember to run generator to generate sample file and include mousetrap-rails with Rails Asset Pipeline\e[0m\n\n \e[32m$ rails generate mousetrap:install \e[0m\n\n" rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 2.1.11 signing_key: specification_version: 4 summary: Integrate Mousetrap javascript library with Rails Asset Pipeline test_files: - spec/dummy/.rspec - spec/dummy/README.rdoc - spec/dummy/Rakefile - spec/dummy/app/assets/javascripts/application.js - spec/dummy/app/assets/stylesheets/application.css - spec/dummy/app/controllers/application_controller.rb - spec/dummy/app/helpers/application_helper.rb - spec/dummy/app/mailers/.gitkeep - spec/dummy/app/models/.gitkeep - spec/dummy/app/views/layouts/application.html.erb - spec/dummy/config.ru - spec/dummy/config/application.rb - spec/dummy/config/boot.rb - spec/dummy/config/database.yml - spec/dummy/config/environment.rb - spec/dummy/config/environments/development.rb - spec/dummy/config/environments/production.rb - spec/dummy/config/environments/test.rb - spec/dummy/config/initializers/backtrace_silencers.rb - spec/dummy/config/initializers/inflections.rb - spec/dummy/config/initializers/mime_types.rb - spec/dummy/config/initializers/secret_token.rb - spec/dummy/config/initializers/session_store.rb - spec/dummy/config/initializers/wrap_parameters.rb - spec/dummy/config/locales/en.yml - spec/dummy/config/routes.rb - spec/dummy/db/test.sqlite3 - spec/dummy/lib/assets/.gitkeep - spec/dummy/log/.gitkeep - spec/dummy/log/development.log - spec/dummy/public/404.html - spec/dummy/public/422.html - spec/dummy/public/500.html - spec/dummy/public/favicon.ico - spec/dummy/script/rails - spec/generators/install_generator_spec.rb - spec/spec_helper.rb mousetrap-rails-1.4.6/lib/0000755000076400007640000000000012546466474014475 5ustar pravipravimousetrap-rails-1.4.6/lib/mousetrap-rails/0000755000076400007640000000000012546466474017624 5ustar pravipravimousetrap-rails-1.4.6/lib/mousetrap-rails/railtie.rb0000644000076400007640000000012712546466474021602 0ustar pravipravimodule Mousetrap module Rails class Railtie < ::Rails::Railtie end end end mousetrap-rails-1.4.6/lib/mousetrap-rails/version.rb0000644000076400007640000000010012546466474021625 0ustar pravipravimodule Mousetrap module Rails VERSION = "1.4.6" end end mousetrap-rails-1.4.6/lib/mousetrap-rails/engine.rb0000644000076400007640000000012512546466474021414 0ustar pravipravimodule Mousetrap module Rails class Engine < ::Rails::Engine end end end mousetrap-rails-1.4.6/lib/mousetrap-rails.rb0000644000076400007640000000047112546466474020153 0ustar pravipravirequire "mousetrap-rails/version" # Mousetrap main module module Mousetrap # Mousetrap rails module # Require railtie or engine depending of rails version module Rails if ::Rails.version < "3.1" require "mousetrap-rails/railtie" else require "mousetrap-rails/engine" end end end mousetrap-rails-1.4.6/lib/generators/0000755000076400007640000000000012546466474016646 5ustar pravipravimousetrap-rails-1.4.6/lib/generators/mousetrap/0000755000076400007640000000000012546466474020665 5ustar pravipravimousetrap-rails-1.4.6/lib/generators/mousetrap/install/0000755000076400007640000000000012546466474022333 5ustar pravipravimousetrap-rails-1.4.6/lib/generators/mousetrap/install/install_generator.rb0000644000076400007640000000260212546466474026374 0ustar pravipravimodule Mousetrap # Mousetrap rails generators module module Generators # Install generator implementation class InstallGenerator < ::Rails::Generators::Base desc "Copy Mousetrap default files" source_root File.expand_path('../templates', __FILE__) # Copy keybindings scripts to assets folder. This coffescript file # provides unobtrusive way to use HTML5 data attributes for # binding click and focus events to DOM elements. def copy_mousetrap copy_file "keybindings.js.coffee", "app/assets/javascripts/keybindings.js.coffee" end # Inject mousetrap scripts to manifest file `application.js` def add_javascript_assets if File.exist?('app/assets/javascripts/application.js') insert_into_file "app/assets/javascripts/application.js", "//= require mousetrap\n", :after => "jquery_ujs\n" else copy_file "application.js", "app/assets/javascripts/application.js" end end # Inject mousetrap styles to manifest file `application.css` def add_css_assets if File.exist?('app/assets/stylesheets/application.css') insert_into_file "app/assets/stylesheets/application.css", "*= require mousetrap\n ", :before => "*= require_tree ." else copy_file "application.css", "app/assets/stylesheets/application.css" end end end end end mousetrap-rails-1.4.6/lib/generators/mousetrap/install/USAGE0000644000076400007640000000055412546466474023126 0ustar pravipraviDescription: Mousetrap generator installs mousetrap javascript library in your Rails application Example: rails generate mousetrap:install This will: Create `keybindings.js.coffee' file in your `app/assets/javascripts' directory And add `//= require mousetrap' line to `application.js' file to include library to Rails Asset Pipeline mousetrap-rails-1.4.6/lib/generators/mousetrap/install/templates/0000755000076400007640000000000012546466474024331 5ustar pravipravimousetrap-rails-1.4.6/lib/generators/mousetrap/install/templates/keybindings.js.coffee0000644000076400007640000000365612546466474030435 0ustar pravipravi$ -> handleKeyBindings() $(document).on 'page:change', -> handleKeyBindings() handleKeyBindings = -> # As turbolinks does not refresh the page, some old keybindings could be still present. Therefore a reset is required. Mousetrap.reset() # Hotkey binding to links with 'data-keybinding' attribute # Navigate link when hotkey pressed $('a[data-keybinding]').each (i, el) -> bindedKey = $(el).data('keybinding') bindedKey = bindedKey.toString() if typeof(bindedKey) == 'number' Mousetrap.bind bindedKey, (e) -> if typeof(Turbolinks) == 'undefined' # Emulate click if turbolinks defined el.click() else # Use turbolinks to go to URL Turbolinks.visit(el.href) # Hotkey binding to inputs with 'data-keybinding' attribute # Focus input when hotkey pressed $('input[data-keybinding]').each (i, el) -> Mousetrap.bind $(el).data('keybinding'), (e) -> el.focus() if e.preventDefault e.preventDefault() else e.returnValue = false # Toggle show/hide hotkey hints window.mouseTrapRails = showOnLoad: false # Show/hide hotkey hints by default (on page load). Mostly for debugging purposes. toggleKeys: 'alt+shift+h' # Keys combo to toggle hints visibility. keysShown: false # State of hotkey hints toggleHints: -> $('a[data-keybinding]').each (i, el) -> $el = $(el) if mouseTrapRails.keysShown $el.removeClass('mt-hotkey-el').find('.mt-hotkey-hint').remove() else mtKey = $el.data('keybinding') $hint = "#{mtKey}" $el.addClass('mt-hotkey-el') unless $el.css('position') is 'absolute' $el.append $hint @keysShown ^= true Mousetrap.bind mouseTrapRails.toggleKeys, -> mouseTrapRails.toggleHints() mouseTrapRails.toggleHints() if mouseTrapRails.showOnLoad mousetrap-rails-1.4.6/lib/generators/mousetrap/install/templates/application.js0000644000076400007640000000074512546466474027200 0ustar pravipravi// This is a manifest file that'll be compiled into including all the files listed below. // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically // be included in the compiled file accessible from http://example.com/assets/application.js // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // the compiled file. // //= require jquery //= require jquery_ujs //= require mousetrap //= require_tree . mousetrap-rails-1.4.6/lib/generators/mousetrap/install/templates/application.css0000644000076400007640000000107012546466474027344 0ustar pravipravi/* * This is a manifest file that'll be compiled into application.css, which will include all the files * listed below. * * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. * * You're free to add application-wide styles to this file and they'll appear at the top of the * compiled file, but it's generally better to create a new file per style scope. * *= require_self *= require mousetrap *= require_tree . */ mousetrap-rails-1.4.6/Rakefile0000644000076400007640000000271212546466474015376 0ustar pravipravirequire "bundler/gem_tasks" require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) task :default => :spec ORIGIN_URL = "https://raw.github.com/ccampbell/mousetrap/master" BASE_FILE_PATH = "vendor/assets/javascripts" namespace :mousetrap do desc "Update main mousetrap javascript lib and its plugins" task :update do %w(main plugins).each do |task| Rake::Task["mousetrap:update:#{task}"].invoke end end namespace :update do desc "Update main mousetrap javascript lib" task :main do origin_url = "#{ORIGIN_URL}/mousetrap.js" file_path = "#{BASE_FILE_PATH}/mousetrap.js" download origin_url, file_path puts "\033[32m-> Main mousetrap lib updated!\033[0m\n\n" end desc "Update mousetrap javascript lib plugins" task :plugins do plugins = { dictionary: 'plugins/bind-dictionary/mousetrap-bind-dictionary.js', global: 'plugins/global-bind/mousetrap-global-bind.js', pause: 'plugins/pause/mousetrap-pause.js', record: 'plugins/record/mousetrap-record.js' } plugins.each_pair do |name, file| origin_url = "#{ORIGIN_URL}/#{file}" file_path = "#{BASE_FILE_PATH}/mousetrap/#{name}.js" download origin_url, file_path puts "\033[32m-> #{name} mousetrap plugin updated!\033[0m\n\n" end end end end def download(source, dest) system 'wget', source, "-O", dest end mousetrap-rails-1.4.6/.gitignore0000644000076400007640000000031612546466474015717 0ustar pravipravi*.gem *.rbc .bundle .config .yardoc .rvmrc .ruby-gemset .ruby-version Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp *.log .sass-cache