prospecto 0.0.7 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,3 +1,3 @@
1
1
  # Prospecto
2
2
 
3
- *Seperation of views and templates in rails.*
3
+ *Simple rails presenter that emphasizes using plain old ruby.*
@@ -0,0 +1,13 @@
1
+ Description:
2
+ Generate a simple presenter class.
3
+
4
+ The name can be anything you want, there is no direct correlation between a
5
+ presenter and a single model, although there is often a correlation with the
6
+ presenter and the controller.
7
+
8
+ Example:
9
+ rails generate presenter User
10
+
11
+ This will create:
12
+ app/presenters/user_presenter.rb
13
+ spec/presenters/user_presenter_spec.rb
@@ -0,0 +1,25 @@
1
+ class PresenterGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def write_presenter
5
+ template 'presenter.rb', "app/presenters/#{file_name_root}_presenter.rb"
6
+ end
7
+
8
+ def write_presenter_spec
9
+ template 'presenter_spec.rb', "spec/presenters/#{file_name_root}_presenter_spec.rb"
10
+ end
11
+
12
+ protected
13
+
14
+ def file_name_root
15
+ name.underscore
16
+ end
17
+
18
+ def class_name
19
+ name.camelize
20
+ end
21
+
22
+ def single_name
23
+ name.underscore.singularize
24
+ end
25
+ end
@@ -0,0 +1,8 @@
1
+ class <%= class_name %>Presenter < Prospecto::PresenterView
2
+ # The presenter class is completely optional and just gives a
3
+ # little initialization sugar. Ala:
4
+ #
5
+ # accepts :<%= single_name %>
6
+ # presents :<%= single_name %>_public
7
+ #
8
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= class_name %>Presenter do
4
+ end
@@ -1,3 +1,3 @@
1
1
  require 'prospecto/version'
2
- require 'prospecto/view'
2
+ require 'prospecto/presenter_view'
3
3
  require 'prospecto/railtie' if defined?(Rails)
@@ -0,0 +1,30 @@
1
+ module Prospecto
2
+ class PresenterView
3
+ def initialize(args={})
4
+ args.each do |name, value|
5
+ if respond_to? name
6
+ instance_variable_set("@#{name}", value)
7
+ else
8
+ # Stop everything there is a design problem.
9
+ raise ArgumentError.new("Unknown property '#{name}' for class '#{self.class.name}'.")
10
+ end
11
+ end
12
+ end
13
+
14
+ class << self
15
+ # "Presents" means a member will be reflected out to the view
16
+ alias :presents :attr_reader
17
+
18
+ # Accepts means the view uses the member internally, but it is not available
19
+ # outside the class.
20
+ def accepts(*args)
21
+ args.each do |name|
22
+ define_method name do
23
+ instance_variable_get("@#{name}")
24
+ end
25
+ protected name
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,17 +1,9 @@
1
1
  require 'rails/railtie'
2
- require 'prospecto/controller'
3
2
 
4
3
  module Prospecto
5
4
  class Railtie < Rails::Railtie
6
5
  initializer "prospecto.initialize" do |app|
7
- ActionController::Base.extend(ProspectoController)
8
- ActionController::Base.class_eval { enable_prospecto }
9
- end
10
6
 
11
- initializer 'prospecto.autoload', :before => :set_autoload_paths do |app|
12
- Dir["#{app.root}/app/views/**/"].each do |view_folder|
13
- app.config.autoload_paths << view_folder
14
- end
15
7
  end
16
8
  end
17
9
  end
@@ -1,3 +1,3 @@
1
1
  module Prospecto
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -32,3 +32,11 @@
32
32
   (0.0ms) rollback transaction
33
33
   (0.3ms) begin transaction
34
34
   (0.0ms) rollback transaction
35
+  (0.5ms) begin transaction
36
+  (0.1ms) rollback transaction
37
+  (0.3ms) begin transaction
38
+  (0.0ms) rollback transaction
39
+  (0.4ms) begin transaction
40
+  (0.1ms) rollback transaction
41
+  (0.1ms) begin transaction
42
+  (0.0ms) rollback transaction
@@ -1,10 +1,15 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class ViewTest < ActiveSupport::TestCase
4
- test "auto generates a constructor and attr_readers" do
5
- class TestConstructor < Prospecto::View
6
- accepts :name, :age
7
- end
4
+ class TestConstructor < Prospecto::View
5
+ accepts :name, :age
6
+ end
7
+
8
+ test "auto generates a constructor" do
9
+ assert TestConstructor.new(:name => "Bob", :age => 44).present?
10
+ end
11
+
12
+ test "auto generates attr_readers" do
8
13
  person = TestConstructor.new(:name => "Bob", :age => 44)
