action-presenter 0.2.0
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/Rakefile +76 -0
- data/lib/action-presenter.rb +9 -0
- data/lib/action-presenter/base.rb +52 -0
- data/lib/action-presenter/railtie.rb +9 -0
- data/lib/action-presenter/record_helper.rb +16 -0
- data/test/test_helper.rb +14 -0
- metadata +72 -0
data/Rakefile
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require "rake/rdoctask"
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
|
5
|
+
spec = Gem::Specification.new do |s|
|
6
|
+
s.name = "action-presenter"
|
7
|
+
s.authors = ["Lance Pollard"]
|
8
|
+
s.version = "0.2.0"
|
9
|
+
s.description = "Simple Presenters"
|
10
|
+
s.summary = "Simple Presenters"
|
11
|
+
s.homepage = "http://github.com/viatropos/action-presenter"
|
12
|
+
s.email = "lancejpollard@gmail.com"
|
13
|
+
s.rubyforge_project = "action-presenter"
|
14
|
+
s.platform = Gem::Platform::RUBY
|
15
|
+
s.files = %w(Rakefile) + Dir["{lib,rails,test}/**/*"] - Dir["test/tmp"]
|
16
|
+
s.require_path = "lib"
|
17
|
+
end
|
18
|
+
|
19
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
20
|
+
pkg.gem_spec = spec
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'run unit tests'
|
24
|
+
task :test do
|
25
|
+
Dir["test/**/*"].each do |file|
|
26
|
+
next unless File.basename(file) =~ /test_/
|
27
|
+
next unless File.extname(file) == ".rb"
|
28
|
+
system "ruby #{file}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "Create .gemspec file (useful for github)"
|
33
|
+
task :gemspec do
|
34
|
+
File.open("#{spec.name}.gemspec", "w") do |f|
|
35
|
+
f.puts spec.to_ruby
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "Build the gem into the current directory"
|
40
|
+
task :gem => :gemspec do
|
41
|
+
`gem build #{spec.name}.gemspec`
|
42
|
+
end
|
43
|
+
|
44
|
+
desc "Publish gem to rubygems"
|
45
|
+
task :publish => [:package] do
|
46
|
+
%x[gem push #{spec.name}-#{spec.version}.gem]
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "Print a list of the files to be put into the gem"
|
50
|
+
task :manifest do
|
51
|
+
File.open("Manifest", "w") do |f|
|
52
|
+
spec.files.each do |file|
|
53
|
+
f.puts file
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
desc "Install the gem locally"
|
59
|
+
task :install => [:package] do
|
60
|
+
File.mkdir("pkg") unless File.exists?("pkg")
|
61
|
+
command = "gem install pkg/#{spec.name}-#{spec.version} --no-ri --no-rdoc"
|
62
|
+
command = "sudo #{command}" if ENV["SUDO"] == true
|
63
|
+
sh %{#{command}}
|
64
|
+
end
|
65
|
+
|
66
|
+
desc "Generate the rdoc"
|
67
|
+
Rake::RDocTask.new do |rdoc|
|
68
|
+
files = ["README.md", "lib/**/*.rb"]
|
69
|
+
rdoc.rdoc_files.add(files)
|
70
|
+
rdoc.main = "README.md"
|
71
|
+
rdoc.title = spec.summary
|
72
|
+
end
|
73
|
+
|
74
|
+
task :yank do
|
75
|
+
`gem yank #{spec.name} -v #{spec.version}`
|
76
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module ActionPresenter
|
2
|
+
# renders it as a simple hash, so the view has no logic.
|
3
|
+
# so it's ready for javascript templates.
|
4
|
+
# http://blog.dynamic50.com/2010/02/17/mustache-and-rails3/
|
5
|
+
# http://beautifulpixel.com/2007/1/11/how-to-write-a-rails-template-handler
|
6
|
+
# http://geek.swombat.com/rails-rendering-templates-outside-of-a-contro
|
7
|
+
# http://stackoverflow.com/questions/2822314/about-presenter-pattern-in-rails-is-a-better-way-to-do-it
|
8
|
+
# http://akdubya.github.com/dustjs/
|
9
|
+
class Base
|
10
|
+
unloadable
|
11
|
+
|
12
|
+
def initialize(*args, &block)
|
13
|
+
options = args.extract_options!
|
14
|
+
record = args.shift
|
15
|
+
if record.present?
|
16
|
+
klass = record.class.respond_to?(:base_class) ? record.class.base_class : record.class
|
17
|
+
|
18
|
+
name = klass.name.underscore
|
19
|
+
self.instance_variable_set("@#{name}", record)
|
20
|
+
unless self.respond_to?(name)
|
21
|
+
self.class.send :define_method, name do
|
22
|
+
instance_variable_get("@#{name}")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
options.each do |key, value|
|
28
|
+
self.send("#{key}=", value)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def controller
|
33
|
+
@controller ||= Thread.current[:controller]
|
34
|
+
end
|
35
|
+
|
36
|
+
def render
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def render_json
|
41
|
+
render.to_json
|
42
|
+
end
|
43
|
+
|
44
|
+
def method_missing(method, *args, &block)
|
45
|
+
if controller.present?
|
46
|
+
controller.send(:view_context).send(method, *args, &block)
|
47
|
+
else
|
48
|
+
super
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ActionPresenter
|
2
|
+
module RecordHelper
|
3
|
+
unloadable
|
4
|
+
def presenter
|
5
|
+
@presenter ||= "::#{self.class.base_class.name}Presenter".constantize.new(self)
|
6
|
+
end
|
7
|
+
|
8
|
+
def presenter=(value)
|
9
|
+
@presenter = value
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_template
|
13
|
+
presenter.render
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require 'shoulda'
|
6
|
+
require 'mocha'
|
7
|
+
|
8
|
+
require 'active_model'
|
9
|
+
|
10
|
+
require 'active_support/core_ext/module/deprecation'
|
11
|
+
require 'action_view/test_case'
|
12
|
+
|
13
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
14
|
+
require 'action-presenter
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: action-presenter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Lance Pollard
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-07-05 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Simple Presenters
|
23
|
+
email: lancejpollard@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- Rakefile
|
32
|
+
- lib/action-presenter/base.rb
|
33
|
+
- lib/action-presenter/railtie.rb
|
34
|
+
- lib/action-presenter/record_helper.rb
|
35
|
+
- lib/action-presenter.rb
|
36
|
+
- test/test_helper.rb
|
37
|
+
has_rdoc: true
|
38
|
+
homepage: http://github.com/viatropos/action-presenter
|
39
|
+
licenses: []
|
40
|
+
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
hash: 3
|
52
|
+
segments:
|
53
|
+
- 0
|
54
|
+
version: "0"
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project: action-presenter
|
67
|
+
rubygems_version: 1.3.7
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Simple Presenters
|
71
|
+
test_files: []
|
72
|
+
|