base_presenter 0.0.8 → 0.0.9
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.
- data/.travis.yml +4 -0
- data/README.md +16 -5
- data/Rakefile +8 -0
- data/base_presenter.gemspec +2 -3
- data/lib/application_helper.rb +4 -2
- data/lib/base_presenter/version.rb +1 -1
- data/lib/generators/base_presenter/install/USAGE +3 -0
- data/lib/generators/base_presenter/install/install_generator.rb +18 -0
- data/lib/generators/base_presenter/install/templates/application_presenter.rb +3 -0
- metadata +7 -3
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# BasePresenter
|
2
|
+
[](http://badge.fury.io/rb/base_presenter)
|
3
|
+
[](https://travis-ci.org/raglub/base_presenter)
|
2
4
|
|
3
5
|
The gem adds "Presenter" functionality into Rails application.
|
4
6
|
|
5
|
-
|
7
|
+
# Installation
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
8
10
|
|
@@ -16,12 +18,21 @@ Or install it yourself as:
|
|
16
18
|
|
17
19
|
$ gem install base_presenter
|
18
20
|
|
19
|
-
|
21
|
+
# Getting Started
|
20
22
|
|
21
|
-
|
23
|
+
## First step
|
24
|
+
|
25
|
+
Usa a generator
|
26
|
+
|
27
|
+
rails g base_presenter:install [model_name]
|
28
|
+
|
29
|
+
## Second step
|
30
|
+
|
31
|
+
For model_name equal 'example' we should get file in director root_rails/app/presenters/example_presenter.rb which we can improve.
|
32
|
+
For example:
|
22
33
|
|
23
34
|
```ruby
|
24
|
-
class ExamplePresenter <
|
35
|
+
class ExamplePresenter < ApplicationPresenter
|
25
36
|
presents :example
|
26
37
|
delegate :id, to: :example
|
27
38
|
|
@@ -60,6 +71,7 @@ and in file show.html.erb with:
|
|
60
71
|
Class name: <%= presenter.class_name %>
|
61
72
|
<% end %>
|
62
73
|
```
|
74
|
+
|
63
75
|
## Methods
|
64
76
|
|
65
77
|
Methods of BasePresenter
|
@@ -68,4 +80,3 @@ Method returns span with 'None given' when value is blank
|
|
68
80
|
```erb
|
69
81
|
#handle_none(value)
|
70
82
|
```
|
71
|
-
|
data/Rakefile
CHANGED
data/base_presenter.gemspec
CHANGED
@@ -6,10 +6,10 @@ require 'base_presenter/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "base_presenter"
|
8
8
|
spec.version = BasePresenter::VERSION
|
9
|
-
spec.date = '2013-10-
|
9
|
+
spec.date = '2013-10-26'
|
10
10
|
spec.authors = ["Michał Szyma"]
|
11
11
|
spec.email = ["raglub.ruby@gmail.com"]
|
12
|
-
spec.description = %q{The gem adds "Presenter" functionality into Rails application}
|
12
|
+
spec.description = %q{The gem adds "Presenter" functionality into Rails application.}
|
13
13
|
spec.summary = %q{The gem adds "Presenter" functionality into Rails application}
|
14
14
|
spec.homepage = "https://github.com/raglub/base_presenter"
|
15
15
|
spec.license = "MIT"
|
@@ -23,5 +23,4 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "rake"
|
24
24
|
spec.add_development_dependency 'rspec-rails'
|
25
25
|
spec.add_development_dependency 'rails', ">= 3.0.0"
|
26
|
-
|
27
26
|
end
|
data/lib/application_helper.rb
CHANGED
@@ -11,8 +11,10 @@ module ApplicationHelper
|
|
11
11
|
presenter = klass.new(object_or_class, self)
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
if block_given?
|
15
|
+
block.arity > 0 ? yield(presenter) : presenter.instance_eval(&block)
|
16
|
+
end
|
17
|
+
|
16
18
|
return presenter
|
17
19
|
end
|
18
20
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class BasePresenter
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
argument :model_name, :type => :string, :default => "example"
|
6
|
+
def generate_install
|
7
|
+
copy_file "application_presenter.rb", "app/presenters/application_presenter.rb"
|
8
|
+
create_file "app/presenters/#{model_name.underscore}_presenter.rb", <<-FILE
|
9
|
+
class #{model_name.classify}Presenter < ApplicationPresenter
|
10
|
+
presents :#{model_name.underscore.split("/").last}
|
11
|
+
|
12
|
+
# delegete :name
|
13
|
+
end
|
14
|
+
FILE
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: base_presenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
12
|
+
date: 2013-10-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -75,7 +75,7 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: 3.0.0
|
78
|
-
description: The gem adds "Presenter" functionality into Rails application
|
78
|
+
description: The gem adds "Presenter" functionality into Rails application.
|
79
79
|
email:
|
80
80
|
- raglub.ruby@gmail.com
|
81
81
|
executables: []
|
@@ -83,6 +83,7 @@ extensions: []
|
|
83
83
|
extra_rdoc_files: []
|
84
84
|
files:
|
85
85
|
- .gitignore
|
86
|
+
- .travis.yml
|
86
87
|
- Gemfile
|
87
88
|
- LICENSE.txt
|
88
89
|
- README.md
|
@@ -91,6 +92,9 @@ files:
|
|
91
92
|
- lib/application_helper.rb
|
92
93
|
- lib/base_presenter.rb
|
93
94
|
- lib/base_presenter/version.rb
|
95
|
+
- lib/generators/base_presenter/install/USAGE
|
96
|
+
- lib/generators/base_presenter/install/install_generator.rb
|
97
|
+
- lib/generators/base_presenter/install/templates/application_presenter.rb
|
94
98
|
- spec/dummy/app/controllers/application_controller.rb
|
95
99
|
- spec/dummy/app/controllers/concerns/.keep
|
96
100
|
- spec/dummy/app/helpers/application_helper.rb
|