faat 0.1.3 → 0.1.4
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.
- checksums.yaml +8 -8
- data/Gemfile +0 -1
- data/README.md +42 -1
- data/lib/faat/forms/base.rb +19 -0
- data/lib/faat/version.rb +1 -1
- data/lib/generators/faat/forms/forms_generator.rb +41 -0
- data/lib/generators/faat/forms/templates/form_template.rb +8 -0
- data/lib/generators/faat/resources/resources_generator.rb +0 -4
- metadata +5 -3
- data/lib/generators/faat/forms/templates/form_tamplate.rb +0 -0
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZTE4ZjhlMWVlZTYyYTc3MWE3MzgwZDFkYTIxNDc5MGE0MzdhOGYzMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MGYwOWI1MzY3ZjE0YjUyMDFhZjRmMGQxYzNkMDZiOTA5ZDNiMDhmMA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTM3NDE0ZjY2NGU1YjkyYTdkYmU3MTQxMDhlNWQ4YTA3OWVkNGQ5MTE5MmMx
|
10
|
+
NTM3Y2NhZjk2NTUyYTE1YmNkYzE0OTBmODJjNTJhNDE5ZDk5ZDE2MDA1ODQ3
|
11
|
+
MGVkOWU4Mzg5ZTM3MWMyYjY1N2ZkNDNlZTYyOTI2N2UzZDNmMTc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
M2YxYzAzNmQwZmE3ZTNhMGQxYjEwZjQwMjA5YzU3Y2YyNmNmMWI2MjIyZWFj
|
14
|
+
YzU3ZjQ1Nzg3ZDMyMDdiZTk5MzNjODQ5MjBiMzA4ZWM2NmEzMjM3NmY1MTE4
|
15
|
+
MmQwMTgzMDRjOWQ4YzRmYmVkNWQ5YjAyYTQwMjE2NDM1ZGViYjY=
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -25,11 +25,15 @@ Or install it yourself as:
|
|
25
25
|
Run ```rails generate faat:resources {model_name}```,
|
26
26
|
generator will create folder ```resource``` in ```app``` directory, and file ```{model_name}_resource.rb```
|
27
27
|
|
28
|
+
Run ```rails generate faat:forms {form_name} {attribute_name}:{attribute_type}```,
|
29
|
+
generator will create folder ```forms``` in ```app``` directory, and file ```{form_name}_form.rb```
|
28
30
|
|
29
31
|
###Initialize:
|
30
32
|
```ruby
|
31
33
|
@post = Post.new
|
32
34
|
@post_resource = PostResource.new(@post)
|
35
|
+
|
36
|
+
@post_form = PostForm.new(post_form_params)
|
33
37
|
```
|
34
38
|
|
35
39
|
###Usage:
|
@@ -42,9 +46,46 @@ PostResource.all => Post.all
|
|
42
46
|
PostResource.where(title: "First Test Title") => Post.where(...)
|
43
47
|
```
|
44
48
|
|
49
|
+
###Examples:
|
50
|
+
|
51
|
+
|
52
|
+
In ```post_resource.rb```
|
53
|
+
```ruby
|
54
|
+
class PostResource < Faat::Resources::Base
|
55
|
+
...
|
56
|
+
|
57
|
+
def initialize(post_form)
|
58
|
+
@author = Author.create!(name: post_form.author_name, email: post_form.author_email)
|
59
|
+
@post = Post.create!(text: post_form.text, title: post_form.title)
|
60
|
+
send_confirmation_email(@author)
|
61
|
+
end
|
62
|
+
|
63
|
+
...
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
In```post_controller.rb```
|
68
|
+
```ruby
|
69
|
+
...
|
70
|
+
def create
|
71
|
+
@post_form = PostForm.new(post_form_params)
|
72
|
+
if @post_form.valid?
|
73
|
+
@post_resource = PostResource.new(@post_form) => create @author and @post
|
74
|
+
end
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
78
|
+
Some other usage:
|
79
|
+
```ruby
|
80
|
+
@post_form = PostForm.new(post_form_params)
|
81
|
+
@post_form.valid? # or invalid?
|
82
|
+
@post_form.text => some value
|
83
|
+
@post_form.author_email => john@example.com
|
84
|
+
@ost_form.author_name => John Smith
|
85
|
+
```
|
45
86
|
## TODO
|
46
87
|
|
47
|
-
Add
|
88
|
+
Add spec/test auto generator
|
48
89
|
|
49
90
|
|
50
91
|
## Contributing
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'virtus'
|
2
|
+
# root module Faat
|
3
|
+
module Faat
|
4
|
+
# Faat::Forms forms module
|
5
|
+
module Forms
|
6
|
+
# Faat::Forms::Base base forms class
|
7
|
+
class Base
|
8
|
+
# Your classes must inherited from this Base class
|
9
|
+
# for removing all business logic from models classes,
|
10
|
+
# and controllers
|
11
|
+
|
12
|
+
include Virtus.model
|
13
|
+
|
14
|
+
extend ActiveModel::Naming
|
15
|
+
include ActiveModel::Conversion
|
16
|
+
include ActiveModel::Validations
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/faat/version.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'generators/faat'
|
2
|
+
require 'rails/generators/base'
|
3
|
+
|
4
|
+
module Faat
|
5
|
+
module Generators
|
6
|
+
class FormsGenerator < Base
|
7
|
+
argument :form_name, type: :string, default: 'app', banner: 'form_name'
|
8
|
+
argument :attr, type: :array, default: [], banner: 'form attributes'
|
9
|
+
|
10
|
+
def create_form
|
11
|
+
@form_attributes = []
|
12
|
+
|
13
|
+
unless attr.size.zero?
|
14
|
+
attr.each do |arg|
|
15
|
+
if arg.include?(':')
|
16
|
+
@form_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':'))
|
17
|
+
else
|
18
|
+
@form_attributes << Rails::Generators::GeneratedAttribute.new(arg)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
template "form_template.rb", "app/forms/#{file_name}_form.rb"
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def attributes
|
29
|
+
@form_attributes
|
30
|
+
end
|
31
|
+
|
32
|
+
def file_name
|
33
|
+
form_name.underscore
|
34
|
+
end
|
35
|
+
|
36
|
+
def class_name
|
37
|
+
form_name.downcase.capitalize
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<%= '# default generated template' %>
|
2
|
+
|
3
|
+
class <%= "#{class_name}Form" %> < Faat::Forms::Base
|
4
|
+
<% attributes.each do |arg| %>
|
5
|
+
<%= "attribute :#{arg.name}, #{arg.type.capitalize}" %><% end %>
|
6
|
+
<%= '# add your attributes "attribute :title, String"' %>
|
7
|
+
<%= '# and add your validation for forms "validates :title, presence: true"' %>
|
8
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nazarii Sheremet
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|
@@ -126,11 +126,13 @@ files:
|
|
126
126
|
- bin/setup
|
127
127
|
- faat.gemspec
|
128
128
|
- lib/faat.rb
|
129
|
+
- lib/faat/forms/base.rb
|
129
130
|
- lib/faat/helpers/string.rb
|
130
131
|
- lib/faat/resources/base.rb
|
131
132
|
- lib/faat/version.rb
|
132
133
|
- lib/generators/faat.rb
|
133
|
-
- lib/generators/faat/forms/
|
134
|
+
- lib/generators/faat/forms/forms_generator.rb
|
135
|
+
- lib/generators/faat/forms/templates/form_template.rb
|
134
136
|
- lib/generators/faat/resources/resources_generator.rb
|
135
137
|
- lib/generators/faat/resources/templates/resource_template.rb
|
136
138
|
homepage: https://github.com/xo8bit/faat
|
File without changes
|