frosting 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +35 -0
- data/frosting.gemspec +12 -0
- data/lib/frosting/base_presenter.rb +11 -0
- data/lib/frosting/integration/rails.rb +11 -0
- data/lib/frosting/presentation.rb +16 -0
- data/lib/frosting/version.rb +3 -0
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDFhNjliYTE0ODBjNzQxZjg4ZTA5YjZiZjcyMDdiM2ZhMjYwNzAwMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzNhMmM5Yzg5YTMyODI5NWZlMTA2MGI3Njc4ZTIwNWI2ZWIzZWI2MA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NGQyZWFjNGVlZDg3ZDc3ZTdhNjE1MzQzOGNiMzdiNDRiMjlkMDlkOGRhNDY4
|
10
|
+
YzgwNjA1MzA3OGI4ZWY2OTA0NzI3ZWRhNGYzMzFkYTYwM2FlNGE5MmM0ZjU5
|
11
|
+
MWU0ZWU0MTRkMWYxNDc5NWExNjczMjc3ZTc5MGM5NGVkZTc2NjU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDcyYzYxNTBhOGYzMDU3ODc2MjExMThmYzBlZGFhMjkzOWVjMTJlYzEzNzI4
|
14
|
+
MzEwZGVjZTk5ODMzMjJjZWEzOGQ1NTc5ZjM1MGM1YTk5ODRiNzA0NTAzYTQw
|
15
|
+
ZjA1ZjEzNDdjZDdkZjBmNTc1YTEzZTk5MjIyY2I5YzVkMGRhNTY=
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Frosting
|
2
|
+
|
3
|
+
Let's simplify using presenters in Rails.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add `gem "frosting"` to your Gemfile and run `bundle install`.
|
8
|
+
|
9
|
+
## Introduction
|
10
|
+
|
11
|
+
You have a `Post` model. You're a good lil' rabbit, and it only contains methods concerned with its persistence.
|
12
|
+
|
13
|
+
So where do you put presentation-specific logic?
|
14
|
+
|
15
|
+
The view, right? Nah, man. You should probably use a presenter.
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
Let's say we're in `PostsController#show` and you want to implement some sort of presentation logic. How about we're color coding based on the age of the post.
|
20
|
+
|
21
|
+
If you `present @post` from your controller (and its class is `Post`), frosting will look for `Presenters::Post` (defined in `/models/presenters/post.rb` presumably). Here's what that could look like:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
module Presenters
|
25
|
+
class Post < Frosting::BasePresenter
|
26
|
+
def color
|
27
|
+
old? ? 'red' : 'green'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
You defined `#old?` in your model because it's not a presentation concern. Good job.
|
34
|
+
|
35
|
+
`Frosting::BasePresenter` delegates to the resource you're presenting, and it also has access to the view context. It delegates `link_to` and `content_tag` by default. You should probably make your own base presenter that inherits from frosting's base. It's your life, and you should do what you want to.
|
data/frosting.gemspec
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'frosting'
|
3
|
+
s.version = '0.0.2'
|
4
|
+
s.date = '2014-02-04'
|
5
|
+
s.summary = "Let's make presenters easy."
|
6
|
+
s.description = "Adds some methods to your controllers and a base presenter. Get that presentation logic out of your models."
|
7
|
+
s.authors = ["Ben Eddy", "Jon Evans"]
|
8
|
+
s.email = 'rubygems@foraker.com'
|
9
|
+
s.files = `git ls-files`.split($/)
|
10
|
+
s.homepage = 'http://www.github.com/foraker/frosting'
|
11
|
+
s.license = 'MIT'
|
12
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Frosting
|
2
|
+
module Presentation
|
3
|
+
def present(resource, options = {})
|
4
|
+
begin
|
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
|
10
|
+
end
|
11
|
+
|
12
|
+
def present_collection(collection, options = {})
|
13
|
+
collection.map { |resource| present(resource, options) }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Eddy
|
@@ -18,7 +18,13 @@ executables: []
|
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
+
- README.md
|
22
|
+
- frosting.gemspec
|
21
23
|
- lib/frosting.rb
|
24
|
+
- lib/frosting/base_presenter.rb
|
25
|
+
- lib/frosting/integration/rails.rb
|
26
|
+
- lib/frosting/presentation.rb
|
27
|
+
- lib/frosting/version.rb
|
22
28
|
homepage: http://www.github.com/foraker/frosting
|
23
29
|
licenses:
|
24
30
|
- MIT
|