iandb-merb_stateful_display 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Ivey & Brown, Inc.
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.
data/README ADDED
@@ -0,0 +1,19 @@
1
+ merb_stateful_display
2
+ =====================
3
+
4
+ stateful_display()
5
+ Works like display, but checks to see if the object has a 'state'
6
+ method. Especially useful in show and edit, where it will check
7
+ a given object and look for a template to match the current state
8
+ of the object.
9
+
10
+ EX:
11
+ def show
12
+ ...
13
+ @ord.state = 'in_cart'
14
+ sdisplay(@ord)
15
+ end
16
+
17
+ Looks for a template named "show_in_cart.html.erb" else it falls
18
+ back to a standard behavior of "show.html.erb"
19
+
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+
4
+ require 'merb-core'
5
+ require 'merb-core/tasks/merb'
6
+
7
+ GEM_NAME = "merb_stateful_display"
8
+ GEM_VERSION = "0.0.1"
9
+
10
+ spec = Gem::Specification.new do |s|
11
+ s.rubyforge_project = 'merb'
12
+ s.name = GEM_NAME
13
+ s.version = GEM_VERSION
14
+ s.platform = Gem::Platform::RUBY
15
+ s.has_rdoc = true
16
+ s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
17
+ s.summary = "Simple extension of Merb's display() that chooses templates based on an object's state"
18
+ s.description = s.summary
19
+ s.authors = ["Michael D. Ivey", "Shay Arnett"]
20
+ s.email = "info@iveyandbrown.com"
21
+ s.homepage = "http://github.com/iandb/merb_stateful_display"
22
+ s.add_dependency('merb-core', '>= 0.9.10')
23
+ s.require_path = 'lib'
24
+ s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
25
+
26
+ end
27
+
28
+ Rake::GemPackageTask.new(spec) do |pkg|
29
+ pkg.gem_spec = spec
30
+ end
31
+
32
+ desc "install the plugin as a gem"
33
+ task :install do
34
+ Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
35
+ end
36
+
37
+ desc "Uninstall the gem"
38
+ task :uninstall do
39
+ Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
40
+ end
41
+
42
+ desc "Create a gemspec file"
43
+ task :gemspec do
44
+ File.open("#{GEM_NAME}.gemspec", "w") do |file|
45
+ file.puts spec.to_ruby
46
+ end
47
+ end
data/TODO ADDED
@@ -0,0 +1,5 @@
1
+ TODO:
2
+ Fix LICENSE with your name
3
+ Fix Rakefile with your name and contact info
4
+ Add your code to lib/merb_stateful_display.rb
5
+ Add your Merb rake tasks to lib/merb_stateful_display/merbtasks.rb
@@ -0,0 +1,14 @@
1
+ require 'merb_stateful_display/instance_methods'
2
+
3
+ # make sure we're running inside Merb
4
+ if defined?(Merb::Plugins)
5
+
6
+ # Merb gives you a Merb::Plugins.config hash...feel free to put your stuff in your piece of it
7
+ Merb::Plugins.config[:merb_stateful_display] = {
8
+ :state_method => :state
9
+ }
10
+
11
+ Merb::BootLoader.after_app_loads do
12
+ Application.send(:include,MerbStatefulDisplay::InstanceMethods)
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ module MerbStatefulDisplay
2
+ module InstanceMethods
3
+
4
+ def _default_state_display_method
5
+ Merb::Plugins.config[:merb_stateful_display][:state_method] || :state
6
+ end
7
+
8
+ # Stateful display()
9
+ # Works like display, but checks to see if the object has a 'state'
10
+ # method. Especially useful in show and edit
11
+ def sdisplay(object, thing = nil, opts = {})
12
+ state_method = opts.delete(:state_method) || _default_state_display_method
13
+ unless object.respond_to?(state_method)
14
+ return display(object, thing, opts)
15
+ end
16
+ begin
17
+ nopts = opts.dup
18
+ template ||= "#{action_name}_#{object.send(state_method)}".to_sym
19
+ display(object, template, nopts)
20
+ rescue
21
+ display(object, action_name.to_sym, opts)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "merb_stateful_display" do
4
+ it "should do nothing" do
5
+ true.should == true
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iandb-merb_stateful_display
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael D. Ivey
8
+ - Shay Arnett
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2008-10-30 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: merb
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.9.10
24
+ version:
25
+ description: Simple extension of Merb's display() that chooses templates based on an object's state
26
+ email: info@iveyandbrown.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README
33
+ - LICENSE
34
+ - TODO
35
+ files:
36
+ - LICENSE
37
+ - README
38
+ - Rakefile
39
+ - TODO
40
+ - lib/merb_stateful_display
41
+ - lib/merb_stateful_display/instance_methods.rb
42
+ - lib/merb_stateful_display.rb
43
+ - spec/merb_stateful_display_spec.rb
44
+ - spec/spec_helper.rb
45
+ has_rdoc: true
46
+ homepage: http://github.com/iandb/merb_stateful_display
47
+ post_install_message:
48
+ rdoc_options: []
49
+
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project: merb
67
+ rubygems_version: 1.2.0
68
+ signing_key:
69
+ specification_version: 2
70
+ summary: Simple extension of Merb's display() that chooses templates based on an object's state
71
+ test_files: []
72
+