rails_admin_state_machine 1.0.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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 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.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = RailsAdminStateMachine
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
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 = 'RailsAdminStateMachine'
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
+
26
+ Bundler::GemHelper.install_tasks
27
+
@@ -0,0 +1 @@
1
+ = form.send field.view_helper, field.method_name, field._html_attributes
@@ -0,0 +1,10 @@
1
+ require "rails_admin_state_machine/engine"
2
+
3
+ module RailsAdminStateMachine
4
+ end
5
+
6
+ require 'rails_admin/config/fields'
7
+ require 'rails_admin/config/fields/base'
8
+
9
+ require "rails_admin_state_machine/inputs/state_event"
10
+ require "rails_admin_state_machine/inputs/state"
@@ -0,0 +1,4 @@
1
+ module RailsAdminStateMachine
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,38 @@
1
+ module RailsAdmin
2
+ module Config
3
+ module Fields
4
+ module Types
5
+ class State < RailsAdmin::Config::Fields::Base
6
+ RailsAdmin::Config::Fields::Types::register(self)
7
+
8
+ register_instance_option(:partial) do
9
+ :form_enumeration
10
+ end
11
+
12
+ register_instance_option(:enum) do
13
+ bindings[:object].class.state_machine(@name).states.map {|s| [s.human_name, s.name] }
14
+ end
15
+
16
+ register_instance_option(:pretty_value) do
17
+ if enum.is_a?(::Hash)
18
+ enum.reject{|k,v| v.to_s != value.to_s}.keys.first.to_s.presence || value.presence || ' - '
19
+ elsif enum.is_a?(::Array) && enum.first.is_a?(::Array)
20
+ enum.find{|e|e[1].to_s == value.to_s}.try(:first).to_s.presence || value.presence || ' - '
21
+ else
22
+ value.presence || ' - '
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
32
+ if properties[:name] == :state
33
+ fields << RailsAdmin::Config::Fields::Types::State.new(parent, properties[:name], properties)
34
+ true
35
+ else
36
+ false
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ module RailsAdmin
2
+ module Config
3
+ module Fields
4
+ module Types
5
+ class StateEvent < RailsAdmin::Config::Fields::Base
6
+ RailsAdmin::Config::Fields::Types::register(self)
7
+
8
+ register_instance_option(:partial) do
9
+ :form_enumeration
10
+ end
11
+
12
+ register_instance_option(:enum) do
13
+ bindings[:object].send("state_transitions").map {|t| ["#{t.from} > #{t.to}", t.event] if t.from_name != t.to_name }.compact
14
+ end
15
+
16
+ register_instance_option(:pretty_value) do
17
+ if enum.is_a?(::Hash)
18
+ enum.reject{|k,v| v.to_s != value.to_s}.keys.first.to_s.presence || value.presence || ' - '
19
+ elsif enum.is_a?(::Array) && enum.first.is_a?(::Array)
20
+ enum.find{|e|e[1].to_s == value.to_s}.try(:first).to_s.presence || value.presence || ' - '
21
+ else
22
+ value.presence || ' - '
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
32
+ if properties[:name] == :state_event
33
+ fields << RailsAdmin::Config::Fields::Types::StateEvent.new(parent, properties[:name], properties)
34
+ true
35
+ else
36
+ false
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module RailsAdminStateMachine
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_admin_state_machine
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexander Shcherbinin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.2
30
+ description: ! 'Add state_machine inputs state and state_event for rails_admin '
31
+ email:
32
+ - realmyst@ya.ru
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - app/views/rails_admin/main/_form_state_machine.html.haml
38
+ - lib/rails_admin_state_machine/engine.rb
39
+ - lib/rails_admin_state_machine/inputs/state.rb
40
+ - lib/rails_admin_state_machine/inputs/state_event.rb
41
+ - lib/rails_admin_state_machine/version.rb
42
+ - lib/rails_admin_state_machine.rb
43
+ - MIT-LICENSE
44
+ - Rakefile
45
+ - README.rdoc
46
+ homepage: https://github.com/realmyst/rails_admin_state_machine
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 1.8.24
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Add custom inputs for rails_admin
70
+ test_files: []