faalis 2.0.0.rc5 → 2.0.0.rc6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +20 -0
  3. data/lib/faalis/dashboard/sections/resource.rb +4 -0
  4. data/lib/faalis/dashboard/sections/resource_create.rb +25 -4
  5. data/lib/faalis/dashboard/sections/resource_destroy.rb +10 -1
  6. data/lib/faalis/dashboard/sections/resource_show.rb +7 -2
  7. data/lib/faalis/dashboard/sections/resources_index.rb +6 -1
  8. data/lib/faalis/version.rb +1 -1
  9. data/lib/generators/faalis/install_generator.rb +6 -1
  10. data/lib/generators/faalis/views_generator.rb +43 -29
  11. data/spec/generators/install_spec.rb +2 -0
  12. metadata +47 -106
  13. data/lib/generators/faalis/angularjs_resource_generator.rb +0 -74
  14. data/lib/generators/faalis/install_specs_generator.rb +0 -48
  15. data/lib/generators/faalis/js/install_i18n_generator.rb +0 -47
  16. data/lib/generators/faalis/js/list_view_generator.rb +0 -95
  17. data/lib/generators/faalis/scaffold_generator.rb +0 -215
  18. data/spec/dummy/db/migrate/20151210221051_devise_create_faalis_users.faalis.rb +0 -63
  19. data/spec/dummy/db/migrate/20151210221052_create_faalis_groups.faalis.rb +0 -13
  20. data/spec/dummy/db/migrate/20151210221053_create_faalis_permissions.faalis.rb +0 -13
  21. data/spec/dummy/db/migrate/20151210221054_add_permissions_groups_table.faalis.rb +0 -9
  22. data/spec/dummy/db/migrate/20151210221055_add_users_groups_table.faalis.rb +0 -9
  23. data/spec/dummy/db/migrate/20151210221056_add_uniqueness_index_to_users_groups.faalis.rb +0 -12
  24. data/spec/dummy/db/migrate/20151210221057_create_application_models.model_discovery_engine.rb +0 -10
  25. data/spec/dummy/db/schema.rb +0 -70
  26. data/spec/dummy/db/test.sqlite3 +0 -0
  27. data/spec/dummy/log/test.log +0 -3922
  28. data/spec/dummy/tmp/Gemfile +0 -2
  29. data/spec/dummy/tmp/app/assets/javascripts/dashboard/application.js +0 -19
  30. data/spec/dummy/tmp/app/assets/stylesheets/dashboard/ltr/application.css +0 -3
  31. data/spec/dummy/tmp/app/assets/stylesheets/dashboard/rtl/application.css +0 -3
  32. data/spec/dummy/tmp/app/assets/stylesheets/ltr/application.css +0 -3
  33. data/spec/dummy/tmp/app/assets/stylesheets/rtl/application.css +0 -3
  34. data/spec/dummy/tmp/app/controllers/api_controller.rb +0 -2
  35. data/spec/dummy/tmp/app/controllers/application_controller.rb +0 -0
  36. data/spec/dummy/tmp/app/controllers/dashboard/application_controller.rb +0 -18
  37. data/spec/dummy/tmp/app/policies/application_policy.rb +0 -2
  38. data/spec/dummy/tmp/config/initializers/assets.rb +0 -1
  39. data/spec/dummy/tmp/config/initializers/devise.rb +0 -251
  40. data/spec/dummy/tmp/config/initializers/faalis.rb +0 -12
  41. data/spec/dummy/tmp/config/initializers/faalis_assets.rb +0 -1
  42. data/spec/dummy/tmp/config/initializers/formtastic.rb +0 -1
  43. data/spec/dummy/tmp/config/routes.rb +0 -0
  44. data/spec/dummy/tmp/db/seeds.rb +0 -1
