frosting 0.0.2 → 0.0.3
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.
- checksums.yaml +8 -8
- data/Gemfile +4 -0
- data/frosting.gemspec +6 -1
- data/lib/frosting/base_presenter.rb +13 -1
- data/lib/frosting/presentation.rb +6 -9
- data/lib/frosting/repository.rb +18 -0
- data/lib/frosting/version.rb +1 -1
- data/spec/frosting/base_presenter_spec.rb +36 -0
- data/spec/frosting/presentation_spec.rb +34 -0
- data/spec/frosting/repository_spec.rb +54 -0
- metadata +49 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YWZhYTY4OTY0YjFmMzUyODQ2NDExYTUxZWRhZTZmMGE3MTdmMjc0ZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Yjg0ODZiZTNmODVhZmNmMjZiN2JlM2I0M2YxZTg3ZjJiZGE4Y2FkMQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTk1YWFmMTgwNjI1ZWIzYWJkMmI0MmE4YjMyOGUwMGRmNTI3MGViOWU0YzYx
|
10
|
+
NmQ5ZDAzZjkxMDIzOWE2MTdjMzZjMWU4OGViMjZkOTY5NGY3ODEyN2MxNjIw
|
11
|
+
OTIxZDgyZTFlMDEyZWIxNjQ2ODUxZTI3Y2MyMWNjZDg2Mzc3ODA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjQ1MmI3Y2MzZDRiMzUxN2JhMWJmYjMyZTMzYTZiMjZmM2M4ZWJkYTlmNWM4
|
14
|
+
YjczOGZmZGI1OTExYWM1MjA2YTMyMDkxYWI2ZDZiN2Q3MzkwYTk4MWQxNmI1
|
15
|
+
NThiNjA5ZWU0ZGRjYzQ5NTliYTc5NTgwZDJhNjNkMzNkYTY2MjU=
|
data/Gemfile
ADDED
data/frosting.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'frosting'
|
3
|
-
s.version = '0.0.
|
3
|
+
s.version = '0.0.3'
|
4
4
|
s.date = '2014-02-04'
|
5
5
|
s.summary = "Let's make presenters easy."
|
6
6
|
s.description = "Adds some methods to your controllers and a base presenter. Get that presentation logic out of your models."
|
@@ -9,4 +9,9 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.files = `git ls-files`.split($/)
|
10
10
|
s.homepage = 'http://www.github.com/foraker/frosting'
|
11
11
|
s.license = 'MIT'
|
12
|
+
|
13
|
+
s.add_dependency "activesupport"
|
14
|
+
|
15
|
+
s.add_development_dependency 'bundler', '~> 1.3'
|
16
|
+
s.add_development_dependency 'rspec', '~> 2.0'
|
12
17
|
end
|
@@ -1,11 +1,23 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
require 'frosting/presentation'
|
3
|
+
|
1
4
|
module Frosting
|
2
5
|
class BasePresenter < SimpleDelegator
|
3
|
-
|
6
|
+
include Presentation
|
4
7
|
|
5
8
|
def initialize(resource, context = nil)
|
6
9
|
@context = context
|
7
10
|
@wrapped = resource
|
8
11
|
super(@wrapped)
|
9
12
|
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def _context
|
17
|
+
@context
|
18
|
+
end
|
19
|
+
|
20
|
+
alias :view_context :_context
|
21
|
+
alias :h :_context
|
10
22
|
end
|
11
23
|
end
|
@@ -1,16 +1,13 @@
|
|
1
|
+
require 'frosting/repository'
|
2
|
+
|
1
3
|
module Frosting
|
2
4
|
module Presentation
|
3
|
-
def present(
|
4
|
-
|
5
|
-
klass = options[:presenter] || "Presenters::#{resource.class.name}".constantize
|
6
|
-
klass.new(resource, view_context)
|
7
|
-
rescue LoadError
|
8
|
-
raise "No such presenter: #{klass}"
|
9
|
-
end
|
5
|
+
def present(*args)
|
6
|
+
Repository.present(*args)
|
10
7
|
end
|
11
8
|
|
12
|
-
def present_collection(
|
13
|
-
|
9
|
+
def present_collection(*args)
|
10
|
+
Repository.present_collection(*args)
|
14
11
|
end
|
15
12
|
end
|
16
13
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "active_support/core_ext/string/inflections"
|
2
|
+
|
3
|
+
module Frosting
|
4
|
+
class Repository
|
5
|
+
def self.present(resource, options = {})
|
6
|
+
begin
|
7
|
+
klass = options[:presenter] || "Presenters::#{resource.class.name}".constantize
|
8
|
+
klass.new(resource, options[:context])
|
9
|
+
rescue LoadError
|
10
|
+
raise "No such presenter: #{klass}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.present_collection(collection, options = {})
|
15
|
+
collection.map { |resource| present(resource, options) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/frosting/version.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path("../../../lib/frosting/base_presenter", __FILE__)
|
2
|
+
|
3
|
+
module Frosting
|
4
|
+
class TestPresenter < BasePresenter
|
5
|
+
def page_title
|
6
|
+
"Page Title"
|
7
|
+
end
|
8
|
+
|
9
|
+
def formatted_name
|
10
|
+
name.upcase
|
11
|
+
end
|
12
|
+
|
13
|
+
def root_url
|
14
|
+
h.root_url
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe TestPresenter do
|
19
|
+
let(:context) { double(root_url: "/home") }
|
20
|
+
let(:resource) { double(name: "bruce wayne") }
|
21
|
+
|
22
|
+
subject { described_class.new(resource, context) }
|
23
|
+
|
24
|
+
it "responds to defined methods" do
|
25
|
+
subject.page_title.should == "Page Title"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "delegates undefined methods" do
|
29
|
+
subject.formatted_name.should == "BRUCE WAYNE"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "delegates to the context" do
|
33
|
+
subject.root_url.should == "/home"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path("../../../lib/frosting/presentation", __FILE__)
|
2
|
+
|
3
|
+
module Frosting
|
4
|
+
class TestClass
|
5
|
+
include Frosting::Presentation
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "an instance a Presentation class" do
|
9
|
+
|
10
|
+
subject { TestClass.new }
|
11
|
+
|
12
|
+
describe "#present" do
|
13
|
+
it "delegates to the Presenter repository and returns the presented resource" do
|
14
|
+
resource, presented_resource = double, double
|
15
|
+
Frosting::Repository.stub(:present)
|
16
|
+
.with(resource)
|
17
|
+
.and_return(presented_resource)
|
18
|
+
|
19
|
+
subject.present(resource).should == presented_resource
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#present_collection" do
|
24
|
+
it "delegates to the Presenter repository and returns the presented collection" do
|
25
|
+
collection, presented_collection = collection, double
|
26
|
+
Frosting::Repository.stub(:present_collection)
|
27
|
+
.with(collection)
|
28
|
+
.and_return(presented_collection)
|
29
|
+
|
30
|
+
subject.present_collection(collection).should == presented_collection
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.expand_path("../../../lib/frosting/repository", __FILE__)
|
2
|
+
|
3
|
+
module Test ; end
|
4
|
+
module Presenters ; module Test ; end end
|
5
|
+
|
6
|
+
module Frosting
|
7
|
+
describe Repository do
|
8
|
+
class Test::Resource ; end
|
9
|
+
class Presenters::Test::Resource < Struct.new(:resource, :context) ; end
|
10
|
+
|
11
|
+
describe ".present" do
|
12
|
+
let(:resource) { Test::Resource.new }
|
13
|
+
let(:context) { double }
|
14
|
+
|
15
|
+
subject do
|
16
|
+
described_class.present(resource, context: context)
|
17
|
+
end
|
18
|
+
|
19
|
+
it { should be_instance_of(Presenters::Test::Resource) }
|
20
|
+
its(:resource) { should eq resource }
|
21
|
+
its(:context) { should eq context }
|
22
|
+
|
23
|
+
context "specifying a presenter class" do
|
24
|
+
class Presenters::Test::Alternative < Struct.new(:resource, :context) ; end
|
25
|
+
|
26
|
+
subject do
|
27
|
+
described_class.present(resource, {
|
28
|
+
context: context,
|
29
|
+
presenter: Presenters::Test::Alternative
|
30
|
+
})
|
31
|
+
end
|
32
|
+
|
33
|
+
it { should be_instance_of(Presenters::Test::Alternative) }
|
34
|
+
its(:resource) { should eq resource }
|
35
|
+
its(:context) { should eq context }
|
36
|
+
end
|
37
|
+
|
38
|
+
it "throws an exception when the resource has no presenter" do
|
39
|
+
class Test::OtherResource ; end
|
40
|
+
resource = Test::OtherResource.new
|
41
|
+
expect { described_class.present(resource, context: context) }.to raise_error(NameError)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe ".present_collection" do
|
46
|
+
it "presents each item in the collection with options" do
|
47
|
+
resource = double
|
48
|
+
described_class.should_receive(:present)
|
49
|
+
.with(resource, {option: :val})
|
50
|
+
described_class.present_collection([resource], {option: :val})
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frosting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Eddy
|
@@ -10,7 +10,49 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
date: 2014-02-04 00:00:00.000000000 Z
|
13
|
-
dependencies:
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ! '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.3'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.3'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '2.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '2.0'
|
14
56
|
description: Adds some methods to your controllers and a base presenter. Get that
|
15
57
|
presentation logic out of your models.
|
16
58
|
email: rubygems@foraker.com
|
@@ -18,13 +60,18 @@ executables: []
|
|
18
60
|
extensions: []
|
19
61
|
extra_rdoc_files: []
|
20
62
|
files:
|
63
|
+
- Gemfile
|
21
64
|
- README.md
|
22
65
|
- frosting.gemspec
|
23
66
|
- lib/frosting.rb
|
24
67
|
- lib/frosting/base_presenter.rb
|
25
68
|
- lib/frosting/integration/rails.rb
|
26
69
|
- lib/frosting/presentation.rb
|
70
|
+
- lib/frosting/repository.rb
|
27
71
|
- lib/frosting/version.rb
|
72
|
+
- spec/frosting/base_presenter_spec.rb
|
73
|
+
- spec/frosting/presentation_spec.rb
|
74
|
+
- spec/frosting/repository_spec.rb
|
28
75
|
homepage: http://www.github.com/foraker/frosting
|
29
76
|
licenses:
|
30
77
|
- MIT
|