knockout-assets 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/README.md +3 -0
- data/app/helpers/knockout_assets.rb +20 -0
- data/app/views/_knockout_assets.erb +23 -0
- data/lib/knockout/assets.rb +2 -0
- data/lib/knockout/assets/engine.rb +11 -0
- data/lib/knockout/assets/version.rb +3 -0
- metadata +69 -0
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module KnockoutAssets
|
2
|
+
def knockout_assets(options = {})
|
3
|
+
options = {
|
4
|
+
exclude: nil,
|
5
|
+
preload: true,
|
6
|
+
}.merge(options)
|
7
|
+
|
8
|
+
files = {}
|
9
|
+
Rails.application.config.assets.paths.each { |p|
|
10
|
+
Dir["#{p}/**/*"].select { |f| f =~ /.*\.(png|gif|jpg|jpeg|bmp)/ }.each { |f|
|
11
|
+
item_path = f[p.length+1..-1]
|
12
|
+
if !options[:exclude] || options[:exclude] !~ item_path
|
13
|
+
files[item_path] = path_to_image(item_path)
|
14
|
+
end
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
render :partial => '/knockout_assets', locals: {asset_files: files, preload: options[:preload]}
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<% # Prepare the asset hash and populate it %>
|
2
|
+
<script type="text/javascript">
|
3
|
+
var knockout_assets = {};
|
4
|
+
|
5
|
+
<% asset_files.each { |k,v| %>
|
6
|
+
knockout_assets['<%= k %>'] = '<%= v %>';
|
7
|
+
<% } %>
|
8
|
+
|
9
|
+
ko.bindingHandlers.img = {
|
10
|
+
init: function (element, valueAccessor) {
|
11
|
+
var str = ko.utils.unwrapObservable(valueAccessor());
|
12
|
+
$(element).attr('src', knockout_assets[str]);
|
13
|
+
}
|
14
|
+
};
|
15
|
+
</script>
|
16
|
+
|
17
|
+
<% # Write out all the images hidden. This preloads them so templates show instantly %>
|
18
|
+
<% if preload
|
19
|
+
asset_files.each { |k, v| %>
|
20
|
+
<img src="<%= v %>" style="display: none;"/>
|
21
|
+
<% }
|
22
|
+
end
|
23
|
+
%>
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knockout-assets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Harry Lascelles
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
type: :runtime
|
16
|
+
name: rails
|
17
|
+
prerelease: false
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '0'
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Prepares the SHA values of CDN assets in a JS hash. Knockout templates
|
31
|
+
can then refer to them without being rendered by erb or haml every time.
|
32
|
+
email:
|
33
|
+
- harry@harrylascelles.com
|
34
|
+
executables: []
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- app/views/_knockout_assets.erb
|
39
|
+
- app/helpers/knockout_assets.rb
|
40
|
+
- lib/knockout/assets/engine.rb
|
41
|
+
- lib/knockout/assets/version.rb
|
42
|
+
- lib/knockout/assets.rb
|
43
|
+
- README.md
|
44
|
+
homepage: https://github.com/hlascelles/knockout-assets
|
45
|
+
licenses: []
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.8.25
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Prepares the SHA values of CDN assets for inclusion in templates.
|
68
|
+
test_files: []
|
69
|
+
has_rdoc:
|