model_form 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dca1534fce717736619f9bb5808320c0ca108129
4
+ data.tar.gz: 3bdae74c91012cb6feadaafa9947e0fbfdd36923
5
+ SHA512:
6
+ metadata.gz: 432d7adfec039565353e225e024ab3738503933ae1cf16534ff0ee2eac37f49f6bd414ad169d515de12840c9de4aa680935296e396ddb0f8dbf1dace56137881
7
+ data.tar.gz: 5edae2e55602e2dc0a94663884bcae93c3ea0d971f92ef3a4bdee0fccdc83a5d4a0e1bb3110fe137a221add18cd012271517aa19b2a78d8172c8ce76fcf705ce
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "https://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem 'simple_form'
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.13"
12
+ gem "jeweler"
13
+ gem "simplecov", ">= 0"
14
+ end
@@ -0,0 +1,118 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ actionpack (5.0.1)
5
+ actionview (= 5.0.1)
6
+ activesupport (= 5.0.1)
7
+ rack (~> 2.0)
8
+ rack-test (~> 0.6.3)
9
+ rails-dom-testing (~> 2.0)
10
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
11
+ actionview (5.0.1)
12
+ activesupport (= 5.0.1)
13
+ builder (~> 3.1)
14
+ erubis (~> 2.7.0)
15
+ rails-dom-testing (~> 2.0)
16
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
17
+ activemodel (5.0.1)
18
+ activesupport (= 5.0.1)
19
+ activesupport (5.0.1)
20
+ concurrent-ruby (~> 1.0, >= 1.0.2)
21
+ i18n (~> 0.7)
22
+ minitest (~> 5.1)
23
+ tzinfo (~> 1.1)
24
+ addressable (2.5.0)
25
+ public_suffix (~> 2.0, >= 2.0.2)
26
+ builder (3.2.2)
27
+ concurrent-ruby (1.0.4)
28
+ descendants_tracker (0.0.4)
29
+ thread_safe (~> 0.3, >= 0.3.1)
30
+ docile (1.1.5)
31
+ erubis (2.7.0)
32
+ faraday (0.9.2)
33
+ multipart-post (>= 1.2, < 3)
34
+ git (1.3.0)
35
+ github_api (0.11.3)
36
+ addressable (~> 2.3)
37
+ descendants_tracker (~> 0.0.1)
38
+ faraday (~> 0.8, < 0.10)
39
+ hashie (>= 1.2)
40
+ multi_json (>= 1.7.5, < 2.0)
41
+ nokogiri (~> 1.6.0)
42
+ oauth2
43
+ hashie (3.4.6)
44
+ highline (1.7.8)
45
+ i18n (0.7.0)
46
+ jeweler (2.3.2)
47
+ builder
48
+ bundler (>= 1.0)
49
+ git (>= 1.2.5)
50
+ github_api (~> 0.11.0)
51
+ highline (>= 1.6.15)
52
+ nokogiri (>= 1.5.10)
53
+ psych (~> 2.2)
54
+ rake
55
+ rdoc
56
+ semver2
57
+ json (1.8.3)
58
+ jwt (1.5.6)
59
+ loofah (2.0.3)
60
+ nokogiri (>= 1.5.9)
61
+ mini_portile2 (2.1.0)
62
+ minitest (5.10.1)
63
+ multi_json (1.12.1)
64
+ multi_xml (0.6.0)
65
+ multipart-post (2.0.0)
66
+ nokogiri (1.6.8.1)
67
+ mini_portile2 (~> 2.1.0)
68
+ oauth2 (1.3.0)
69
+ faraday (>= 0.8, < 0.11)
70
+ jwt (~> 1.0)
71
+ multi_json (~> 1.3)
72
+ multi_xml (~> 0.5)
73
+ rack (>= 1.2, < 3)
74
+ psych (2.2.2)
75
+ public_suffix (2.0.5)
76
+ rack (2.0.1)
77
+ rack-test (0.6.3)
78
+ rack (>= 1.0)
79
+ rails-dom-testing (2.0.2)
80
+ activesupport (>= 4.2.0, < 6.0)
81
+ nokogiri (~> 1.6)
82
+ rails-html-sanitizer (1.0.3)
83
+ loofah (~> 2.0)
84
+ rake (12.0.0)
85
+ rdoc (3.12.2)
86
+ json (~> 1.4)
87
+ semver2 (3.4.2)
88
+ shoulda (3.5.0)
89
+ shoulda-context (~> 1.0, >= 1.0.1)
90
+ shoulda-matchers (>= 1.4.1, < 3.0)
91
+ shoulda-context (1.2.2)
92
+ shoulda-matchers (2.8.0)
93
+ activesupport (>= 3.0.0)
94
+ simple_form (3.4.0)
95
+ actionpack (> 4, < 5.1)
96
+ activemodel (> 4, < 5.1)
97
+ simplecov (0.12.0)
98
+ docile (~> 1.1.0)
99
+ json (>= 1.8, < 3)
100
+ simplecov-html (~> 0.10.0)
101
+ simplecov-html (0.10.0)
102
+ thread_safe (0.3.5)
103
+ tzinfo (1.2.2)
104
+ thread_safe (~> 0.1)
105
+
106
+ PLATFORMS
107
+ ruby
108
+
109
+ DEPENDENCIES
110
+ bundler (~> 1.13)
111
+ jeweler
112
+ rdoc (~> 3.12)
113
+ shoulda
114
+ simple_form
115
+ simplecov
116
+
117
+ BUNDLED WITH
118
+ 1.13.7
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2017 gravindra
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.
@@ -0,0 +1,31 @@
1
+ = model_form(beta)
2
+
3
+ * Generate form with one line of code.
4
+
5
+ == Overview
6
+ * This Gem act as a wrapper to simple_form gem and bootstrap.
7
+ * You can use this gem to create forms in quickest possible way.
8
+ * If you are already using simple_form gem in your application, you can use this gem to avoid writing code.
9
+
10
+ == Usage
11
+ * Add gem 'model_form' to your Gemfile
12
+ * Run bundle
13
+ * Add model_form(instance_of_model) eg. <%= model_form(@user) %>
14
+ * You can also pass the same number of parameters as of simple_form_for
15
+ * e.g. <%= model_form @user, url: 'users/someurl', html: { class: 'form-vertical'} %>
16
+
17
+ == Contributing to model_form
18
+
19
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
20
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
21
+ * Fork the project.
22
+ * Start a feature/bugfix branch.
23
+ * Commit and push until you are happy with your contribution.
24
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
25
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
26
+
27
+ == Copyright
28
+
29
+ Copyright (c) 2017 gravindra. See LICENSE.txt for
30
+ further details.
31
+
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "model_form"
18
+ gem.homepage = "http://github.com/gravindra/model_form"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{ModelForm: Save Your Time}
21
+ gem.description = %Q{ModelForm: Avoid writing html helper}
22
+ gem.email = "ravighare26@gmail.com"
23
+ gem.authors = ["gravindra", "waqar-baig", "vipin235", "sandyrocks"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ desc "Code coverage detail"
36
+ task :simplecov do
37
+ ENV['COVERAGE'] = "true"
38
+ Rake::Task['test'].execute
39
+ end
40
+
41
+ task :default => :test
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "model_form #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,8 @@
1
+ class ModelFormGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def create_initializer_file
5
+ copy_file "model_form.yml", "#{Rails.root}/config/model_form.yml"
6
+ end
7
+
8
+ end
@@ -0,0 +1,13 @@
1
+ #Global ignored attributes are active by default
2
+ global:
3
+ ignored_attributes: ['created_at', 'updated_at', 'id']
4
+
5
+ #If you want to ignore or allow the attribute on model level
6
+ #Look at the below configuration
7
+
8
+ # post:
9
+ # ignored_attributes: ['name']
10
+ # allowed_attributes: ['created_at']
11
+ # comment:
12
+ # ignored_attributes: ['post_id']
13
+ # allowed_attributes: ['created_at', 'updated_at']
@@ -0,0 +1,55 @@
1
+ module ModelForm
2
+ CONFIG_FILE = "/config/model_form.yml"
3
+
4
+ # takes ActiveRecord object
5
+ def model_form resource, options={}
6
+ default_options = {:html => { :class => 'form-horizontal' }}
7
+ default_options.deep_merge! options
8
+ simple_form_for resource, default_options do |f|
9
+ visible_fields(resource).each {|attr_name| concat f.input(attr_name) }
10
+ concat f.button(:submit)
11
+ concat cancel_link(resource)
12
+ end
13
+ end
14
+
15
+ def visible_fields resource
16
+ (resource.attribute_names - ignored_attributes(resource)) | allowed_attributes(resource)
17
+ end
18
+
19
+ def cancel_link resource
20
+ link_to t('.cancel', :default => t("helpers.links.cancel")),
21
+ send(resource.model_name.collection + '_path'), :class => 'btn btn-default'
22
+ end
23
+
24
+ def ignored_attributes resource
25
+ config = load_config
26
+ (global_config(resource, config) + model_config(resource, config)).uniq
27
+ end
28
+
29
+ def global_config resource, config
30
+ # config.fetch("global_ignored_attributes", [])
31
+ config.fetch("global", {}).fetch("ignored_attributes", [])
32
+ end
33
+
34
+ def model_config resource, config
35
+ config.fetch(resource.class.to_s.downcase, {}).fetch("ignored_attributes", [])
36
+ end
37
+
38
+ def allowed_attributes(resource)
39
+ config = load_config
40
+ config.fetch(resource.class.to_s.downcase, {}).fetch("allowed_attributes", [])
41
+ end
42
+
43
+ def load_config
44
+ file = "#{Rails.root}#{CONFIG_FILE}"
45
+ base_file = "../generators/templates/model_form.yml"
46
+ if File.exists?(file)
47
+ YAML.load_file(file)
48
+ else
49
+ YAML.load_file File.expand_path(base_file, __FILE__)
50
+ end
51
+
52
+ end
53
+
54
+ ActionView::Base.send :include, ModelForm
55
+ end
@@ -0,0 +1,68 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: model_form 0.1.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "model_form"
9
+ s.version = "0.1.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["gravindra", "waqar-baig", "vipin235", "sandyrocks"]
14
+ s.date = "2017-02-08"
15
+ s.description = "ModelForm: Avoid writing html helper"
16
+ s.email = "ravighare26@gmail.com"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/generators/model_form_generator.rb",
30
+ "lib/generators/templates/model_form.yml",
31
+ "lib/model_form.rb",
32
+ "model_form.gemspec",
33
+ "test/helper.rb",
34
+ "test/test_model_form.rb"
35
+ ]
36
+ s.homepage = "http://github.com/gravindra/model_form"
37
+ s.licenses = ["MIT"]
38
+ s.rubygems_version = "2.5.1"
39
+ s.summary = "ModelForm: Save Your Time"
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 4
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<simple_form>, [">= 0"])
46
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
47
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.13"])
49
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
50
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<simple_form>, [">= 0"])
53
+ s.add_dependency(%q<shoulda>, [">= 0"])
54
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
55
+ s.add_dependency(%q<bundler>, ["~> 1.13"])
56
+ s.add_dependency(%q<jeweler>, [">= 0"])
57
+ s.add_dependency(%q<simplecov>, [">= 0"])
58
+ end
59
+ else
60
+ s.add_dependency(%q<simple_form>, [">= 0"])
61
+ s.add_dependency(%q<shoulda>, [">= 0"])
62
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.13"])
64
+ s.add_dependency(%q<jeweler>, [">= 0"])
65
+ s.add_dependency(%q<simplecov>, [">= 0"])
66
+ end
67
+ end
68
+
@@ -0,0 +1,34 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_adapter 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
17
+ require 'rubygems'
18
+ require 'bundler'
19
+ begin
20
+ Bundler.setup(:default, :development)
21
+ rescue Bundler::BundlerError => e
22
+ $stderr.puts e.message
23
+ $stderr.puts "Run `bundle install` to install missing gems"
24
+ exit e.status_code
25
+ end
26
+ require 'test/unit'
27
+ require 'shoulda'
28
+
29
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
30
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
31
+ require 'model_form'
32
+
33
+ class Test::Unit::TestCase
34
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestModelForm < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: model_form
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - gravindra
8
+ - waqar-baig
9
+ - vipin235
10
+ - sandyrocks
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2017-02-08 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: simple_form
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: shoulda
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ - !ruby/object:Gem::Dependency
45
+ name: rdoc
46
+ requirement: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - "~>"
49
+ - !ruby/object:Gem::Version
50
+ version: '3.12'
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '3.12'
58
+ - !ruby/object:Gem::Dependency
59
+ name: bundler
60
+ requirement: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - "~>"
63
+ - !ruby/object:Gem::Version
64
+ version: '1.13'
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '1.13'
72
+ - !ruby/object:Gem::Dependency
73
+ name: jeweler
74
+ requirement: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ - !ruby/object:Gem::Dependency
87
+ name: simplecov
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ description: 'ModelForm: Avoid writing html helper'
101
+ email: ravighare26@gmail.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files:
105
+ - LICENSE.txt
106
+ - README.rdoc
107
+ files:
108
+ - ".document"
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - LICENSE.txt
112
+ - README.rdoc
113
+ - Rakefile
114
+ - VERSION
115
+ - lib/generators/model_form_generator.rb
116
+ - lib/generators/templates/model_form.yml
117
+ - lib/model_form.rb
118
+ - model_form.gemspec
119
+ - test/helper.rb
120
+ - test/test_model_form.rb
121
+ homepage: http://github.com/gravindra/model_form
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.5.1
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: 'ModelForm: Save Your Time'
145
+ test_files: []