faalis 0.16.3 → 0.17.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.
- checksums.yaml +4 -4
- data/app/views/angularjs_templates/modules.html +1 -1
- data/lib/faalis.rb +2 -0
- data/lib/faalis/generators.rb +1 -0
- data/lib/faalis/generators/concerns.rb +9 -0
- data/lib/faalis/generators/concerns/angular.rb +31 -0
- data/lib/faalis/generators/concerns/bulk.rb +36 -0
- data/lib/faalis/generators/concerns/dependency.rb +14 -0
- data/lib/faalis/generators/concerns/menu.rb +29 -0
- data/lib/faalis/generators/concerns/parent.rb +35 -0
- data/lib/faalis/generators/concerns/required.rb +22 -0
- data/lib/faalis/generators/concerns/resource_fields.rb +82 -0
- data/lib/faalis/generators/concerns/resource_name.rb +42 -0
- data/lib/faalis/generators/concerns/tabs.rb +40 -0
- data/lib/faalis/generators/dashboard_scaffold.rb +35 -0
- data/lib/faalis/generators/fields/relation.rb +28 -0
- data/lib/faalis/version.rb +1 -1
- data/lib/generators/faalis/js/list_view_generator.rb +110 -0
- data/lib/generators/faalis/js_scaffold_generator.rb +4 -251
- data/lib/generators/faalis/templates/angularjs/module.js.erb +1 -1
- data/lib/generators/faalis/templates/js/list_view/README +31 -0
- data/lib/generators/faalis/templates/js/list_view/details.html.erb +20 -0
- data/lib/generators/faalis/templates/js/list_view/index.html.erb +62 -0
- data/lib/generators/faalis/templates/js/list_view/module.js.erb +333 -0
- data/lib/generators/faalis/templates/js/list_view/new.html.erb +62 -0
- metadata +338 -328
- data/app/assets/javascripts/faalis/dashboard/gen-doc.sh~ +0 -3
- data/spec/dummy/log/development.log +0 -0
- data/spec/dummy/log/test.log +0 -15
- data/spec/dummy/tmp/ember-rails/ember-data.js +0 -10204
- data/spec/dummy/tmp/ember-rails/ember.js +0 -36991
data/lib/faalis/version.rb
CHANGED
@@ -0,0 +1,110 @@
|
|
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
|
+
# `faalis:js:list_view` scaffold generator class
|
24
|
+
class ListViewGenerator < Faalis::Generators::DashboardScaffold
|
25
|
+
|
26
|
+
# templates path
|
27
|
+
source_root File.expand_path('../../templates', __FILE__)
|
28
|
+
|
29
|
+
# Field name to use as title of each object
|
30
|
+
class_option :title_field, :type => :string, :default => "name", :desc => "Field name to use as title of each object"
|
31
|
+
|
32
|
+
# Don't copy the new.html template
|
33
|
+
class_option :no_new_template, :type => :boolean, :default => false, :desc => "Don't copy the new.html template"
|
34
|
+
|
35
|
+
desc "Create a new resource for client side application"
|
36
|
+
def create_module
|
37
|
+
unless options[:only_controller]
|
38
|
+
unless options[:only_specs]
|
39
|
+
template "js/list_view/module.js.erb", "#{angularjs_app_path}modules/#{resource_path}.js"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def create_template
|
45
|
+
unless options[:only_controller]
|
46
|
+
unless options[:only_specs]
|
47
|
+
template "js/list_view/index.html.erb", "app/views/angularjs_templates/#{resource.underscore}/index.html"
|
48
|
+
unless options[:no_new_template]
|
49
|
+
template "js/list_view/new.html.erb", "app/views/angularjs_templates/#{resource.underscore}/new.html"
|
50
|
+
end
|
51
|
+
template "js/list_view/details.html.erb", "app/views/angularjs_templates/#{resource.underscore}/details.html"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
unless options[:only_specs]
|
56
|
+
template "views/index.json.jbuilder.erb", "app/views/api/v1/#{resource.pluralize.underscore}/index.json.jbuilder"
|
57
|
+
template "views/show.json.jbuilder.erb", "app/views/api/v1/#{resource.pluralize.underscore}/show.json.jbuilder"
|
58
|
+
template "views/create.json.jbuilder.erb", "app/views/api/v1/#{resource.pluralize.underscore}/create.json.jbuilder"
|
59
|
+
template "views/destroy.json.jbuilder.erb", "app/views/api/v1/#{resource.pluralize.underscore}/destroy.json.jbuilder"
|
60
|
+
template "views/update.json.jbuilder.erb", "app/views/api/v1/#{resource.pluralize.underscore}/update.json.jbuilder"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def create_api
|
65
|
+
unless options[:only_specs]
|
66
|
+
template "api/controller.rb.erb", "app/controllers/api/v1/#{resource.pluralize.underscore}_controller.rb"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def create_specs
|
71
|
+
unless options[:without_specs]
|
72
|
+
template "features/api.feature", "features/#{resource.underscore}.api.feature"
|
73
|
+
template "features/api.step.rb", "features/step_definitions/#{resource.underscore}.rb"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def show_readme
|
78
|
+
readme "js/list_view/README" if behavior == :invoke
|
79
|
+
end
|
80
|
+
|
81
|
+
# PRIVATES --------------------------------------------
|
82
|
+
private
|
83
|
+
|
84
|
+
def is_in_engine?
|
85
|
+
false
|
86
|
+
end
|
87
|
+
|
88
|
+
def random_json_data
|
89
|
+
data = {}
|
90
|
+
fields.each do |field, type|
|
91
|
+
case type
|
92
|
+
when "belongs_to"
|
93
|
+
data["#{field}_id"] = 1
|
94
|
+
when "integer"
|
95
|
+
data[field] = 1+ rand(1000)
|
96
|
+
else
|
97
|
+
data[field] = random_string
|
98
|
+
end
|
99
|
+
end
|
100
|
+
data.to_json.to_s
|
101
|
+
end
|
102
|
+
|
103
|
+
def random_string
|
104
|
+
o = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten
|
105
|
+
(0...50).map{ o[rand(o.length)] }.join
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -20,65 +20,21 @@
|
|
20
20
|
module Faalis
|
21
21
|
module Generators
|
22
22
|
# `js_scaffold` main class
|
23
|
-
class JsScaffoldGenerator <
|
23
|
+
class JsScaffoldGenerator < Faalis::Generators::DashboardScaffold
|
24
|
+
# We keep this class to keep backward compatiblity
|
25
|
+
puts "[DEPRECATED]: This generator will be removed soon, Use faalis:js:list_view instead."
|
26
|
+
# TODO: Remove this ater a while
|
24
27
|
|
25
|
-
include ActionView::Helpers::TextHelper
|
26
28
|
|
27
29
|
# templates path
|
28
30
|
source_root File.expand_path('../templates', __FILE__)
|
29
31
|
|
30
|
-
# Name of the resource to create.
|
31
|
-
argument :resource_name, :type => :string, :required => true
|
32
|
-
|
33
|
-
# An array of resource fields. fields should be separated by space
|
34
|
-
# each filed should be in this format `field_name:field_type[:extra_info]
|
35
|
-
argument :resource_fields, type: :array, default: [], banner: "fields[:types]"
|
36
|
-
|
37
|
-
# Do not install specs
|
38
|
-
class_option :without_specs, :type => :boolean, :default => false, :desc => "Do not install specs"
|
39
|
-
|
40
|
-
# Generate only spec files
|
41
|
-
class_option :only_specs, :type => :boolean, :default => false, :desc => "Generate only spec files"
|
42
|
-
|
43
|
-
# Generate only controller
|
44
|
-
class_option :only_controller, :type => :boolean, :default => false, :desc => "Generate only controller"
|
45
|
-
|
46
|
-
# Fields to use in in bulk edit, comma separated
|
47
|
-
class_option :bulk_fields, :type => :string, :default => "", :desc => "Fields to use in in bulk edit, comma separated"
|
48
|
-
|
49
|
-
# No bulk edit needed
|
50
|
-
class_option :no_bulk, :type => :boolean, :default => false, :desc => "No bulk edit needed"
|
51
|
-
|
52
|
-
# Provide menu items which should be in sidebar. format: menu1:url,menu2:url
|
53
|
-
class_option :menu, :type => :string, :default => "", :desc => "Provide menu items which should be in sidebar. format: menu1:url,menu2:url"
|
54
|
-
|
55
32
|
# Field name to use as title of each object
|
56
33
|
class_option :title_field, :type => :string, :default => "name", :desc => "Field name to use as title of each object"
|
57
34
|
|
58
|
-
# Non optional fields, comma separated
|
59
|
-
class_option :required, :type => :string, :default => "", :desc => "Non optional fields, comma separated"
|
60
|
-
|
61
|
-
# Dependencies of Angularjs module, comma separated
|
62
|
-
class_option :deps, :type => :string, :default => "", :desc => "Dependencies of Angularjs module, comma separated"
|
63
|
-
|
64
|
-
# Path to js_scaffold target inside 'app/assets/javascripts/'
|
65
|
-
class_option :path, :type => :string, :default => "", :desc => "Path to js_scaffold target inside 'app/assets/javascripts/'"
|
66
|
-
|
67
|
-
# Path to js_scaffold target
|
68
|
-
class_option :raw_path, :type => :string, :default => "", :desc => "Path to js_scaffold target"
|
69
|
-
|
70
|
-
# Add tabs to 'new' view of scaffold. format: --tabs tab1:'field1;field2',tab2 Note: __all__ field include all fileds.
|
71
|
-
class_option :tabs, :type => :string, :default => "", :desc => "Add tabs to 'new' view of scaffold. format: --tabs tab1:'field1;field2',tab2 Note: __all__ field include all fileds."
|
72
|
-
|
73
|
-
# Don't show a filter box
|
74
|
-
class_option :no_filter, :type => :boolean, :default => false, :desc => "Don't view a filter box"
|
75
|
-
|
76
35
|
# Don't copy the new.html template
|
77
36
|
class_option :no_new_template, :type => :boolean, :default => false, :desc => "Don't copy the new.html template"
|
78
37
|
|
79
|
-
# Specify the parent resource if there was any
|
80
|
-
class_option :parent, :type => :string, :default => "", :desc => "Specify the parent resource if there was any"
|
81
|
-
|
82
38
|
desc "Create a new resource for client side application"
|
83
39
|
def create_module
|
84
40
|
unless options[:only_controller]
|
@@ -128,183 +84,10 @@ module Faalis
|
|
128
84
|
# PRIVATES --------------------------------------------
|
129
85
|
private
|
130
86
|
|
131
|
-
# Resource parent related ----------------------
|
132
|
-
# check for parent
|
133
|
-
def parent?
|
134
|
-
if options[:parent] != ""
|
135
|
-
return true
|
136
|
-
end
|
137
|
-
false
|
138
|
-
end
|
139
|
-
|
140
|
-
# Remove the starting slash from the given parent path
|
141
|
-
def trim_parent_path
|
142
|
-
if parent?
|
143
|
-
options[:parent].gsub(/^\//, "")
|
144
|
-
else
|
145
|
-
""
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
# -------------------------
|
150
|
-
|
151
|
-
# Path to the resource
|
152
|
-
def resource_path
|
153
|
-
path_parts = resource_name.split("/")
|
154
|
-
if path_parts.length > 1
|
155
|
-
return "#{path_parts(0..-2).join("/")}/#{path_parts[-1].underscore}"
|
156
|
-
end
|
157
|
-
resource_name.underscore
|
158
|
-
end
|
159
|
-
|
160
|
-
# Url of resource
|
161
|
-
def resource_url
|
162
|
-
path_parts = resource_name.split("/")
|
163
|
-
if path_parts.length > 1
|
164
|
-
return "#{path_parts(0..-2).join("/")}/#{path_parts[-1].pluralize.underscore}"
|
165
|
-
end
|
166
|
-
resource_name.pluralize.underscore
|
167
|
-
end
|
168
|
-
|
169
|
-
def resource
|
170
|
-
path_parts = resource_name.split("/")
|
171
|
-
if path_parts.length > 1
|
172
|
-
return path_parts[-1].camelize
|
173
|
-
end
|
174
|
-
resource_name.camelize
|
175
|
-
end
|
176
|
-
|
177
87
|
def is_in_engine?
|
178
88
|
false
|
179
89
|
end
|
180
90
|
|
181
|
-
def angularjs_app_path
|
182
|
-
if options[:raw_path] != ""
|
183
|
-
options[:raw_path]
|
184
|
-
elsif options[:path] != ""
|
185
|
-
"app/assets/javascripts/#{options[:path]}/"
|
186
|
-
else
|
187
|
-
path = Faalis::Engine.dashboard_js_manifest.split("/")[0..-2].join("/")
|
188
|
-
"app/assets/javascripts/#{path}/"
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
# Tabs ------------------------------------
|
193
|
-
|
194
|
-
# Process the user provided tabs
|
195
|
-
# @return a Hash of tabs like
|
196
|
-
def tabs
|
197
|
-
if options[:tabs].present?
|
198
|
-
tabs = options[:tabs].split(",")
|
199
|
-
result = {}
|
200
|
-
tabs.each do |tab|
|
201
|
-
name, fields = tab.split(":")
|
202
|
-
fields_list = []
|
203
|
-
unless fields.nil?
|
204
|
-
fields_list = fields.split(";")
|
205
|
-
end
|
206
|
-
result[name] = fields_list
|
207
|
-
end
|
208
|
-
return result
|
209
|
-
else
|
210
|
-
{}
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
def any_tabs?
|
215
|
-
options[:tabs].present?
|
216
|
-
end
|
217
|
-
# -----------------------------------
|
218
|
-
|
219
|
-
# An array of fields like
|
220
|
-
# [name, type]
|
221
|
-
def fields
|
222
|
-
fields = []
|
223
|
-
resource_fields.each do |field|
|
224
|
-
name, type, to = field.split(":")
|
225
|
-
if ["belongs_to", "has_many", "in"].include? type
|
226
|
-
type = Relation.new(type, to)
|
227
|
-
end
|
228
|
-
|
229
|
-
fields << [name, type]
|
230
|
-
end
|
231
|
-
fields
|
232
|
-
end
|
233
|
-
|
234
|
-
def fields_hash
|
235
|
-
Hash[fields]
|
236
|
-
end
|
237
|
-
|
238
|
-
def grid_fields
|
239
|
-
fields
|
240
|
-
end
|
241
|
-
|
242
|
-
# Returns fields which is needed to be in bulk edit
|
243
|
-
def bulk_edit_fields
|
244
|
-
unless options[:bulk_fields].empty?
|
245
|
-
bfields = options[:bulk_fields].split(",")
|
246
|
-
fields_ = fields_hash
|
247
|
-
bfields.each do |f|
|
248
|
-
unless fields_.include? f
|
249
|
-
raise ::Exception.new "'#{f}' is not in scaffold fields."
|
250
|
-
end
|
251
|
-
end
|
252
|
-
return bfields
|
253
|
-
else
|
254
|
-
|
255
|
-
return self.send(:fields).collect {|f| f[0]}
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
|
-
# Return an string to use as a function parameters each
|
260
|
-
# field appears as symbol
|
261
|
-
def fields_as_params(relations: false)
|
262
|
-
result = ""
|
263
|
-
field_num = 0
|
264
|
-
fields.each do |name, type|
|
265
|
-
if relations
|
266
|
-
if ["belongs_to"].include? type
|
267
|
-
result += " :#{name}_id"
|
268
|
-
else
|
269
|
-
result += " :#{name}"
|
270
|
-
end
|
271
|
-
field_num += 1
|
272
|
-
if field_num < fields.length
|
273
|
-
result += ","
|
274
|
-
end
|
275
|
-
|
276
|
-
else
|
277
|
-
unless ["belongs_to", "has_many"].include? type
|
278
|
-
result += " :#{name}"
|
279
|
-
field_num += 1
|
280
|
-
if field_num < fields.length
|
281
|
-
result += ","
|
282
|
-
end
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
end
|
287
|
-
|
288
|
-
if result
|
289
|
-
result = ",#{result}"
|
290
|
-
if result[-1] == ","
|
291
|
-
result = result[0..-2]
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
result
|
296
|
-
end
|
297
|
-
|
298
|
-
def parse_menu(menu)
|
299
|
-
title, url = menu.split(":")
|
300
|
-
model = nil
|
301
|
-
if title.split(">").length > 1
|
302
|
-
title, model = title.split(">")
|
303
|
-
end
|
304
|
-
return title, url, model
|
305
|
-
end
|
306
|
-
|
307
|
-
|
308
91
|
def random_json_data
|
309
92
|
data = {}
|
310
93
|
fields.each do |field, type|
|
@@ -325,36 +108,6 @@ module Faalis
|
|
325
108
|
(0...50).map{ o[rand(o.length)] }.join
|
326
109
|
end
|
327
110
|
|
328
|
-
def required_fields
|
329
|
-
if not options[:required].empty?
|
330
|
-
return options[:required].split(",")
|
331
|
-
end
|
332
|
-
[]
|
333
|
-
end
|
334
|
-
class Relation < String
|
335
|
-
attr_accessor :to
|
336
|
-
|
337
|
-
def initialize(value, to_)
|
338
|
-
super(value)
|
339
|
-
self.to = to_
|
340
|
-
end
|
341
|
-
|
342
|
-
def resource_name
|
343
|
-
to.split("/").last
|
344
|
-
end
|
345
|
-
|
346
|
-
def restangular
|
347
|
-
result = "API"
|
348
|
-
to.split("/").each do |resource|
|
349
|
-
result = "#{result}.all(\"#{resource}\")"
|
350
|
-
end
|
351
|
-
result
|
352
|
-
end
|
353
|
-
|
354
|
-
def get_list
|
355
|
-
"#{restangular}.getList()"
|
356
|
-
end
|
357
|
-
end
|
358
111
|
end
|
359
112
|
end
|
360
113
|
end
|
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
<% end %>
|
22
22
|
// <%= resource.pluralize %> Module
|
23
|
-
var <%= resource.pluralize %> = angular.module("<%= resource %>", ["ListView", "Filter", "Anim", "Fields",<% if options[:deps] %><% options[:deps].split(",").each do |dependency|
|
23
|
+
var <%= resource.pluralize %> = angular.module("<%= resource %>", ["ListView", "Filter", "Anim", "Fields",<% if options[:deps] %><% options[:deps].gsub(" ", "").split(",").each do |dependency| %> "<%= dependency.camelize %>", <% end %><% end %>]);
|
24
24
|
|
25
25
|
// <%= resource.pluralize %> configuration section ---------------------------
|
26
26
|
<%= resource.pluralize %>.config(["$routeProvider", function($routeProvider){
|
@@ -0,0 +1,31 @@
|
|
1
|
+
==================================================
|
2
|
+
Steps to installation:
|
3
|
+
|
4
|
+
0. You have to have a working model to use this scaffold. So create
|
5
|
+
your model and setup validations, relations and other stuff.
|
6
|
+
|
7
|
+
1. Add resource to routes.rb for example in case of `car` scaffold do:
|
8
|
+
|
9
|
+
namespace :api, :defaults => {:format => :json} do
|
10
|
+
namespace :v1 do
|
11
|
+
resources :cars
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
2. The Angularjs module of your resource should be added as an dependency
|
16
|
+
to another Angularjs module. Add it by hand or if you want to view module
|
17
|
+
in dashboard's main page add your resource to `config/initializers/faalis.rb`
|
18
|
+
like this:
|
19
|
+
|
20
|
+
config.dashboard_modules = {
|
21
|
+
:car => {
|
22
|
+
:icon => "fa fa-car",
|
23
|
+
:sidemenu => true,
|
24
|
+
},
|
25
|
+
}
|
26
|
+
|
27
|
+
3. Make sure that you have `api_controller.rb` in your `app/controllers` with this content:
|
28
|
+
|
29
|
+
|
30
|
+
class APIController < Faalis::APIController
|
31
|
+
end
|