@@ -1,74 +0,0 @@
1
- # -----------------------------------------------------------------------------
2
- # Faalis - Basic website skel engine
3
- # Copyright (C) 2012-2013 Yellowen
4
- #
5
- # This program is free software; you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation; either version 2 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU General Public License along
16
- # with this program; if not, write to the Free Software Foundation, Inc.,
17
- # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
- # -----------------------------------------------------------------------------
19
-
20
- module Faalis
21
- module Generators
22
- class AngularjsResourceGenerator < Rails::Generators::Base
23
- source_root File.expand_path('../templates', __FILE__)
24
-
25
- argument :resource_name, :type => :string, :required => true
26
- argument :dependencies, type: :array, default: [], banner: "dependencies"
27
-
28
- desc "Create a new resource for angularjs application"
29
- def create_module
30
- template "angularjs/module.js.erb", "#{angularjs_app_path}modules/#{resource_path}.js"
31
- end
32
-
33
- def create_template
34
- template "angularjs/index.html.erb", "app/assets/templates/#{resource.underscore}/index.html"
35
- end
36
-
37
- private
38
-
39
- def get_dependencies
40
- deps = []
41
- dependencies.each do |dependency|
42
- deps << "'#{dependency.camelize}'"
43
- end
44
-
45
- deps.join(", ")
46
- end
47
-
48
- def resource_path
49
- path_parts = resource_name.split("/")
50
- if path_parts.length > 1
51
- return "#{path_parts(0..-2).join("/")}/#{path_parts[-1].underscore}"
52
- end
53
- resource_name.underscore
54
- end
55
-
56
- def resource
57
- path_parts = resource_name.split("/")
58
- if path_parts.length > 1
59
- return path_parts[-1].camelize
60
- end
61
- resource_name.camelize
62
- end
63
-
64
- def is_in_engine?
65
- false
66
- end
67
-
68
- def angularjs_app_path
69
- path = Faalis::Engine.dashboard_js_manifest.split("/")[0..-2].join("/")
70
- "app/assets/javascripts/#{path}/"
71
- end
72
- end
73
- end
74
- end
@@ -1,48 +0,0 @@
1
- # -----------------------------------------------------------------------------
2
- # Faalis - Basic website skel engine
3
- # Copyright (C) 2012-2013 Yellowen
4
- #
5
- # This program is free software; you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation; either version 2 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU General Public License along
16
- # with this program; if not, write to the Free Software Foundation, Inc.,
17
- # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
- # -----------------------------------------------------------------------------
19
-
20
- module Faalis
21
- module Generators
22
- class InstallSpecsGenerator < Rails::Generators::Base
23
- source_root File.expand_path('../templates', __FILE__)
24
-
25
- desc "Copy all the necessary files to install and use specs"
26
-
27
- def install_gems
28
- invoke "rspec:install"
29
- invoke "cucumber:install", ["--capybara", "--rspec"]
30
- end
31
-
32
- def update_configurations
33
- copy_file "features/step_definitions/email_steps.rb", "features/step_definitions/email_steps.rb"
34
- copy_file "features/support/env.rb", "features/support/env.rb"
35
- copy_file "spec/factories/groups.rb", "spec/factories/groups.rb"
36
- copy_file "spec/factories/users.rb", "spec/factories/users.rb"
37
- copy_file "spec/spec_helper.rb", "spec/spec_helper.rb"
38
- copy_file "spec/support/devise.rb", "spec/support/devise.rb"
39
- end
40
-
41
- def show_readme
42
- readme "SPECS" if behavior == :invoke
43
- end
44
-
45
-
46
- end
47
- end
48
- end
@@ -1,47 +0,0 @@
1
- # -----------------------------------------------------------------------------
2
- # Faalis - Basic website skel engine
3
- # Copyright (C) 2012-2013 Yellowen
4
- #
5
- # This program is free software; you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation; either version 2 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU General Public License along
16
- # with this program; if not, write to the Free Software Foundation, Inc.,
17
- # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
- # -----------------------------------------------------------------------------
19
-
20
- module Faalis
21
- module Generators
22
- module Js
23
- # Generator responsible for `install_i18n` generator
24
- class InstallI18nGenerator < Rails::Generators::Base
25
- source_root File.expand_path('../../templates/', __FILE__)
26
-
27
- desc 'Copy all the necessary files to use Faalis client side i18n'
28
-
29
- def copy_init_files
30
- template 'i18n/Gruntfile.js.erb', 'lib/tasks/grunt/Gruntfile.js'
31
- copy_file 'i18n/fa.js', 'app/assets/javascripts/locales/fa.js'
32
- end
33
-
34
- def show_readme
35
- readme 'i18n/README' if behavior == :invoke
36
- end
37
-
38
- private
39
-
40
- def angularjs_app_path
41
- path = Faalis::Engine.dashboard_js_manifest.split('/')[0..-2].join('/')
42
- "app/assets/javascripts/#{path}/"
43
- end
44
- end
45
- end
46
- end
47
- end
@@ -1,95 +0,0 @@
1
- module Faalis
2
- module Generators
3
- module Js
4
- # `faalis:js:list_view` scaffold generator class
5
- class ListViewGenerator < Faalis::Generators::DashboardScaffold
6
-
7
- # templates path
8
- source_root File.expand_path('../../templates', __FILE__)
9
-
10
- # Field name to use as title of each object
11
- class_option :title_field, :type => :string, :default => "name", :desc => "Field name to use as title of each object"
12
-
13
- # Don't copy the new.html template
14
- class_option :no_new_template, :type => :boolean, :default => false, :desc => "Don't copy the new.html template"
15
-
16
- desc "Create a new resource for client side application"
17
- def create_module
18
- unless options[:only_controller]
19
- unless options[:only_specs]
20
- template "js/list_view/module.js.erb", "#{angularjs_app_path}modules/#{resource_path}.js"
21
- end
22
- end
23
- end
24
-
25
- def create_template
26
- unless options[:only_controller]
27
- unless options[:only_specs]
28
- template "js/list_view/index.html.erb", "app/views/angular/#{resource.underscore}/index.html"
29
- unless options[:no_new_template]
30
- template "js/list_view/new.html.erb", "app/views/angular/#{resource.underscore}/new.html"
31
- end
32
- template "js/list_view/details.html.erb", "app/views/angular/#{resource.underscore}/details.html"
33
- end
34
- end
35
-
36
- unless options[:only_specs]
37
- template "views/index.json.jbuilder.erb", "app/views/api/v1/#{resource.pluralize.underscore}/index.json.jbuilder"
38
- template "views/show.json.jbuilder.erb", "app/views/api/v1/#{resource.pluralize.underscore}/show.json.jbuilder"
39
- template "views/create.json.jbuilder.erb", "app/views/api/v1/#{resource.pluralize.underscore}/create.json.jbuilder"
40
- template "views/destroy.json.jbuilder.erb", "app/views/api/v1/#{resource.pluralize.underscore}/destroy.json.jbuilder"
41
- template "views/update.json.jbuilder.erb", "app/views/api/v1/#{resource.pluralize.underscore}/update.json.jbuilder"
42
- end
43
- end
44
-
45
- def create_api
46
- unless options[:only_specs]
47
- template "api/controller.rb.erb", "app/controllers/api/v1/#{resource.pluralize.underscore}_controller.rb"
48
- end
49
- end
50
-
51
- def create_policy
52
- template "policy/policy.rb.erb", "app/policies/#{resource.underscore}_policy.rb"
53
- end
54
-
55
- def create_specs
56
- unless options[:without_specs]
57
- template "features/api.feature", "features/#{resource.underscore}.api.feature"
58
- template "features/api.step.rb", "features/step_definitions/#{resource.underscore}.rb"
59
- end
60
- end
61
-
62
- def show_readme
63
- readme "js/list_view/README" if behavior == :invoke
64
- end
65
-
66
- # PRIVATES --------------------------------------------
67
- private
68
-
69
- def is_in_engine?
70
- false
71
- end
72
-
73
- def random_json_data
74
- data = {}
75
- fields.each do |field, type|
76
- case type
77
- when "belongs_to"
78
- data["#{field}_id"] = 1
79
- when "integer"
80
- data[field] = 1+ rand(1000)
81
- else
82
- data[field] = random_string
83
- end
84
- end
85
- data.to_json.to_s
86
- end
87
-
88
- def random_string
89
- o = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten
90
- (0...50).map{ o[rand(o.length)] }.join
91
- end
92
- end
93
- end
94
- end
95
- end
@@ -1,215 +0,0 @@
1
- # -----------------------------------------------------------------------------
2
- # Faalis - Basic website skel engine
3
- # Copyright (C) 2012-2015 Yellowen
4
- #
5
- # This program is free software; you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation; either version 2 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU General Public License along
16
- # with this program; if not, write to the Free Software Foundation, Inc.,
17
- # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
- # -----------------------------------------------------------------------------
19
-
20
- module Faalis
21
- module Generators
22
- # Generator Full Faalis scaffold with dashboard
23
- class ScaffoldGenerator < Rails::Generators::Base
24
- include Faalis::Generators::Concerns::RequireFields
25
- include Faalis::Generators::Concerns::Parent
26
- include Faalis::Generators::Concerns::Child
27
- include Faalis::Generators::Concerns::InputFile
28
- include Faalis::Generators::Concerns::ResourceName
29
- include Faalis::Generators::Concerns::ResourceFields
30
- include Faalis::Generators::Concerns::Globalize
31
-
32
-
33
- desc 'Create full faalis full scaffold'
34
- # FIXME: These options should have :desc or even default
35
- # value
36
- class_option :no_model, :type => :boolean
37
- class_option :no_route, :type => :boolean
38
- class_option :no_controller, :type => :boolean
39
- class_option :no_migration, :type => :boolean
40
- class_option :no_asset, :type => :boolean
41
-
42
- # This method will create full scaffold based on user options
43
- def create_scaffold
44
- if options.empty?
45
- # TODO: ....
46
- end
47
- # TODO: Show error if in class_option migration is selected by model not
48
- create_model unless options[:no_model]
49
- create_route unless options[:no_route]
50
- create_controller unless options[:no_controller]
51
- create_list_view
52
- end
53
-
54
- private
55
-
56
- # Create a dedicated controller,
57
- def create_controller
58
- if options[:no_asset]
59
- `rails g scaffold_controller #{resource_data["name"]} #{all_fields}--assets=false`
60
- else
61
- `rails g scaffold_controller #{resource_data["name"]} #{all_fields}`
62
- end
63
- end
64
-
65
- # Create route of the scaffold in config/routes.rb
66
- def create_route
67
- route "resources :#{resource_data["name"].pluralize}"
68
- end
69
-
70
- # Create model of the scaffold with belongs_to support
71
- # It does not support has_many relation yet
72
- def create_model
73
-
74
- # Load all globalize field and create a string to adding in model
75
- globalizes = "\n translates "+
76
- globalize_fields.map { |field | ":#{field['name'].underscore}" }.join(", ")
77
- invoke('active_record:model', [resource_data['name'].singularize.underscore, all_fields.split(' ')], {
78
- migration: !options[:no_migragtion], timestamps: true
79
- })
80
- if globalize_fields.any?
81
- create_globalize_migration
82
- end
83
-
84
- if File.exist?("app/models/#{resource_data["name"]}.rb")
85
- inject_into_file "app/models/#{resource_data["name"].underscore}.rb", after: 'Base' do
86
- globalize_fields.empty? ? relations : relations + globalizes
87
- end
88
- else
89
- say_status "error", "Could not find file app/models/#{resource_data["name"].underscore}"
90
- end
91
-
92
- end
93
-
94
- #Invoke Faalis list view generator
95
- def create_list_view
96
- invoke 'faalis:js:list_view', [input_file]
97
- end
98
-
99
- def create_globalize_migration
100
- `rails g migration add_globalize_to_#{resource_data["name"].underscore} `
101
- Dir["#{Rails.root}/db/migrate/**/*globalize*.rb"].each {|file| require file }
102
- klass = "add_globalize_to_#{resource_data['name']}".underscore.camelize
103
-
104
- migration_class = "::#{klass}".constantize
105
- migration_path = migration_class.instance_method(:change).source_location
106
-
107
- fields = globalize_fields.map { |field | ":#{field['name']} => :#{field['type']}" }.join(", ")
108
-
109
- inject_into_file migration_path[0], after: 'change' do
110
- "\n #{resource_data['name'].camelize}"+
111
- '.create_translation_table! '+
112
- fields
113
- end
114
- end
115
-
116
- def create_images
117
- fields.each do |name, type|
118
- if type == 'image'
119
- generate "paperclicp #{resource_data['name']} #{name}"
120
- end
121
- end
122
- end
123
-
124
- def create_tags
125
- fields.each do |name, type|
126
- if type == 'image'
127
- rake "rake acts_as_taggable_on_engine:install:migrations"
128
- end
129
- end
130
- end
131
-
132
- # Create string of all relations that needs in models
133
- def relations
134
- relations = "\n"
135
-
136
- fields.each do |name, type, to|
137
- case type
138
- when 'belongs_to'
139
- if to.singularize != name
140
- relations << " belongs_to :#{name.singularize},
141
- :class_name => \"#{to.singularize.camelize}\"\n"
142
- else
143
- relations << " belongs_to :#{to.singularize}\n"
144
- end
145
-
146
- when 'image'
147
- relations << "
148
- attr_accessor :image_data\n
149
- before_create :randomize_file_name\n
150
- has_attached_file :#{name}\n
151
- content_type: %w(image/jpeg image/jpg image/png),
152
- validates_attachment_content_type :#{name},
153
- less_than: 1.megabytes\n
154
- "
155
- # TODO: randomize_file_name method should be added
156
- when 'tag'
157
- relations << " acts_as_taggable_on :#{name}\n"
158
-
159
- when 'has_and_belongs_to_many'
160
- relations << " has_and_belongs_to_many :#{to.pluralize}\n"
161
- say_status 'warn', "There is a many to many relation between #{resource_data['name']} and #{to},
162
- You should create it manually in model files"
163
-
164
- when 'has_many'
165
- relations << " has_many :#{to.pluralize}\n"
166
- say_status 'warn', "There is a many to many relation between #{resource_data['name']} and #{to},
167
- You should create it manually in model files"
168
- end
169
- end
170
-
171
- if parent?
172
- parents.each do |parent|
173
- relations << " belongs_to :#{parent.singularize}\n"
174
- end
175
- end
176
-
177
- childs.each do |child|
178
- relations << " has_many :#{child.pluralize}\n"
179
- end
180
- return relations
181
- end
182
-
183
- # It will extract name and types of all fields
184
- # And will return it as supported format for scaffold_controller
185
- def all_fields
186
- result = []
187
- fields.each do |name, type, to|
188
- case type
189
- when 'belongs_to'
190
- name_ = "#{name.singularize}_id"
191
- result << [name_, 'integer']
192
-
193
- when 'text', 'integer', 'string', 'boolean', 'datetime', 'time', 'date', 'float'
194
- result << [name, type]
195
-
196
- when 'tag', 'in'
197
- result << [name, 'string']
198
- end
199
- end
200
-
201
- if parent?
202
- parents.each do |parent|
203
- result << ["#{parent.singularize}_id", "integer"]
204
- end
205
- end
206
-
207
- all_fields = []
208
- all_fields = result.collect do |x|
209
- x.join(':')
210
- end
211
- return all_fields.join " "
212
- end
213
- end
214
- end
215
- end