assets_js 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,4 @@
1
+ lib/**/*.rb
2
+ README.rdoc
3
+ ChangeLog.rdoc
4
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ html/
2
+ pkg/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
data/ChangeLog.rdoc ADDED
@@ -0,0 +1,4 @@
1
+ === 0.1.0 / 2012-06-26
2
+
3
+ * Initial release:
4
+
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 jbutler
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.rdoc ADDED
@@ -0,0 +1,52 @@
1
+ = assets_js
2
+
3
+ * {Homepage}[https://github.com/johnnypez/assets_js]
4
+ * {Documentation}[https://github.com/johnnypez/assets_js]
5
+
6
+ == Description
7
+
8
+ Provides some javascript helpers for Rails assets.
9
+
10
+ == Features
11
+
12
+ == Examples
13
+
14
+ Add this to your application.js
15
+
16
+ //= require 'assets_js'
17
+
18
+ Then somewhere else in your application.js you will be able to reference assets with:
19
+
20
+ asset_path('rails.png')
21
+ => '/assets/rails.png'
22
+
23
+ This works if you have digests enabled too:
24
+
25
+ asset_path('rails.png');
26
+ => '/assets/rails-dc0842763ddf5d7ea5c32b7e8a4cfa39.png'
27
+
28
+ asset_url('rails.png');
29
+ => 'http://www.example.com/assets/rails-dc0842763ddf5d7ea5c32b7e8a4cfa39.png'
30
+
31
+ There are some simple tag helpers too:
32
+
33
+ image_tag('rails.png');
34
+ => <img src="/assets/rails-dc0842763ddf5d7ea5c32b7e8a4cfa39.png" />
35
+
36
+ javascript_include_tag('app.js');
37
+ => <script type="text/javascript" src="/assets/app-dc0842763ddf5d7ea5c32b7e8a4cfa39.js"></script>
38
+
39
+ stylesheet_link_tag('style.css');
40
+ => <link rel="stylesheet" media="screen" href="/assets/style-dc0842763ddf5d7ea5c32b7e8a4cfa39.css" />
41
+
42
+ == Requirements
43
+
44
+ == Install
45
+
46
+ $ gem install assets_js
47
+
48
+ == Copyright
49
+
50
+ Copyright (c) 2012 John Butler
51
+
52
+ See LICENSE.txt for details.
data/Rakefile ADDED
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+
6
+ begin
7
+ gem 'rubygems-tasks', '~> 0.2'
8
+ require 'rubygems/tasks'
9
+
10
+ Gem::Tasks.new
11
+ rescue LoadError => e
12
+ warn e.message
13
+ warn "Run `gem install rubygems-tasks` to install 'rubygems/tasks'."
14
+ end
15
+
16
+ begin
17
+ gem 'rdoc', '~> 3.0'
18
+ require 'rdoc/task'
19
+
20
+ RDoc::Task.new do |rdoc|
21
+ rdoc.title = "assets_js"
22
+ end
23
+ rescue LoadError => e
24
+ warn e.message
25
+ warn "Run `gem install rdoc` to install 'rdoc/task'."
26
+ end
27
+ task :doc => :rdoc
28
+
29
+ begin
30
+ gem 'rspec', '~> 2.4'
31
+ require 'rspec/core/rake_task'
32
+
33
+ RSpec::Core::RakeTask.new
34
+ rescue LoadError => e
35
+ task :spec do
36
+ abort "Please run `gem install rspec` to install RSpec."
37
+ end
38
+ end
39
+
40
+ task :test => :spec
41
+ task :default => :spec
@@ -0,0 +1,72 @@
1
+ <%
2
+ manifest = {}
3
+ app = Rails.application
4
+ env = app.assets
5
+ env.each_logical_path do |logical_path|
6
+ if File.basename(logical_path)[/[^\.]+/, 0] == 'index'
7
+ logical_path.sub!(/\/index\./, '.')
8
+ end
9
+
10
+ # grabbed from Sprockets::Environment#find_asset
11
+ pathname = Pathname.new(logical_path)
12
+ if pathname.absolute?
13
+ return unless stat(pathname)
14
+ logical_path = attributes_for(pathname).logical_path
15
+ else
16
+ begin
17
+ pathname = resolve(logical_path)
18
+ rescue Sprockets::FileNotFound
19
+ return nil
20
+ end
21
+ end
22
+
23
+ asset = Sprockets::Asset.new(env, logical_path, pathname)
24
+ manifest[logical_path] = app.config.assets.digest ? asset.digest_path : asset.logical_path
25
+ end
26
+ %>
27
+
28
+ !function(window, document, undefined){
29
+
30
+ var manifest = <%= ActiveSupport::JSON.encode(manifest) %>;
31
+
32
+ function asset_path(path){
33
+ if(manifest.hasOwnProperty(path)){
34
+ return '/assets/' + manifest[path];
35
+ }
36
+ else{
37
+ throw Error('missing asset: ' + path);
38
+ }
39
+ };
40
+
41
+ function asset_url(path){
42
+ return window.location.protocol + '//' + window.location.host + asset_path(path);
43
+ };
44
+
45
+ function tag(tag, options){
46
+ var tag = $(document.createElement(tag));
47
+ tag.attr(options);
48
+ return tag[0].outerHTML
49
+ }
50
+
51
+ function image_tag(path, options){
52
+ var attr = $.extend({}, options, {src: asset_path(path)});
53
+ return tag('img', attr);
54
+ }
55
+
56
+ function javascript_include_tag(path, options){
57
+ var attr = $.extend({type: 'text/javascript'}, options, {src: asset_path(path)});
58
+ return tag('script', attr);
59
+ }
60
+
61
+ function stylesheet_link_tag(path, options){
62
+ var attr = $.extend({rel: 'stylesheet', media: 'screen'}, options, {href: asset_path(path)});
63
+ return tag('link', attr);
64
+ }
65
+
66
+ window.asset_path = asset_path;
67
+ window.asset_url = asset_url;
68
+ window.image_tag = image_tag;
69
+ window.javascript_include_tag = javascript_include_tag;
70
+ window.stylesheet_link_tag = stylesheet_link_tag;
71
+
72
+ }(window, document);
data/assets_js.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path('../lib/assets_js/version', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "assets_js"
7
+ gem.version = AssetsJS::VERSION
8
+ gem.summary = %q{Provides rails asset helpers to your client side javascript}
9
+ gem.description = %q{Provides rails asset helpers to your client side javascript}
10
+ gem.license = "MIT"
11
+ gem.authors = ["jbutler"]
12
+ gem.homepage = "https://rubygems.org/gems/assets_js"
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.add_development_dependency "rubygems-tasks", "~> 0.2"
20
+ gem.add_development_dependency "rdoc", "~> 3.0"
21
+ gem.add_development_dependency "rspec", "~> 2.4"
22
+ end
data/lib/assets_js.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'assets_js/version'
2
+ require 'assets_js/engine'
@@ -0,0 +1,6 @@
1
+ require 'rails'
2
+
3
+ module AssetsJS
4
+ class Engine < Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ module AssetsJS
2
+ # assets_js version
3
+ VERSION = "0.1.0"
4
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ require 'assets_js'
3
+
4
+ describe AssetsJavaScript do
5
+ it "should have a VERSION constant" do
6
+ subject.const_get('VERSION').should_not be_empty
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ gem 'rspec', '~> 2.4'
2
+ require 'rspec'
3
+ require 'assets_js/version'
4
+
5
+ include AssetsJavaScript
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: assets_js
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - jbutler
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-26 00:00:00.000000000 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rubygems-tasks
17
+ requirement: &70315071465500 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '0.2'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *70315071465500
26
+ - !ruby/object:Gem::Dependency
27
+ name: rdoc
28
+ requirement: &70315071464980 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *70315071464980
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ requirement: &70315071464520 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: '2.4'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *70315071464520
48
+ description: Provides rails asset helpers to your client side javascript
49
+ email:
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .document
55
+ - .gitignore
56
+ - .rspec
57
+ - ChangeLog.rdoc
58
+ - LICENSE.txt
59
+ - README.rdoc
60
+ - Rakefile
61
+ - app/assets/javascripts/assets_js.js.erb
62
+ - assets_js.gemspec
63
+ - lib/assets_js.rb
64
+ - lib/assets_js/engine.rb
65
+ - lib/assets_js/version.rb
66
+ - spec/assets_js_spec.rb
67
+ - spec/spec_helper.rb
68
+ has_rdoc: true
69
+ homepage: https://rubygems.org/gems/assets_js
70
+ licenses:
71
+ - MIT
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 1.6.2
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: Provides rails asset helpers to your client side javascript
94
+ test_files:
95
+ - spec/assets_js_spec.rb
96
+ - spec/spec_helper.rb