cells-assets 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +50 -0
- data/Rakefile +5 -0
- data/cells-assets.gemspec +24 -0
- data/lib/cell/assets.rb +27 -0
- data/lib/cell/assets/version.rb +5 -0
- data/spec/cell/assets_spec.rb +46 -0
- data/spec/spec_helper.rb +4 -0
- metadata +108 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
# Cell Assets
|
3
|
+
|
4
|
+
Cells encapsulate display components. The brilliant part about them is that everything you need to
|
5
|
+
actually render a bit of view is contained in one place, not crapped about your app.
|
6
|
+
|
7
|
+
But controller and templates aren't the only thing that it takes to make a cell a cell. There's the
|
8
|
+
other things like javascript and CSS that contribute to how the cell ultimately looks and behaves.
|
9
|
+
|
10
|
+
If you feel like those things should also be packaged with the cell then cell assets is for you. All
|
11
|
+
it does is let you get at other things which should be private data of the cell (like how it behaves)
|
12
|
+
|
13
|
+
Let's say I've got some cell:
|
14
|
+
|
15
|
+
class MyCell < Cell::Rails
|
16
|
+
def hello
|
17
|
+
render
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
that has a directory structure like:
|
22
|
+
|
23
|
+
my/hello.html.erb
|
24
|
+
/init.js
|
25
|
+
/dragndrop.js
|
26
|
+
/mycell.css
|
27
|
+
/icon.png
|
28
|
+
|
29
|
+
and I want to get all the javascript associated with it:
|
30
|
+
|
31
|
+
MyCell.assets("*.js") #=> ['dragndrop.js','init.js']
|
32
|
+
|
33
|
+
|
34
|
+
if you pass it a block it will give you the content of each asset. For example,
|
35
|
+
let's just read the init code:
|
36
|
+
|
37
|
+
MyCell.assets("init.js") do |content|
|
38
|
+
# content contains in init.js
|
39
|
+
end
|
40
|
+
|
41
|
+
matching assets are always returned in alphabetically sorted order so that
|
42
|
+
you don't run into ordering problems when using different operating systems.
|
43
|
+
|
44
|
+
# Why?
|
45
|
+
|
46
|
+
We use this as part of system that loads cells in isolation and so it is important
|
47
|
+
that each cell be aware of all the bits that it needs to run. Perhaps this will be
|
48
|
+
useful to other folks in the future. What you do with cell assets is your business,
|
49
|
+
but the point is that the cell's assets are *it's* business and ain't nobody else's
|
50
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "cell/assets/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "cells-assets"
|
7
|
+
s.version = Cell::Assets::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Charles Lowell"]
|
10
|
+
s.email = ["cowboyd@thefrontside.net"]
|
11
|
+
s.homepage = "http://github.com/cowboyd/cells-assets"
|
12
|
+
s.summary = "Query your cells for things that are theirs and theirs alone"
|
13
|
+
s.description = "CSS, Javascript, images. These are your cell's business and nobody else's. Keep your cell's private data where it belongs"
|
14
|
+
|
15
|
+
s.rubyforge_project = "cells-assets"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency "cells", ">= 3.5.0"
|
23
|
+
s.add_development_dependency "rspec", ">= 2.0.0"
|
24
|
+
end
|
data/lib/cell/assets.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'cells'
|
2
|
+
require 'cell/assets/version'
|
3
|
+
|
4
|
+
module Cell
|
5
|
+
module Assets
|
6
|
+
|
7
|
+
def inherited(cls)
|
8
|
+
super
|
9
|
+
cls.extend(Cell::Assets)
|
10
|
+
end
|
11
|
+
|
12
|
+
def assets(glob)
|
13
|
+
[].tap do |matches|
|
14
|
+
self.view_paths.each do |path|
|
15
|
+
base = "#{path}/#{cell_name}"
|
16
|
+
Dir.glob("#{base}/#{glob}").sort.each do |entry|
|
17
|
+
match = "#{base}/#{File.basename(entry)}"
|
18
|
+
matches << match
|
19
|
+
yield match, File.read(File.expand_path(match)) if block_given?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Cell::Rails.extend(self)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cell::Assets do
|
4
|
+
|
5
|
+
it "can be queried with a dir glob" do
|
6
|
+
Dir.should_receive(:glob).twice.with("/mock/cells/A/*.js").and_return(["one.js", "two.js"])
|
7
|
+
File.should_receive(:read).with("/mock/cells/A/one.js").and_return("foo = 'bar'")
|
8
|
+
File.should_receive(:read).with("/mock/cells/A/two.js").and_return("bar = 'baz'")
|
9
|
+
mock_cell(:A).tap do |cell|
|
10
|
+
cell.assets("*.js").should == ["/mock/cells/A/one.js","/mock/cells/A/two.js"]
|
11
|
+
files = {}
|
12
|
+
cell.assets("*.js") do |name, content|
|
13
|
+
files[name] = content
|
14
|
+
end
|
15
|
+
files.should == {
|
16
|
+
"/mock/cells/A/one.js" => "foo = 'bar'",
|
17
|
+
"/mock/cells/A/two.js" => "bar = 'baz'"
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "are returned in alphabetic sort order" do
|
23
|
+
Dir.should_receive(:glob).with("/mock/cells/A/*.js").and_return(["two.js", "one.js"])
|
24
|
+
mock_cell(:A).tap do |cell|
|
25
|
+
cell.assets("*.js").should == ["/mock/cells/A/one.js", "/mock/cells/A/two.js"]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def mock_cell(name, &body)
|
30
|
+
Class.new(Cell::Rails).tap do |cell|
|
31
|
+
mc = class << cell;self;end
|
32
|
+
mc.send(:define_method, :to_s) do
|
33
|
+
"#{name}"
|
34
|
+
end
|
35
|
+
mc.send(:define_method, :cell_name) do
|
36
|
+
"#{name}"
|
37
|
+
end
|
38
|
+
def cell.view_paths
|
39
|
+
["/mock/cells"]
|
40
|
+
end
|
41
|
+
# @cells[name.to_s] = cell
|
42
|
+
cell.class_eval(&body) if block_given?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cells-assets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Charles Lowell
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-02-23 00:00:00 -06:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: cells
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 19
|
30
|
+
segments:
|
31
|
+
- 3
|
32
|
+
- 5
|
33
|
+
- 0
|
34
|
+
version: 3.5.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 15
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 0
|
49
|
+
- 0
|
50
|
+
version: 2.0.0
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
description: CSS, Javascript, images. These are your cell's business and nobody else's. Keep your cell's private data where it belongs
|
54
|
+
email:
|
55
|
+
- cowboyd@thefrontside.net
|
56
|
+
executables: []
|
57
|
+
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
extra_rdoc_files: []
|
61
|
+
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- cells-assets.gemspec
|
68
|
+
- lib/cell/assets.rb
|
69
|
+
- lib/cell/assets/version.rb
|
70
|
+
- spec/cell/assets_spec.rb
|
71
|
+
- spec/spec_helper.rb
|
72
|
+
has_rdoc: true
|
73
|
+
homepage: http://github.com/cowboyd/cells-assets
|
74
|
+
licenses: []
|
75
|
+
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
hash: 3
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
version: "0"
|
99
|
+
requirements: []
|
100
|
+
|
101
|
+
rubyforge_project: cells-assets
|
102
|
+
rubygems_version: 1.5.2
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Query your cells for things that are theirs and theirs alone
|
106
|
+
test_files:
|
107
|
+
- spec/cell/assets_spec.rb
|
108
|
+
- spec/spec_helper.rb
|