javascript_auto_include 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'actionpack', '>= 3.0.0', :require => 'action_pack'
4
+
5
+ group :development do
6
+ gem "bundler", "~> 1.0.0"
7
+ gem "jeweler", "~> 1.5.2"
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionpack (3.0.3)
6
+ activemodel (= 3.0.3)
7
+ activesupport (= 3.0.3)
8
+ builder (~> 2.1.2)
9
+ erubis (~> 2.6.6)
10
+ i18n (~> 0.4)
11
+ rack (~> 1.2.1)
12
+ rack-mount (~> 0.6.13)
13
+ rack-test (~> 0.5.6)
14
+ tzinfo (~> 0.3.23)
15
+ activemodel (3.0.3)
16
+ activesupport (= 3.0.3)
17
+ builder (~> 2.1.2)
18
+ i18n (~> 0.4)
19
+ activesupport (3.0.3)
20
+ builder (2.1.2)
21
+ erubis (2.6.6)
22
+ abstract (>= 1.0.0)
23
+ git (1.2.5)
24
+ i18n (0.4.2)
25
+ jeweler (1.5.2)
26
+ bundler (~> 1.0.0)
27
+ git (>= 1.2.5)
28
+ rake
29
+ rack (1.2.1)
30
+ rack-mount (0.6.13)
31
+ rack (>= 1.0.0)
32
+ rack-test (0.5.7)
33
+ rack (>= 1.0)
34
+ rake (0.8.7)
35
+ tzinfo (0.3.24)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ actionpack (>= 3.0.0)
42
+ bundler (~> 1.0.0)
43
+ jeweler (~> 1.5.2)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Ulf Möhring <hello@ulfmoehring.net>
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,42 @@
1
+ # Automatically include controller/action-specific javascript files
2
+
3
+ `javascript_auto_include` provides basic helper methods for automatically including javascript files into your Rails 3 templates, based on a controller/action pattern. I found this to be a convenient way of avoiding countless content_fors in your views when trying to keep your javascripts unobtrusive.
4
+
5
+ ## Install
6
+
7
+ Should be as easy as:
8
+
9
+ $ gem install javascript_auto_include
10
+
11
+ Or in your Gemfile:
12
+
13
+ $ gem 'javascript_auto_include', '~> 0.1.0'
14
+
15
+ ## Usage
16
+
17
+ Put in your layout's head just like you would with javascript_include_tag
18
+
19
+ ### Basic
20
+
21
+ <%= javascript_auto_include_tag :defaults %>
22
+
23
+ ... will insert the default javascripts (just like `javascript_include_tag`) and also look for an action-specifc javascript file at public/javascripts/:controller/:action.js. If it exists, it will be included as well.
24
+
25
+ ### With custom pattern
26
+
27
+ <%= javascript_auto_include_tag :defaults, :pattern => ':controller_:action.js' %>
28
+
29
+ ... will work just like shown above but alter the search path according to the supplied pattern: public/javascripts/:controller_:action.js (e.g. public/javascripts/album_new.js)
30
+
31
+ ### Compatibility
32
+
33
+ `javascript_auto_include_tag` uses Rails' `javascript_include_tag` helper and passes on all options (:concat, :cache, ...) and keys (:defaults, :all, ...) supplied.
34
+
35
+ ## TODO
36
+
37
+ I just extracted this from a current project. It still lacks specs and testing but so far it seems to work for me.
38
+
39
+ ## Copyright
40
+
41
+ Copyright (c) 2011 Ulf Möhring <hello@ulfmoehring.net>. See LICENSE.txt for
42
+ further details.
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+ require 'rake'
12
+
13
+ require 'jeweler'
14
+ Jeweler::Tasks.new do |gem|
15
+ gem.name = "javascript_auto_include"
16
+ gem.homepage = "http://github.com/paceline/javascript_auto_include"
17
+ gem.license = "MIT"
18
+ gem.summary = "Rails helper for automatically including javascript files"
19
+ gem.description = "Rails helper for automatically including javascript files. Looks up assets in public/javascripts based on the current controller/action pair."
20
+ gem.email = "hello@ulfmoehring.net"
21
+ gem.authors = ["Ulf Moehring"]
22
+ gem.add_runtime_dependency 'actionpack', '>= 3.0.0'
23
+ end
24
+ Jeweler::RubygemsDotOrgTasks.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,60 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{javascript_auto_include}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ulf Moehring"]
12
+ s.date = %q{2011-01-15}
13
+ s.description = %q{Rails helper for automatically including javascript files. Looks up assets in public/javascripts based on the current controller/action pair.}
14
+ s.email = %q{hello@ulfmoehring.net}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.markdown",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "javascript_auto_include.gemspec",
28
+ "lib/javascript_auto_include.rb",
29
+ "lib/javascript_auto_include/helpers/action_controller.rb",
30
+ "lib/javascript_auto_include/helpers/action_view.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/paceline/javascript_auto_include}
33
+ s.licenses = ["MIT"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.7}
36
+ s.summary = %q{Rails helper for automatically including javascript files}
37
+
38
+ if s.respond_to? :specification_version then
39
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_runtime_dependency(%q<actionpack>, [">= 3.0.0"])
44
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
45
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
46
+ s.add_runtime_dependency(%q<actionpack>, [">= 3.0.0"])
47
+ else
48
+ s.add_dependency(%q<actionpack>, [">= 3.0.0"])
49
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
50
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
51
+ s.add_dependency(%q<actionpack>, [">= 3.0.0"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<actionpack>, [">= 3.0.0"])
55
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
57
+ s.add_dependency(%q<actionpack>, [">= 3.0.0"])
58
+ end
59
+ end
60
+
@@ -0,0 +1,17 @@
1
+ module JavascriptAutoInclude
2
+ module Helpers
3
+ # = ActionController helpers
4
+ #
5
+ # This module makes sure that the current controller and action are available as
6
+ # public variables and thus accessible for the view helper.
7
+ #
8
+ module ActionController
9
+
10
+ def identify_controller_and_action #:nodoc:
11
+ $CONTROLLER = request.parameters[:controller]
12
+ $ACTION = request.parameters[:action]
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,42 @@
1
+ module JavascriptAutoInclude
2
+ module Helpers
3
+ # = ActionView helpers
4
+ #
5
+ # This module contains the helper +javascript_auto_include_tag+, which inserts the javascript
6
+ # include tag(s) into a view.
7
+ #
8
+ # == Basic usage
9
+ #
10
+ # <%= javascript_auto_include_tag :defaults %>
11
+ #
12
+ # ... will insert the default javascripts (just like javascript_include_tag) and also look for an
13
+ # action-specifc javascript file at public/javascripts/:controller/:action.js. If it exists, it will
14
+ # be included as well.
15
+ #
16
+ # == Using your own pattern
17
+ #
18
+ # <%= javascript_auto_include_tag :defaults, :pattern => ':controller_:action.js' %>
19
+ #
20
+ # ... will work just like shown above but alter the search path according to the supplied pattern:
21
+ # public/javascripts/:controller_:action.js (e.g. public/javascripts/album_new.js)
22
+ #
23
+ # == Compatibility
24
+ #
25
+ # +javascript_auto_include_tag+ uses Rails' javascript_include_tag helper and passes on all options
26
+ # (:concat, :cache, ...) and keys (:defaults, :all, ...) supplied
27
+ #
28
+ module ActionView
29
+
30
+ def javascript_auto_include_tag(*sources) #:nodoc:
31
+ options = sources.extract_options!.stringify_keys
32
+ pattern = options.key?("pattern") ? options.delete("pattern") : ":controller#{File::SEPARATOR}:action"
33
+
34
+ auto_javascript_file = pattern.sub(":controller",$CONTROLLER).sub(":action",$ACTION) + ".js"
35
+
36
+ sources << auto_javascript_file if File.exists?(Rails.root.join('public','javascripts',auto_javascript_file))
37
+ javascript_include_tag(*sources << options)
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,14 @@
1
+ module JavascriptAutoInclude
2
+ class Railtie < Rails::Railtie
3
+ initializer "javascript_auto_include.action_controller" do |app|
4
+ require 'javascript_auto_include/helpers/action_controller'
5
+ ActionController::Base.send(:include, JavascriptAutoInclude::Helpers::ActionController)
6
+ ActionController::Base.send(:before_filter, :identify_controller_and_action)
7
+ end
8
+
9
+ initializer "javascript_auto_include.action_view" do |app|
10
+ require 'javascript_auto_include/helpers/action_view'
11
+ ActionView::Base.send(:include, JavascriptAutoInclude::Helpers::ActionView)
12
+ end
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: javascript_auto_include
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Ulf Moehring
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-15 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: actionpack
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 3
29
+ - 0
30
+ - 0
31
+ version: 3.0.0
32
+ type: :runtime
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: bundler
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 1
44
+ - 0
45
+ - 0
46
+ version: 1.0.0
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: jeweler
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 1
59
+ - 5
60
+ - 2
61
+ version: 1.5.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: actionpack
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 3
74
+ - 0
75
+ - 0
76
+ version: 3.0.0
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *id004
80
+ description: Rails helper for automatically including javascript files. Looks up assets in public/javascripts based on the current controller/action pair.
81
+ email: hello@ulfmoehring.net
82
+ executables: []
83
+
84
+ extensions: []
85
+
86
+ extra_rdoc_files:
87
+ - LICENSE.txt
88
+ - README.markdown
89
+ files:
90
+ - .document
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - LICENSE.txt
94
+ - README.markdown
95
+ - Rakefile
96
+ - VERSION
97
+ - javascript_auto_include.gemspec
98
+ - lib/javascript_auto_include.rb
99
+ - lib/javascript_auto_include/helpers/action_controller.rb
100
+ - lib/javascript_auto_include/helpers/action_view.rb
101
+ has_rdoc: true
102
+ homepage: http://github.com/paceline/javascript_auto_include
103
+ licenses:
104
+ - MIT
105
+ post_install_message:
106
+ rdoc_options: []
107
+
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ hash: -1711570610507802495
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ segments:
125
+ - 0
126
+ version: "0"
127
+ requirements: []
128
+
129
+ rubyforge_project:
130
+ rubygems_version: 1.3.7
131
+ signing_key:
132
+ specification_version: 3
133
+ summary: Rails helper for automatically including javascript files
134
+ test_files: []
135
+