atd-asset_bundler 0.0.1

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/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :gemcutter
2
+
3
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,50 @@
1
+ require 'asset_bundler'
2
+ require 'active_support'
3
+ require 'action_controller/metal'
4
+
5
+ class AssetBundler::AssetsController < ActionController::Metal
6
+ include ActionController::Rendering
7
+ include ActionController::MimeResponds
8
+
9
+ self.view_paths = %w{app}
10
+
11
+ def go
12
+ # Always cache resources. It's the responsibility of the asset tag to
13
+ # invalidate the browser cache with a cache-busting query string.
14
+ headers['Cache-Control'] = 'public'
15
+ headers['Expires'] = 1.year.from_now.httpdate
16
+
17
+ begin
18
+ render File.join(self.controller_path, self.expansion_for(params[:path]))
19
+ rescue ActionView::MissingTemplate
20
+ public_file = File.join(Rails.root, 'public', request.path)
21
+
22
+ File.exists?(public_file) ?
23
+ render(File.read(public_file)) :
24
+ raise(ActionController::RoutingError, "No route matches #{ request.path.inspect }")
25
+ end
26
+ end
27
+
28
+ protected
29
+
30
+ #
31
+ # Counterintuitively, if caching is enabled, we disable Rails caching of
32
+ # the asset template, and assume that it's being cached above us in the
33
+ # app stack. If caching is disabled, use builtin caching to keep the
34
+ # rendered asset in memory until the file on disk changes.
35
+ #
36
+ # TODO: perhaps this should have its own configuration option, in case
37
+ # caching is enabled but there's no Rack::Cache or Varnish in front of us.
38
+ #
39
+ def details_for_lookup
40
+ { :cache => !config.perform_caching }
41
+ end
42
+
43
+ #
44
+ # Expands +path+ into its corresponding assets if it's a registered
45
+ # expansion. Otherswise, returns +path+.
46
+ #
47
+ def expansion_for(path)
48
+ expansion?(path.to_s) ? expansions[path.to_sym] : path
49
+ end
50
+ end
@@ -0,0 +1,15 @@
1
+ module Assets
2
+ class JavascriptsController < AssetBundler::AssetsController
3
+ respond_to :js
4
+
5
+ private
6
+
7
+ def expansions
8
+ ActionView::Helpers::AssetTagHelper.javascript_expansions
9
+ end
10
+
11
+ def expansion?(path)
12
+ expansions.keys.map(&:to_s).include?(path.to_s)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Assets
2
+ class StylesheetsController < AssetBundler::AssetsController
3
+ respond_to :css
4
+
5
+ private
6
+
7
+ def expansions
8
+ ActionView::Helpers::AssetTagHelper.stylesheet_expansions
9
+ end
10
+
11
+ def expansion?(path)
12
+ expansions.keys.map(&:to_s).include?(path.to_s)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ require File.expand_path('../lib/asset_bundler/version', __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'atd-asset_bundler'
5
+ s.version = AssetBundler::VERSION
6
+ s.platform = Gem::Platform::RUBY
7
+ s.authors = [ 'Stephen Touset', 'Antonio Tapiador' ]
8
+ s.email = [ 'atapiador@dit.upm.es' ]
9
+ s.homepage = 'http://github.com/atd/asset_bundler'
10
+ s.summary = 'Simple implementation of dynamic assets for Rails 3.0'
11
+ s.description = 'A Rails Engine that allows you to put assets in app/assets
12
+ and use a Rails template engine to render them. This version
13
+ is compatible with Rails 3.0'
14
+
15
+ s.required_rubygems_version = '>= 1.3.6'
16
+ s.rubyforge_project = 'asset_bundler'
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.executables = `git ls-files`.split("\n").map {|f| f =~ /^bin\/(.*)/ ? $1 : nil }.compact
20
+ s.require_path = 'lib'
21
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ Rails.application.routes.draw do
2
+ javascripts
3
+ stylesheets
4
+ end
@@ -0,0 +1,5 @@
1
+ module AssetBundler
2
+ require 'asset_bundler/version'
3
+ require 'asset_bundler/routing'
4
+ require 'asset_bundler/engine'
5
+ end
@@ -0,0 +1,4 @@
1
+ require 'asset_bundler'
2
+
3
+ class AssetBundler::Engine < ::Rails::Engine
4
+ end
@@ -0,0 +1,33 @@
1
+ require 'action_dispatch/routing/mapper'
2
+
3
+ module ActionDispatch::Routing::Mapper::Assets
4
+ # TODO: provide { route => location } mappings; can't right now because
5
+ # adding a +location+ to the controller's +view_paths+ adds it for _all_
6
+ # +path+s.
7
+
8
+ #
9
+ # Renders Javascript assets whenever +paths+ are matched. Defaults to
10
+ # recognizing routes under '/javascripts' if no +paths+ are given.
11
+ #
12
+ def javascripts(*paths)
13
+ paths.push '/javascripts' if paths.empty?
14
+ paths.each do |route|
15
+ match "#{route}/*path.:format", :to => 'assets/javascripts#go'
16
+ end
17
+ end
18
+
19
+ #
20
+ # Renders stylesheet assets whenever +paths+ are matched. Defaults to
21
+ # recognizing routes under '/stylesheets' if no +paths+ are given.
22
+ #
23
+ def stylesheets(*paths)
24
+ paths.push '/stylesheets' if paths.empty?
25
+ paths.each do |route|
26
+ match "#{route}/*path.:format", :to => 'assets/stylesheets#go'
27
+ end
28
+ end
29
+ end
30
+
31
+ class ActionDispatch::Routing::Mapper
32
+ include ActionDispatch::Routing::Mapper::Assets
33
+ end
@@ -0,0 +1,3 @@
1
+ module AssetBundler
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: atd-asset_bundler
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Stephen Touset
14
+ - Antonio Tapiador
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-10-25 00:00:00 +02:00
20
+ default_executable:
21
+ dependencies: []
22
+
23
+ description: |-
24
+ A Rails Engine that allows you to put assets in app/assets
25
+ and use a Rails template engine to render them. This version
26
+ is compatible with Rails 3.0
27
+ email:
28
+ - atapiador@dit.upm.es
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files: []
34
+
35
+ files:
36
+ - .gitignore
37
+ - Gemfile
38
+ - Rakefile
39
+ - app/controllers/asset_bundler/assets_controller.rb
40
+ - app/controllers/assets/javascripts_controller.rb
41
+ - app/controllers/assets/stylesheets_controller.rb
42
+ - asset_bundler.gemspec
43
+ - config/routes.rb
44
+ - lib/asset_bundler.rb
45
+ - lib/asset_bundler/engine.rb
46
+ - lib/asset_bundler/routing.rb
47
+ - lib/asset_bundler/version.rb
48
+ has_rdoc: true
49
+ homepage: http://github.com/atd/asset_bundler
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options: []
54
+
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 23
72
+ segments:
73
+ - 1
74
+ - 3
75
+ - 6
76
+ version: 1.3.6
77
+ requirements: []
78
+
79
+ rubyforge_project: asset_bundler
80
+ rubygems_version: 1.3.7
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Simple implementation of dynamic assets for Rails 3.0
84
+ test_files: []
85
+