exhibit 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ Copyright 2011 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,56 @@
1
+ # Exhibit
2
+
3
+ Exhibit is a simple gem to generate and work with presenters in Rails 3. It is based on the solution Ryan Bates created in [Railscasts Pro episode #287](http://railscasts.com/episodes/287-presenters-from-scratch).
4
+
5
+ version 0.1.0
6
+ Robin Brouwer
7
+ 45north
8
+
9
+ ## Installation
10
+
11
+ Exhibit only works with Rails 3. Add the following to your Gemfile:
12
+
13
+ gem 'exhibit'
14
+
15
+ Now just run `bundle install` and you're ready to exhibit your application! ;)
16
+
17
+ ## Usage
18
+
19
+ Exhibit is a simple and lightweight gem. Using it is pretty straightforward.
20
+ Run the following generator to create a presenter:
21
+
22
+ rails g exhibit:presenter User
23
+
24
+ The presenter is stored in app/presenters/user_presenter.rb.
25
+
26
+ class UserPresenter < Exhibit::Presenter
27
+ exhibit :user
28
+ end
29
+
30
+ You can add methods to this class to exhibit content.
31
+
32
+ class UserPresenter < Exhibit::Presenter
33
+ exhibit :user
34
+
35
+ def email
36
+ content_tag(:span, user.email)
37
+ end
38
+ end
39
+
40
+ You can also use `delegate` to delegate methods to the User Model.
41
+
42
+ class UserPresenter < Exhibit::Presenter
43
+ exhibit :user
44
+ delegate :email, :to => :user
45
+ end
46
+
47
+ But how can you use this presenter inside the View? It works the same as Ryan shows you in [Railscasts Pro episode #287](http://railscasts.com/episodes/287-presenters-from-scratch):
48
+
49
+ <% exhibit(@user) do |user| %>
50
+ <p>
51
+ <strong>E-mail:</strong>
52
+ <%= user.email %>
53
+ </p>
54
+ <% end %>
55
+
56
+ Got feedback? Feature requests? Add it as an issue or create a pull request. Have fun exhibiting your application!
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Exhibit'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task :default => :test
@@ -0,0 +1,9 @@
1
+ require 'exhibit/helpers'
2
+ require 'exhibit/presenter'
3
+
4
+ module Exhibit
5
+ end
6
+
7
+ if defined?(Rails)
8
+ ActionController::Base.send(:helper, Exhibit::Helpers)
9
+ end
@@ -0,0 +1,10 @@
1
+ module Exhibit
2
+ module Helpers
3
+ def exhibit(object, klass = nil)
4
+ klass ||= "#{object.class}Presenter".constantize
5
+ presenter = klass.new(object, self)
6
+ yield presenter if block_given?
7
+ presenter
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ module Exhibit
2
+ class Presenter
3
+ def initialize(object, template)
4
+ @object = object
5
+ @template = template
6
+ end
7
+
8
+ private
9
+
10
+ def self.exhibit(name)
11
+ define_method(name) do
12
+ @object
13
+ end
14
+ end
15
+
16
+ def method_missing(*args, &block)
17
+ @template.send(*args, &block)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Exhibit
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,9 @@
1
+ Description:
2
+ Generates a presenter for the exhibit gem.
3
+
4
+ Example:
5
+ rails generate presenter User
6
+
7
+ This will create:
8
+ app/presenters
9
+ app/presenters/user_presenter.rb
@@ -0,0 +1,26 @@
1
+ require 'rails/generators'
2
+
3
+ module Exhibit
4
+ class PresenterGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __FILE__)
6
+ argument :presenter_name, :type => :string
7
+
8
+ def create_presenter
9
+ template "presenter", "app/presenters/#{file_name}.rb"
10
+ end
11
+
12
+ private
13
+
14
+ def file_name
15
+ "#{underscore}_presenter"
16
+ end
17
+
18
+ def class_name
19
+ presenter_name.camelize
20
+ end
21
+
22
+ def underscore
23
+ presenter_name.underscore
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ class <%= class_name %>Presenter < Exhibit::Presenter
2
+ exhibit :<%= underscore %>
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :exhibit do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exhibit
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Robin Brouwer
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-10-06 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ hash: 7
28
+ segments:
29
+ - 3
30
+ - 0
31
+ - 0
32
+ version: 3.0.0
33
+ requirement: *id001
34
+ type: :runtime
35
+ name: rails
36
+ prerelease: false
37
+ - !ruby/object:Gem::Dependency
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ requirement: *id002
48
+ type: :development
49
+ name: sqlite3
50
+ prerelease: false
51
+ description: "Exhibit is a simple gem to generate and work with presenters in Rails 3. It is based on the solution Ryan Bates created in Railscasts Pro episode #287."
52
+ email:
53
+ - robin@45north.nl
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files: []
59
+
60
+ files:
61
+ - lib/exhibit/helpers.rb
62
+ - lib/exhibit/presenter.rb
63
+ - lib/exhibit/version.rb
64
+ - lib/exhibit.rb
65
+ - lib/generators/exhibit/presenter_generator.rb
66
+ - lib/generators/exhibit/templates/presenter
67
+ - lib/generators/exhibit/USAGE
68
+ - lib/tasks/exhibit_tasks.rake
69
+ - MIT-LICENSE
70
+ - Rakefile
71
+ - README.md
72
+ has_rdoc: true
73
+ homepage: https://github.com/RobinBrouwer/exhibit
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:
102
+ rubygems_version: 1.3.7
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Exhibit is a simple gem to generate and work with presenters in Rails 3.
106
+ test_files: []
107
+