9
14
  assert_equal person.name, "Bob"
10
15
  assert_equal person.age, 44
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prospecto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-16 00:00:00.000000000 Z
12
+ date: 2012-05-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70285831432440 !ruby/object:Gem::Requirement
16
+ requirement: &70256414237120 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70285831432440
24
+ version_requirements: *70256414237120
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3
27
- requirement: &70285831431800 !ruby/object:Gem::Requirement
27
+ requirement: &70256414236320 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70285831431800
35
+ version_requirements: *70256414236320
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: turn
38
- requirement: &70285831431100 !ruby/object:Gem::Requirement
38
+ requirement: &70256414235640 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70285831431100
46
+ version_requirements: *70256414235640
47
47
  description: ''
48
48
  email:
49
49
  - bigjasonwebb@gmail.com
@@ -51,10 +51,13 @@ executables: []
51
51
  extensions: []
52
52
  extra_rdoc_files: []
53
53
  files:
54
- - lib/prospecto/controller.rb
54
+ - lib/generators/presenter/presenter_generator.rb
55
+ - lib/generators/presenter/templates/presenter.rb
56
+ - lib/generators/presenter/templates/presenter_spec.rb
57
+ - lib/generators/presenter/USAGE
58
+ - lib/prospecto/presenter_view.rb
55
59
  - lib/prospecto/railtie.rb
56
60
  - lib/prospecto/version.rb
57
- - lib/prospecto/view.rb
58
61
  - lib/prospecto.rb
59
62
  - lib/tasks/prospecto_tasks.rake
60
63
  - MIT-LICENSE
@@ -81,7 +84,7 @@ files:
81
84
  - test/dummy/config/locales/en.yml
82
85
  - test/dummy/config/routes.rb
83
86
  - test/dummy/config.ru
84
- - test/dummy/db/test.sqlite3
87
+ - test/dummy/log/development.log
85
88
  - test/dummy/log/test.log
86
89
  - test/dummy/public/404.html
87
90
  - test/dummy/public/422.html
@@ -107,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
110
  version: '0'
108
111
  segments:
109
112
  - 0
110
- hash: 3465733031179072830
113
+ hash: -40013224359218802
111
114
  required_rubygems_version: !ruby/object:Gem::Requirement
112
115
  none: false
113
116
  requirements:
@@ -116,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
119
  version: '0'
117
120
  segments:
118
121
  - 0
119
- hash: 3465733031179072830
122
+ hash: -40013224359218802
120
123
  requirements: []
121
124
  rubyforge_project:
122
125
  rubygems_version: 1.8.10
@@ -145,7 +148,7 @@ test_files:
145
148
  - test/dummy/config/locales/en.yml
146
149
  - test/dummy/config/routes.rb
147
150
  - test/dummy/config.ru
148
- - test/dummy/db/test.sqlite3
151
+ - test/dummy/log/development.log
149
152
  - test/dummy/log/test.log
150
153
  - test/dummy/public/404.html
151
154
  - test/dummy/public/422.html
@@ -1,9 +0,0 @@
1
- module Prospecto
2
- module ProspectoController
3
- def enable_prospecto
4
- view_path = Rails.root.join("app/views")
5
- resolver = ActionView::FileSystemResolver.new(view_path, ":prefix/templates/:action{.:locale,}{.:formats,}{.:handlers,}")
6
- prepend_view_path(resolver)
7
- end
8
- end
9
- end
@@ -1,15 +0,0 @@
1
- module Prospecto
2
- class View
3
- # lookup_context is required for rspec integration to work.
4
- attr_reader :lookup_context
5
-
6
- def self.accepts(*names)
7
- attr_accessor *names
8
- define_method :initialize do |args={}|
9
- args.each do |name, value|
10
- instance_variable_set("@#{name}", value)
11
- end
12
- end
13
- end
14
- end
15
- end