Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… 581f9dff-63f6-4202-9a23-85763b9ce6d8
  • Loading branch information
jamied committed Feb 15, 2008
0 parents commit d121504
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 0 deletions.
41 changes: 41 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
JavascriptAutoInclude
=====================

== Resources

Install
* Run the following command:
script/plugin install http://kernowsoul.com/svn/plugins/javascript_auto_include

== Usage

Add the following to the head of your template file

<%= javascript_auto_include_tags %>

Now each time the template is loaded javascript files in the public/javascripts/views
folder that correspond to the name of the current controller or view will be auto
loaded. For example:

/public
/javascripts
/views
users.js
/users
edit.js
roles.js
/accounts
show.js

Assuming the above file structure loading each of the following urls would load:

mydomain.com/users # loads users.js
mydomain.com/users/edit/1 # loads users.js and edit.js
mydomain.com/users/show/1 # loads users.js
mydomain.com/roles # loads roles.js
mydomain.com/accounts # no js files loaded
mydomain.com/accounts/show/1 # loads show.js

== More

http://hosting.media72.co.uk/blog/
22 changes: 22 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

desc 'Default: run unit tests.'
task :default => :test

desc 'Test the javascript_auto_include plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

desc 'Generate documentation for the javascript_auto_include plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'JavascriptAutoInclude'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end
1 change: 1 addition & 0 deletions init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'javascript_auto_include'
3 changes: 3 additions & 0 deletions install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'fileutils'

FileUtils.mkdir File.dirname(__FILE__) + '/../../../public/views'
13 changes: 13 additions & 0 deletions lib/javascript_auto_include.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module ActionView
module Helpers
module AssetTagHelper
def javascript_auto_include_tags
js_path = "#{RAILS_ROOT}/public/javascripts/views"
if File.directory? js_path
paths = [controller.controller_name, File.join(controller.controller_name, controller.action_name)]
paths.collect { |source| javascript_include_tag("views/#{source}") if File.exist?(File.join(js_path, "#{source}.js")) }.join("\n")
end
end
end
end
end
4 changes: 4 additions & 0 deletions tasks/javascript_auto_include_tasks.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# desc "Explaining what the task does"
# task :javascript_auto_include do
# # Task goes here
# end
8 changes: 8 additions & 0 deletions test/javascript_auto_include_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'test/unit'

class JavascriptAutoIncludeTest < Test::Unit::TestCase
# Replace this with your real tests.
def test_this_plugin
flunk
end
end
1 change: 1 addition & 0 deletions uninstall.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Uninstall hook code here

0 comments on commit d121504

Please sign in to comment.