specific_assets 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +102 -0
- data/LICENSE.txt +20 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +48 -0
- data/Rakefile +36 -0
- data/VERSION +1 -0
- data/lib/specific_assets.rb +2 -0
- data/lib/specific_assets/engine.rb +13 -0
- data/lib/specific_assets/specific_assets.rb +83 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +45 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +22 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +26 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +35 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +0 -0
- data/spec/dummy/log/production.log +0 -0
- data/spec/dummy/log/server.log +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/javascripts/application.js +2 -0
- data/spec/dummy/public/javascripts/controls.js +965 -0
- data/spec/dummy/public/javascripts/dragdrop.js +974 -0
- data/spec/dummy/public/javascripts/effects.js +1123 -0
- data/spec/dummy/public/javascripts/prototype.js +6001 -0
- data/spec/dummy/public/javascripts/rails.js +202 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/lib/specific_assets_spec.rb +32 -0
- data/spec/spec_helper.rb +28 -0
- data/specific_assets.gemspec +103 -0
- metadata +196 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rdoc", "~> 3.12"
|
10
|
+
gem "bundler", "~> 1.1.3"
|
11
|
+
gem "jeweler", "~> 1.8.3"
|
12
|
+
gem "rails", "3.0.12"
|
13
|
+
gem "sqlite3"
|
14
|
+
gem "rspec-rails", ">= 2.0.0.beta"
|
15
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
actionmailer (3.0.12)
|
6
|
+
actionpack (= 3.0.12)
|
7
|
+
mail (~> 2.2.19)
|
8
|
+
actionpack (3.0.12)
|
9
|
+
activemodel (= 3.0.12)
|
10
|
+
activesupport (= 3.0.12)
|
11
|
+
builder (~> 2.1.2)
|
12
|
+
erubis (~> 2.6.6)
|
13
|
+
i18n (~> 0.5.0)
|
14
|
+
rack (~> 1.2.5)
|
15
|
+
rack-mount (~> 0.6.14)
|
16
|
+
rack-test (~> 0.5.7)
|
17
|
+
tzinfo (~> 0.3.23)
|
18
|
+
activemodel (3.0.12)
|
19
|
+
activesupport (= 3.0.12)
|
20
|
+
builder (~> 2.1.2)
|
21
|
+
i18n (~> 0.5.0)
|
22
|
+
activerecord (3.0.12)
|
23
|
+
activemodel (= 3.0.12)
|
24
|
+
activesupport (= 3.0.12)
|
25
|
+
arel (~> 2.0.10)
|
26
|
+
tzinfo (~> 0.3.23)
|
27
|
+
activeresource (3.0.12)
|
28
|
+
activemodel (= 3.0.12)
|
29
|
+
activesupport (= 3.0.12)
|
30
|
+
activesupport (3.0.12)
|
31
|
+
arel (2.0.10)
|
32
|
+
builder (2.1.2)
|
33
|
+
diff-lcs (1.1.3)
|
34
|
+
erubis (2.6.6)
|
35
|
+
abstract (>= 1.0.0)
|
36
|
+
git (1.2.5)
|
37
|
+
i18n (0.5.0)
|
38
|
+
jeweler (1.8.3)
|
39
|
+
bundler (~> 1.0)
|
40
|
+
git (>= 1.2.5)
|
41
|
+
rake
|
42
|
+
rdoc
|
43
|
+
json (1.6.6)
|
44
|
+
mail (2.2.19)
|
45
|
+
activesupport (>= 2.3.6)
|
46
|
+
i18n (>= 0.4.0)
|
47
|
+
mime-types (~> 1.16)
|
48
|
+
treetop (~> 1.4.8)
|
49
|
+
mime-types (1.18)
|
50
|
+
polyglot (0.3.3)
|
51
|
+
rack (1.2.5)
|
52
|
+
rack-mount (0.6.14)
|
53
|
+
rack (>= 1.0.0)
|
54
|
+
rack-test (0.5.7)
|
55
|
+
rack (>= 1.0)
|
56
|
+
rails (3.0.12)
|
57
|
+
actionmailer (= 3.0.12)
|
58
|
+
actionpack (= 3.0.12)
|
59
|
+
activerecord (= 3.0.12)
|
60
|
+
activeresource (= 3.0.12)
|
61
|
+
activesupport (= 3.0.12)
|
62
|
+
bundler (~> 1.0)
|
63
|
+
railties (= 3.0.12)
|
64
|
+
railties (3.0.12)
|
65
|
+
actionpack (= 3.0.12)
|
66
|
+
activesupport (= 3.0.12)
|
67
|
+
rake (>= 0.8.7)
|
68
|
+
rdoc (~> 3.4)
|
69
|
+
thor (~> 0.14.4)
|
70
|
+
rake (0.9.2.2)
|
71
|
+
rdoc (3.12)
|
72
|
+
json (~> 1.4)
|
73
|
+
rspec (2.9.0)
|
74
|
+
rspec-core (~> 2.9.0)
|
75
|
+
rspec-expectations (~> 2.9.0)
|
76
|
+
rspec-mocks (~> 2.9.0)
|
77
|
+
rspec-core (2.9.0)
|
78
|
+
rspec-expectations (2.9.1)
|
79
|
+
diff-lcs (~> 1.1.3)
|
80
|
+
rspec-mocks (2.9.0)
|
81
|
+
rspec-rails (2.9.0)
|
82
|
+
actionpack (>= 3.0)
|
83
|
+
activesupport (>= 3.0)
|
84
|
+
railties (>= 3.0)
|
85
|
+
rspec (~> 2.9.0)
|
86
|
+
sqlite3 (1.3.6)
|
87
|
+
thor (0.14.6)
|
88
|
+
treetop (1.4.10)
|
89
|
+
polyglot
|
90
|
+
polyglot (>= 0.3.1)
|
91
|
+
tzinfo (0.3.33)
|
92
|
+
|
93
|
+
PLATFORMS
|
94
|
+
ruby
|
95
|
+
|
96
|
+
DEPENDENCIES
|
97
|
+
bundler (~> 1.1.3)
|
98
|
+
jeweler (~> 1.8.3)
|
99
|
+
rails (= 3.0.12)
|
100
|
+
rdoc (~> 3.12)
|
101
|
+
rspec-rails (>= 2.0.0.beta)
|
102
|
+
sqlite3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Roman Snitko
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
specific_assets
|
2
|
+
======
|
3
|
+
|
4
|
+
*Rails extension to easily add custom css and js in controllers and views*
|
5
|
+
|
6
|
+
Why do you need this?
|
7
|
+
------------------------
|
8
|
+
Ever needed to add different css and js to different pages of the website, but felt that
|
9
|
+
creating a new layout would be an overkill?
|
10
|
+
|
11
|
+
Now you can just say:
|
12
|
+
|
13
|
+
add_css "registration", "some_other_fancy_stuff"
|
14
|
+
add_js "registration"
|
15
|
+
|
16
|
+
and you'll get respective css and js files included into the page.
|
17
|
+
|
18
|
+
INSTALLATION
|
19
|
+
------------
|
20
|
+
|
21
|
+
gem install specific_assets
|
22
|
+
|
23
|
+
Usage
|
24
|
+
---------------
|
25
|
+
|
26
|
+
First, you should add this to your layout:
|
27
|
+
|
28
|
+
js_assets.each { |js| javascript_include_tag(js) }
|
29
|
+
css_assets.each { |css| stylesheet_link_tag(css) }
|
30
|
+
|
31
|
+
Now you're ready to use `#add_js` and `#add_css` methods. Those methods are available as helpers in views, and both as instance and class methods in controllers. If class methods are used, then assets will be added for all the actions in the controller.
|
32
|
+
|
33
|
+
Usage examples:
|
34
|
+
|
35
|
+
class UsersController < ApplicationController
|
36
|
+
|
37
|
+
add_css "users"
|
38
|
+
add_js "users"
|
39
|
+
|
40
|
+
def new
|
41
|
+
add_css "new_user"
|
42
|
+
end
|
43
|
+
|
44
|
+
def show
|
45
|
+
add_js "user_profile", "user_animations"
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "specific_assets"
|
18
|
+
gem.homepage = "http://github.com/snitko/specific_assets"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = "Easily add css and js assets in controllers and views"
|
21
|
+
gem.description = "Adds a couple of class and instance methods to controllers and views that help you load assets"
|
22
|
+
gem.email = "roman.snitko@gmail.com"
|
23
|
+
gem.authors = ["Roman Snitko"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rdoc/task'
|
29
|
+
Rake::RDocTask.new do |rdoc|
|
30
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
31
|
+
|
32
|
+
rdoc.rdoc_dir = 'rdoc'
|
33
|
+
rdoc.title = "specific_assets #{version}"
|
34
|
+
rdoc.rdoc_files.include('README*')
|
35
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
36
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module SpecificAssets
|
2
|
+
|
3
|
+
module InstanceMethods
|
4
|
+
|
5
|
+
def add_js(*asset_name)
|
6
|
+
@js_specific += asset_name
|
7
|
+
end
|
8
|
+
|
9
|
+
def add_css(*asset_name)
|
10
|
+
@css_specific += asset_name
|
11
|
+
end
|
12
|
+
|
13
|
+
# This method is called in view to include all js assets:
|
14
|
+
# js_assets.each { |js| javascript_include_tag(js) }
|
15
|
+
def js_assets
|
16
|
+
unless self.class.js_specific.nil?
|
17
|
+
(filter_class_assets("js") + @js_specific).uniq
|
18
|
+
else
|
19
|
+
@js_specific
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# This method is called in view to include all css assets:
|
24
|
+
# css_assets.each { |css| stylesheet_link_tag(css) }
|
25
|
+
def css_assets
|
26
|
+
unless self.class.css_specific.nil?
|
27
|
+
(filter_class_assets("css") + @css_specific).uniq
|
28
|
+
else
|
29
|
+
@css_specific
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def initialize_assets
|
34
|
+
@js_specific ||= []
|
35
|
+
@css_specific ||= []
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
# Because assets end up being collected in a class variable
|
41
|
+
# assets from other controllers usually end up in the controller
|
42
|
+
# that has nothing to do with them. This method filters assets
|
43
|
+
# and returns the ones which are relevant to the current controller.
|
44
|
+
def filter_class_assets(asset_type)
|
45
|
+
self.class.send("#{asset_type}_specific").map { |a| a[:controller] == self.class.to_s ? a[:asset] : nil }.compact
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
module ClassMethods
|
51
|
+
|
52
|
+
def add_js(*assets)
|
53
|
+
self.js_specific = [] if js_specific.nil?
|
54
|
+
# Storing current controller name in the key
|
55
|
+
self.js_specific = js_specific + label_assets_with_controller_name(assets)
|
56
|
+
end
|
57
|
+
|
58
|
+
def add_css(*assets)
|
59
|
+
self.css_specific = [] if self.css_specific.nil?
|
60
|
+
# Storing current controller name in the key
|
61
|
+
self.css_specific = self.css_specific + label_assets_with_controller_name(assets)
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def label_assets_with_controller_name(assets)
|
67
|
+
assets.map! { |a| { :controller => self.to_s, :asset => a } }
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
def self.included(base)
|
74
|
+
base.extend ClassMethods
|
75
|
+
base.class_eval do
|
76
|
+
include InstanceMethods
|
77
|
+
cattr_accessor :js_specific, :css_specific
|
78
|
+
helper_method :add_js, :add_css, :js_assets, :css_assets
|
79
|
+
before_filter :initialize_assets
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
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
|
+
require 'rake'
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require "active_model/railtie"
|
4
|
+
require "active_record/railtie"
|
5
|
+
require "action_controller/railtie"
|
6
|
+
require "action_view/railtie"
|
7
|
+
require "action_mailer/railtie"
|
8
|
+
|
9
|
+
Bundler.require
|
10
|
+
require "specific_assets"
|
11
|
+
|
12
|
+
module Dummy
|
13
|
+
class Application < Rails::Application
|
14
|
+
# Settings in config/environments/* take precedence over those specified here.
|
15
|
+
# Application configuration should go into files in config/initializers
|
16
|
+
# -- all .rb files in that directory are automatically loaded.
|
17
|
+
|
18
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
19
|
+
# config.autoload_paths += %W(#{config.root}/extras)
|
20
|
+
|
21
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
22
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
23
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
24
|
+
|
25
|
+
# Activate observers that should always be running.
|
26
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
27
|
+
|
28
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
29
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
30
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
31
|
+
|
32
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
33
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
34
|
+
# config.i18n.default_locale = :de
|
35
|
+
|
36
|
+
# JavaScript files you want as :defaults (application.js is always included).
|
37
|
+
# config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
|
38
|
+
|
39
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
40
|
+
config.encoding = "utf-8"
|
41
|
+
|
42
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
43
|
+
config.filter_parameters += [:password]
|
44
|
+
end
|
45
|
+
end
|