mongoid_document_editor 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/app/controllers/mongoid/document_editor/application_controller.rb +7 -0
- data/app/controllers/mongoid/document_editor/documents_controller.rb +34 -0
- data/app/helpers/mongoid/document_editor/documents_helper.rb +44 -0
- data/app/views/mongoid/document_editor/documents/edit.html.erb +6 -0
- data/app/views/mongoid/document_editor/documents/index.html.erb +1 -0
- data/app/views/mongoid/document_editor/layouts/application.html.erb +9 -0
- data/config/routes.rb +7 -0
- data/lib/mongoid/document_editor/configuration/form_configuration.rb +11 -0
- data/lib/mongoid/document_editor/configuration/index_configuration.rb +11 -0
- data/lib/mongoid/document_editor/configuration.rb +22 -0
- data/lib/mongoid/document_editor/engine.rb +14 -0
- data/lib/mongoid/document_editor/version.rb +5 -0
- data/lib/mongoid/document_editor.rb +53 -0
- data/lib/mongoid_document_editor.rb +1 -0
- data/mongoid_document_editor.gemspec +31 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 920e9e158e080607e1c9b4f715924505068850f8
|
4
|
+
data.tar.gz: 75281429ff2f04be8ca4f1254246d03afae6eadb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ca5938f12f2c21c5bd61f437d3962169504d3ca92414db3446987aa16763e1715c95995b8b5f6b66cadfdd41d7a6bed56fb4aec6e14e6c73d19cb2cc4e6c61e7
|
7
|
+
data.tar.gz: 77410914726e7158ae2beea4a21e1f30988f1017a6f250aea803d2599d241f0c43adc0c4e95a94d1545c1d2e981e207214aecbe988211500ab59bd40378a52fb
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Nick DeSteffen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# MongoidDocumentEditor
|
2
|
+
|
3
|
+
Mongoid
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'mongoid_document_editor'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install mongoid_document_editor
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Mongoid
|
2
|
+
module DocumentEditor
|
3
|
+
class DocumentsController < ApplicationController
|
4
|
+
include DocumentsHelper
|
5
|
+
|
6
|
+
layout "mongoid/document_editor/layouts/application"
|
7
|
+
|
8
|
+
before_filter Mongoid::DocumentEditor.authentication_filter
|
9
|
+
|
10
|
+
def index
|
11
|
+
end
|
12
|
+
|
13
|
+
def edit
|
14
|
+
@klass = params[:type].classify.constantize
|
15
|
+
@document = @klass.find(params[:id])
|
16
|
+
end
|
17
|
+
|
18
|
+
def update
|
19
|
+
@klass = params[:type].classify.constantize
|
20
|
+
@document = @klass.find(params[:id])
|
21
|
+
@document.update_attributes(document_params)
|
22
|
+
|
23
|
+
redirect_to edit_document_path(params[:type], @document.id)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def document_params
|
29
|
+
params.require(params[:type].to_sym).permit!
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Mongoid
|
2
|
+
module DocumentEditor
|
3
|
+
module DocumentsHelper
|
4
|
+
|
5
|
+
def document_edit_field(form, klass, document, name, config)
|
6
|
+
name = name.to_s
|
7
|
+
return nil if private_field?(name)
|
8
|
+
|
9
|
+
values = config.fetch(:values, nil)
|
10
|
+
if values.respond_to?(:call) && values.arity == 1
|
11
|
+
values = values.call(document)
|
12
|
+
elsif values.respond_to?(:call)
|
13
|
+
values = values.call
|
14
|
+
end
|
15
|
+
|
16
|
+
label = config.fetch(:label, :name)
|
17
|
+
value = config.fetch(:value, :id)
|
18
|
+
type = config.fetch(:type, nil)
|
19
|
+
options = {}
|
20
|
+
options = {as: :boolean} if klass.fields[name].type == Boolean
|
21
|
+
options = {as: :numeric} if klass.fields[name].type == Integer
|
22
|
+
options = {as: :text} if type == :text
|
23
|
+
options = {collection: values} if values.present?
|
24
|
+
|
25
|
+
options.merge!(label_method: label, value_method: value) if config[:label] && config[:value]
|
26
|
+
|
27
|
+
if klass.fields[name].type == Array && values
|
28
|
+
return form.collection_check_boxes(name, values, value, label)
|
29
|
+
else
|
30
|
+
return form.input(name, options)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def private_field?(name)
|
37
|
+
return true if name.start_with?("_")
|
38
|
+
return true if ["created_at", "updated_at"].include?(name)
|
39
|
+
return false
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<%= simple_form_for @document, url: update_document_path(@klass.to_s.downcase, @document) do |f| %>
|
2
|
+
<% Mongoid::DocumentEditor.fields_for(@klass).each_pair do |name, config| %>
|
3
|
+
<p><%= document_edit_field(f, @klass, @document, name, config) %></p>
|
4
|
+
<% end %>
|
5
|
+
<%= f.submit %>
|
6
|
+
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1>Document Editor</h1>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Mongoid
|
2
|
+
module DocumentEditor
|
3
|
+
|
4
|
+
class Configuration
|
5
|
+
|
6
|
+
def initialize(document_class, configuration, &block)
|
7
|
+
@document_class = document_class
|
8
|
+
@configuration = configuration
|
9
|
+
end
|
10
|
+
|
11
|
+
def evaluate(&block)
|
12
|
+
@self_before_instance_eval = eval("self", block.binding)
|
13
|
+
instance_eval(&block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def method_missing(method, *args, &block)
|
17
|
+
@self_before_instance_eval.send(method, *args, &block)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Mongoid
|
2
|
+
module DocumentEditor
|
3
|
+
class Engine < ::Rails::Engine
|
4
|
+
isolate_namespace Mongoid::DocumentEditor
|
5
|
+
|
6
|
+
config.after_initialize do |app|
|
7
|
+
app.routes.prepend do
|
8
|
+
mount Mongoid::DocumentEditor::Engine => "/documents"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "mongoid/document_editor/version"
|
2
|
+
require "mongoid/document_editor/engine"
|
3
|
+
require "mongoid/document_editor/configuration"
|
4
|
+
require "mongoid/document_editor/configuration/form_configuration"
|
5
|
+
require "mongoid/document_editor/configuration/index_configuration"
|
6
|
+
|
7
|
+
module Mongoid
|
8
|
+
module DocumentEditor
|
9
|
+
extend ActiveSupport::Autoload
|
10
|
+
|
11
|
+
mattr_accessor :form_configuration
|
12
|
+
@@form_configuration = {}
|
13
|
+
|
14
|
+
mattr_accessor :index_configuration
|
15
|
+
@@index_configuration = {}
|
16
|
+
|
17
|
+
mattr_accessor :authentication_filter
|
18
|
+
@@authentication_filter = nil
|
19
|
+
|
20
|
+
def self.configure(&block)
|
21
|
+
instance_eval(&block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.fields_for(klass)
|
25
|
+
default_fields = {}
|
26
|
+
klass.fields.each_pair do |name, options|
|
27
|
+
default_fields[name.to_s] = {}
|
28
|
+
end
|
29
|
+
@@form_configuration.fetch(klass, default_fields)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.index_for(klass)
|
33
|
+
@@index_configuration[klass]
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.form_configuration_for(document_class, &block)
|
37
|
+
@@form_configuration[document_class] = {}
|
38
|
+
config = FormConfiguration.new(document_class, @@form_configuration[document_class])
|
39
|
+
config.evaluate(&block)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.index_configuration_for(document_class, &block)
|
43
|
+
@@index_configuration[document_class] = {}
|
44
|
+
config = IndexConfiguration.new(document_class, @@index_configuration[document_class])
|
45
|
+
config.evaluate(&block)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.authenticate_with(filter)
|
49
|
+
@@authentication_filter = filter
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'mongoid/document_editor'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mongoid/document_editor/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mongoid_document_editor"
|
8
|
+
spec.version = Mongoid::DocumentEditor::VERSION
|
9
|
+
spec.authors = ["Nick DeSteffen"]
|
10
|
+
spec.email = ["nick.desteffen@gmail.com"]
|
11
|
+
spec.description = %q{Write a gem description}
|
12
|
+
spec.summary = %q{Write a gem summary}
|
13
|
+
spec.homepage = "https://github.com/nick-desteffen/mongoid-document-editor"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = Dir.glob("lib/**/*")
|
17
|
+
spec.files += Dir.glob("app/**/*")
|
18
|
+
spec.files += Dir.glob("config/**/*")
|
19
|
+
spec.files += %w(README.md LICENSE.txt mongoid_document_editor.gemspec)
|
20
|
+
|
21
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency "rails", "~> 3.2.0"
|
25
|
+
spec.add_dependency "simple_form", "~> 2.1.0"
|
26
|
+
spec.add_dependency "mongoid", "~> 3.1.0"
|
27
|
+
spec.add_dependency "strong_parameters"
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
30
|
+
spec.add_development_dependency "rake"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongoid_document_editor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick DeSteffen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: simple_form
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.1.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.1.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mongoid
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.1.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.1.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: strong_parameters
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Write a gem description
|
98
|
+
email:
|
99
|
+
- nick.desteffen@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- lib/mongoid/document_editor/configuration/form_configuration.rb
|
105
|
+
- lib/mongoid/document_editor/configuration/index_configuration.rb
|
106
|
+
- lib/mongoid/document_editor/configuration.rb
|
107
|
+
- lib/mongoid/document_editor/engine.rb
|
108
|
+
- lib/mongoid/document_editor/version.rb
|
109
|
+
- lib/mongoid/document_editor.rb
|
110
|
+
- lib/mongoid_document_editor.rb
|
111
|
+
- app/controllers/mongoid/document_editor/application_controller.rb
|
112
|
+
- app/controllers/mongoid/document_editor/documents_controller.rb
|
113
|
+
- app/helpers/mongoid/document_editor/documents_helper.rb
|
114
|
+
- app/views/mongoid/document_editor/documents/edit.html.erb
|
115
|
+
- app/views/mongoid/document_editor/documents/index.html.erb
|
116
|
+
- app/views/mongoid/document_editor/layouts/application.html.erb
|
117
|
+
- config/routes.rb
|
118
|
+
- README.md
|
119
|
+
- LICENSE.txt
|
120
|
+
- mongoid_document_editor.gemspec
|
121
|
+
homepage: https://github.com/nick-desteffen/mongoid-document-editor
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.0.3
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: Write a gem summary
|
145
|
+
test_files: []
|