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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmFhNmU5YjBjNGVhZWJiZDk3YmYzNWMzZGRmZGNlNTk0MTMwYmRkNw==
4
+ NDFhNjliYTE0ODBjNzQxZjg4ZTA5YjZiZjcyMDdiM2ZhMjYwNzAwMg==
5
5
  data.tar.gz: !binary |-
6
- MGI1YTg1YWIxNWRlNTk5MWM2Njc4YTU4YWJkYzcwNzBlNWNlZTdjZQ==
6
+ NzNhMmM5Yzg5YTMyODI5NWZlMTA2MGI3Njc4ZTIwNWI2ZWIzZWI2MA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZjU5NDIwMDQyNDg1OGI4YjZhMzEyOGRmYzgxNGY5ZDQyYzJhZDc0NmNkZTA3
10
- Yzk2NzRlMDI5ZmFjY2FlNDgxNDZkMDU1NWFiNzNjNzNkY2EyYjA3ZjhmZGVi
11
- MjMwYWNmYTRhNzgwYTNmMDZjNzA3Mzg2OWM3OTk2NjM3MWU5N2M=
9
+ NGQyZWFjNGVlZDg3ZDc3ZTdhNjE1MzQzOGNiMzdiNDRiMjlkMDlkOGRhNDY4
10
+ YzgwNjA1MzA3OGI4ZWY2OTA0NzI3ZWRhNGYzMzFkYTYwM2FlNGE5MmM0ZjU5
11
+ MWU0ZWU0MTRkMWYxNDc5NWExNjczMjc3ZTc5MGM5NGVkZTc2NjU=
12
12
  data.tar.gz: !binary |-
13
- ODI4NDU0ZDk1MTFkYWM5M2UyY2M2ZDJiMDkxZjVhNmYzMzU3NGU0ZmZiZWJk
14
- NGY5YmQzY2E3ZWE3OTI5YTQzNTNkZTNkMTcyZTQ0NTVhNGUyM2JhZjhiMGVi
15
- YTFjODk5ZWFhY2Q2MWU3MjlhNDg3ZTQ2ZWRmOTc0NmIwZDc0MWE=
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,11 @@
1
+ module Frosting
2
+ class BasePresenter < SimpleDelegator
3
+ delegate :link_to, :content_tag, to: :@context
4
+
5
+ def initialize(resource, context = nil)
6
+ @context = context
7
+ @wrapped = resource
8
+ super(@wrapped)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'frosting/presentation'
2
+
3
+ module Frosting
4
+ class Railtie < ::Rails::Railtie
5
+ initializer 'frosting.presentation' do
6
+ ActiveSupport.on_load(:action_controller) do
7
+ include Frosting::Presentation
8
+ end
9
+ end
10
+ end
11
+ 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
@@ -0,0 +1,3 @@
1
+ module Frosting
2
+ VERSION = "0.0.1"
3
+ 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.1
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