binda 0.0.2

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.
Files changed (201) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +63 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/config/binda_manifest.js +2 -0
  6. data/app/assets/javascripts/binda/application.js +18 -0
  7. data/app/assets/javascripts/binda/components/form_item.js +54 -0
  8. data/app/assets/javascripts/binda/components/form_item_asset.js +24 -0
  9. data/app/assets/javascripts/binda/components/form_item_repeater.js +66 -0
  10. data/app/assets/javascripts/binda/components/sortable.js +44 -0
  11. data/app/assets/javascripts/binda/dist/binda.bundle.js +336 -0
  12. data/app/assets/javascripts/binda/index.js +16 -0
  13. data/app/assets/stylesheets/binda/application.css +6 -0
  14. data/app/assets/stylesheets/binda/components/assets_manager.scss +46 -0
  15. data/app/assets/stylesheets/binda/components/button.scss +7 -0
  16. data/app/assets/stylesheets/binda/components/form_body.scss +2 -0
  17. data/app/assets/stylesheets/binda/components/form_item.scss +169 -0
  18. data/app/assets/stylesheets/binda/components/form_item_asset.scss +20 -0
  19. data/app/assets/stylesheets/binda/components/form_section.scss +40 -0
  20. data/app/assets/stylesheets/binda/components/login.scss +6 -0
  21. data/app/assets/stylesheets/binda/components/main_container.scss +0 -0
  22. data/app/assets/stylesheets/binda/components/main_content.scss +5 -0
  23. data/app/assets/stylesheets/binda/components/main_header.scss +25 -0
  24. data/app/assets/stylesheets/binda/components/main_table.scss +28 -0
  25. data/app/assets/stylesheets/binda/components/sidebar.scss +131 -0
  26. data/app/assets/stylesheets/binda/components/sortable.scss +98 -0
  27. data/app/assets/stylesheets/binda/index.scss +24 -0
  28. data/app/assets/stylesheets/binda/layout/components_index.scss +9 -0
  29. data/app/assets/stylesheets/binda/layout/dashboard.scss +7 -0
  30. data/app/assets/stylesheets/binda/layout/users_sign_in.scss +29 -0
  31. data/app/assets/stylesheets/binda/settings/common.scss +93 -0
  32. data/app/assets/stylesheets/binda/settings/fonts.scss +90 -0
  33. data/app/assets/stylesheets/binda/settings/variables.scss +83 -0
  34. data/app/assets/stylesheets/scaffolds.scss +89 -0
  35. data/app/controllers/binda/application_controller.rb +29 -0
  36. data/app/controllers/binda/assets_controller.rb +62 -0
  37. data/app/controllers/binda/bindings_controller.rb +62 -0
  38. data/app/controllers/binda/categories_controller.rb +60 -0
  39. data/app/controllers/binda/components_controller.rb +223 -0
  40. data/app/controllers/binda/dates_controller.rb +62 -0
  41. data/app/controllers/binda/field_groups_controller.rb +114 -0
  42. data/app/controllers/binda/field_settings_controller.rb +66 -0
  43. data/app/controllers/binda/galleries_controller.rb +62 -0
  44. data/app/controllers/binda/manage/users_controller.rb +97 -0
  45. data/app/controllers/binda/repeaters_controller.rb +67 -0
  46. data/app/controllers/binda/settings_controller.rb +75 -0
  47. data/app/controllers/binda/structures_controller.rb +89 -0
  48. data/app/controllers/binda/texts_controller.rb +62 -0
  49. data/app/controllers/binda/users/confirmations_controller.rb +33 -0
  50. data/app/controllers/binda/users/omniauth_callbacks_controller.rb +33 -0
  51. data/app/controllers/binda/users/passwords_controller.rb +37 -0
  52. data/app/controllers/binda/users/registrations_controller.rb +89 -0
  53. data/app/controllers/binda/users/sessions_controller.rb +30 -0
  54. data/app/controllers/binda/users/unlocks_controller.rb +33 -0
  55. data/app/helpers/binda/application_helper.rb +25 -0
  56. data/app/helpers/binda/assets_helper.rb +4 -0
  57. data/app/helpers/binda/bindings_helper.rb +4 -0
  58. data/app/helpers/binda/categories_helper.rb +10 -0
  59. data/app/helpers/binda/components_helper.rb +10 -0
  60. data/app/helpers/binda/dates_helper.rb +4 -0
  61. data/app/helpers/binda/field_groups_helper.rb +10 -0
  62. data/app/helpers/binda/field_settings_helper.rb +14 -0
  63. data/app/helpers/binda/galleries_helper.rb +4 -0
  64. data/app/helpers/binda/repeaters_helper.rb +4 -0
  65. data/app/helpers/binda/settings_helper.rb +13 -0
  66. data/app/helpers/binda/structures_helper.rb +4 -0
  67. data/app/helpers/binda/texts_helper.rb +4 -0
  68. data/app/jobs/binda/application_job.rb +4 -0
  69. data/app/mailers/binda/application_mailer.rb +6 -0
  70. data/app/models/binda/application_record.rb +5 -0
  71. data/app/models/binda/asset.rb +21 -0
  72. data/app/models/binda/binding.rb +24 -0
  73. data/app/models/binda/category.rb +31 -0
  74. data/app/models/binda/component.rb +186 -0
  75. data/app/models/binda/date.rb +9 -0
  76. data/app/models/binda/field_group.rb +40 -0
  77. data/app/models/binda/field_setting.rb +95 -0
  78. data/app/models/binda/gallery.rb +18 -0
  79. data/app/models/binda/repeater.rb +108 -0
  80. data/app/models/binda/setting.rb +42 -0
  81. data/app/models/binda/structure.rb +31 -0
  82. data/app/models/binda/text.rb +9 -0
  83. data/app/models/binda/user.rb +8 -0
  84. data/app/uploaders/binda/asset/image_uploader.rb +76 -0
  85. data/app/views/binda/assets/_form.html.erb +22 -0
  86. data/app/views/binda/assets/edit.html.erb +6 -0
  87. data/app/views/binda/assets/index.html.erb +29 -0
  88. data/app/views/binda/assets/new.html.erb +5 -0
  89. data/app/views/binda/assets/show.html.erb +19 -0
  90. data/app/views/binda/bindings/_form.html.erb +32 -0
  91. data/app/views/binda/bindings/edit.html.erb +6 -0
  92. data/app/views/binda/bindings/index.html.erb +31 -0
  93. data/app/views/binda/bindings/new.html.erb +5 -0
  94. data/app/views/binda/bindings/show.html.erb +19 -0
  95. data/app/views/binda/categories/_form.html.erb +58 -0
  96. data/app/views/binda/categories/edit.html.erb +8 -0
  97. data/app/views/binda/categories/index.html.erb +34 -0
  98. data/app/views/binda/categories/new.html.erb +8 -0
  99. data/app/views/binda/components/_form_body.html.erb +86 -0
  100. data/app/views/binda/components/_form_item_asset.html.erb +20 -0
  101. data/app/views/binda/components/_form_item_date.html.erb +16 -0
  102. data/app/views/binda/components/_form_item_gallery.html.erb +0 -0
  103. data/app/views/binda/components/_form_item_new_repeater.html.erb +33 -0
  104. data/app/views/binda/components/_form_item_repeater.html.erb +81 -0
  105. data/app/views/binda/components/_form_item_text.html.erb +28 -0
  106. data/app/views/binda/components/_form_section.html.erb +37 -0
  107. data/app/views/binda/components/_form_section_repeater.html.erb +31 -0
  108. data/app/views/binda/components/_form_sidebar.html.erb +34 -0
  109. data/app/views/binda/components/edit.html.erb +8 -0
  110. data/app/views/binda/components/index.html.erb +43 -0
  111. data/app/views/binda/components/new.html.erb +8 -0
  112. data/app/views/binda/dates/_form.html.erb +22 -0
  113. data/app/views/binda/dates/edit.html.erb +6 -0
  114. data/app/views/binda/dates/index.html.erb +27 -0
  115. data/app/views/binda/dates/new.html.erb +5 -0
  116. data/app/views/binda/dates/show.html.erb +9 -0
  117. data/app/views/binda/field_groups/_form_body.html.erb +71 -0
  118. data/app/views/binda/field_groups/_form_item.html.erb +62 -0
  119. data/app/views/binda/field_groups/_form_section.html.erb +37 -0
  120. data/app/views/binda/field_groups/_form_section_repeater.html.erb +25 -0
  121. data/app/views/binda/field_groups/edit.html.erb +8 -0
  122. data/app/views/binda/field_groups/index.html.erb +34 -0
  123. data/app/views/binda/field_groups/new.html.erb +8 -0
  124. data/app/views/binda/field_settings/_form_body.html.erb +60 -0
  125. data/app/views/binda/field_settings/edit.html.erb +8 -0
  126. data/app/views/binda/field_settings/index.html.erb +31 -0
  127. data/app/views/binda/field_settings/new.html.erb +8 -0
  128. data/app/views/binda/galleries/_form.html.erb +27 -0
  129. data/app/views/binda/galleries/edit.html.erb +6 -0
  130. data/app/views/binda/galleries/index.html.erb +29 -0
  131. data/app/views/binda/galleries/new.html.erb +5 -0
  132. data/app/views/binda/galleries/show.html.erb +14 -0
  133. data/app/views/binda/manage/users/_admin_manage_user.json.jbuilder +2 -0
  134. data/app/views/binda/manage/users/_form_body.html.erb +58 -0
  135. data/app/views/binda/manage/users/edit.html.erb +8 -0
  136. data/app/views/binda/manage/users/index.html.erb +38 -0
  137. data/app/views/binda/manage/users/index.json.jbuilder +1 -0
  138. data/app/views/binda/manage/users/new.html.erb +8 -0
  139. data/app/views/binda/manage/users/show.json.jbuilder +1 -0
  140. data/app/views/binda/repeaters/_form.html.erb +27 -0
  141. data/app/views/binda/repeaters/edit.html.erb +6 -0
  142. data/app/views/binda/repeaters/index.html.erb +29 -0
  143. data/app/views/binda/repeaters/new.html.erb +5 -0
  144. data/app/views/binda/repeaters/show.html.erb +14 -0
  145. data/app/views/binda/settings/_dashboard_form.html.erb +51 -0
  146. data/app/views/binda/settings/_form.html.erb +52 -0
  147. data/app/views/binda/settings/dashboard.html.erb +9 -0
  148. data/app/views/binda/settings/edit.html.erb +8 -0
  149. data/app/views/binda/settings/index.html.erb +34 -0
  150. data/app/views/binda/settings/new.html.erb +8 -0
  151. data/app/views/binda/structures/_form_body.html.erb +56 -0
  152. data/app/views/binda/structures/_form_section.html.erb +64 -0
  153. data/app/views/binda/structures/add_child.html.erb +0 -0
  154. data/app/views/binda/structures/edit.html.erb +8 -0
  155. data/app/views/binda/structures/index.html.erb +34 -0
  156. data/app/views/binda/structures/new.html.erb +8 -0
  157. data/app/views/binda/texts/_form.html.erb +22 -0
  158. data/app/views/binda/texts/edit.html.erb +6 -0
  159. data/app/views/binda/texts/index.html.erb +27 -0
  160. data/app/views/binda/texts/new.html.erb +5 -0
  161. data/app/views/binda/texts/show.html.erb +9 -0
  162. data/app/views/layouts/binda/_flash.html.erb +26 -0
  163. data/app/views/layouts/binda/_header.html.erb +9 -0
  164. data/app/views/layouts/binda/_sidebar.html.erb +50 -0
  165. data/app/views/layouts/binda/application.html.erb +29 -0
  166. data/app/views/users/confirmations/new.html.erb +16 -0
  167. data/app/views/users/mailer/confirmation_instructions.html.erb +5 -0
  168. data/app/views/users/mailer/password_change.html.erb +3 -0
  169. data/app/views/users/mailer/reset_password_instructions.html.erb +8 -0
  170. data/app/views/users/mailer/unlock_instructions.html.erb +7 -0
  171. data/app/views/users/passwords/edit.html.erb +31 -0
  172. data/app/views/users/passwords/new.html.erb +28 -0
  173. data/app/views/users/registrations/edit.html.erb +27 -0
  174. data/app/views/users/registrations/new.html.erb +17 -0
  175. data/app/views/users/sessions/new.html.erb +27 -0
  176. data/app/views/users/shared/_links.html.erb +25 -0
  177. data/app/views/users/unlocks/new.html.erb +16 -0
  178. data/config/initializers/assets.rb +3 -0
  179. data/config/initializers/devise.rb +278 -0
  180. data/config/initializers/devise_patch.rb +50 -0
  181. data/config/initializers/friendly_id.rb +88 -0
  182. data/config/initializers/simple_form.rb +165 -0
  183. data/config/initializers/simple_form_bootstrap.rb +149 -0
  184. data/config/locales/devise.en.yml +62 -0
  185. data/config/locales/en.yml +37 -0
  186. data/config/locales/simple_form.en.yml +31 -0
  187. data/config/routes.rb +67 -0
  188. data/config/tinymce.yml +15 -0
  189. data/db/migrate/1_create_binda_tables.rb +172 -0
  190. data/lib/binda.rb +5 -0
  191. data/lib/binda/engine.rb +30 -0
  192. data/lib/binda/version.rb +3 -0
  193. data/lib/generators/binda/install/USAGE +9 -0
  194. data/lib/generators/binda/install/install_generator.rb +107 -0
  195. data/lib/generators/binda/install/templates/config/initializers/carrierwave.rb +32 -0
  196. data/lib/generators/binda/install/templates/config/initializers/devise.rb +280 -0
  197. data/lib/generators/binda/setup/USAGE +8 -0
  198. data/lib/generators/binda/setup/setup_generator.rb +43 -0
  199. data/lib/tasks/binda.rake +25 -0
  200. data/lib/templates/erb/scaffold/_form.html.erb +13 -0
  201. metadata +637 -0
@@ -0,0 +1,4 @@
1
+ module Binda
2
+ module BindingsHelper
3
+ end
4
+ end
@@ -0,0 +1,10 @@
1
+ module Binda
2
+ module CategoriesHelper
3
+
4
+ def get_form_category_url
5
+ return structure_categories_path if action_name == 'new'
6
+ return structure_category_path if action_name == 'edit'
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Binda
2
+ module ComponentsHelper
3
+
4
+ def get_form_component_url
5
+ return structure_components_path if action_name == 'new'
6
+ return structure_component_path if action_name == 'edit'
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ module Binda
2
+ module DatesHelper
3
+ end
4
+ end
@@ -0,0 +1,10 @@
1
+ module Binda
2
+ module FieldGroupsHelper
3
+
4
+ def get_form_field_group_url
5
+ return structure_field_groups_path if action_name == 'new'
6
+ return structure_field_group_path if action_name == 'edit'
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ module Binda
2
+ module FieldSettingsHelper
3
+
4
+ def get_form_field_setting_url
5
+ return structure_field_group_field_settings_path if action_name == 'new'
6
+ return structure_field_group_field_setting_path if action_name == 'edit'
7
+ end
8
+
9
+ def get_field_types
10
+ FieldSetting.new.get_field_types
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,4 @@
1
+ module Binda
2
+ module GalleriesHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Binda
2
+ module RepeatersHelper
3
+ end
4
+ end
@@ -0,0 +1,13 @@
1
+ module Binda
2
+ module SettingsHelper
3
+
4
+ def get_website_name
5
+ Setting.friendly.find('website-name').content
6
+ end
7
+
8
+ def get_website_description
9
+ Setting.friendly.find('website-description').content
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ module Binda
2
+ module StructuresHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Binda
2
+ module TextsHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Binda
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module Binda
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Binda
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ module Binda
2
+ class Asset < ApplicationRecord
3
+
4
+ # Associations
5
+ has_many :bindings
6
+ has_many :galleries, through: :bindings
7
+ belongs_to :fieldable, polymorphic: true
8
+ belongs_to :field_setting
9
+
10
+ mount_uploader :image, ImageUploader
11
+
12
+ # Validations
13
+
14
+ # Slug
15
+
16
+
17
+ # CUSTOM METHODS
18
+ # --------------
19
+
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ module Binda
2
+ class Binding < ApplicationRecord
3
+
4
+ # Associations
5
+ belongs_to :asset
6
+ belongs_to :gallery
7
+
8
+ # Validations
9
+ validates :name, presence: true
10
+
11
+ # Slug
12
+ extend FriendlyId
13
+ friendly_id :name, use: [:slugged, :finders]
14
+
15
+
16
+ # CUSTOM METHODS
17
+ # --------------
18
+ # https://github.com/norman/friendly_id/issues/436
19
+ def should_generate_new_friendly_id?
20
+ slug.blank?
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,31 @@
1
+ module Binda
2
+ class Category < ApplicationRecord
3
+
4
+ # Associations
5
+ belongs_to :structure
6
+ has_and_belongs_to_many :components
7
+
8
+ # Validations
9
+ validates :name, presence: true
10
+
11
+ # Slug
12
+ extend FriendlyId
13
+ friendly_id :default_slug, use: [:slugged, :finders]
14
+
15
+
16
+ # CUSTOM METHODS
17
+ # --------------
18
+ # https://github.com/norman/friendly_id/issues/436
19
+ def should_generate_new_friendly_id?
20
+ slug.blank? || name_changed?
21
+ end
22
+
23
+ def default_slug
24
+ [ "#{ self.structure.name }-#{ self.name }",
25
+ "#{ self.structure.name }-#{ self.name }-1",
26
+ "#{ self.structure.name }-#{ self.name }-2",
27
+ "#{ self.structure.name }-#{ self.name }-3" ]
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,186 @@
1
+ module Binda
2
+ class Component < ApplicationRecord
3
+
4
+ # Associations
5
+ belongs_to :structure, required: true
6
+ has_and_belongs_to_many :categories
7
+ has_many :texts, as: :fieldable, dependent: :delete_all
8
+ has_many :dates, as: :fieldable, dependent: :delete_all
9
+ has_many :galleries, as: :fieldable, dependent: :delete_all
10
+ has_many :assets, as: :fieldable, dependent: :delete_all
11
+ # Repeaters need destroy_all, not delete_all
12
+ has_many :repeaters, as: :fieldable, dependent: :destroy
13
+
14
+
15
+ accepts_nested_attributes_for :structure, :categories, :texts, :dates, :assets, :galleries, :repeaters, allow_destroy: true
16
+
17
+ cattr_accessor :field_settings_array
18
+
19
+ # has_many :bindings
20
+ # has_many :assets, class_name: 'Admin::Asset', through: :bindings
21
+
22
+ # Validations
23
+ validates :name, presence: true
24
+ validates :slug, uniqueness: true
25
+ validates :publish_state, presence: true, inclusion: { in: %w( draft published )}
26
+
27
+ # Slug
28
+ extend FriendlyId
29
+ friendly_id :name, use: [:slugged, :finders]
30
+
31
+ # Publish state behaviour
32
+ include AASM
33
+
34
+ aasm :column => 'publish_state' do
35
+ state :draft, initial: true
36
+ state :published
37
+
38
+ event :publish do
39
+ transitions from: :draft, to: :published
40
+ end
41
+
42
+ event :unpublish do
43
+ transitions from: :published, to: :draft
44
+ end
45
+
46
+ end
47
+
48
+
49
+ # CUSTOM METHODS
50
+ # --------------
51
+ # https://github.com/norman/friendly_id/issues/436
52
+ def should_generate_new_friendly_id?
53
+ slug.blank?
54
+ end
55
+
56
+ def find_or_create_a_field_by field_setting_id, field_type
57
+ if Binda::FieldSetting.get_fieldables.include?( field_type.capitalize ) && field_setting_id.is_a?( Integer )
58
+ self.send( field_type.pluralize ).find_or_create_by( field_setting_id: field_setting_id )
59
+ else
60
+ raise ArgumentError, "A parameter of the method 'find_or_create_a_field_by' is not correct.", caller
61
+ end
62
+ end
63
+
64
+ def get_text( field_slug )
65
+ # Get the object related to that field setting
66
+ self.texts.find{ |t| t.field_setting_id == Binda::FieldSetting.get_id( field_slug ) }.content
67
+ end
68
+
69
+ def has_text( field_slug )
70
+ # Get the object related to that field setting
71
+ obj = self.texts.find{ |t| t.field_setting_id == Binda::FieldSetting.get_id( field_slug ) }
72
+ if obj.present?
73
+ return !obj.content.blank?
74
+ else
75
+ return false
76
+ end
77
+ end
78
+
79
+ def has_image( field_slug )
80
+ # Check if the field has an attached image
81
+ obj = self.assets.find{ |t| t.field_setting_id == Binda::FieldSetting.get_id( field_slug ) }.image
82
+ return obj.present?
83
+ end
84
+
85
+ def get_image_url( field_slug, size = '' )
86
+ get_image_info( field_slug, size, 'url' )
87
+ end
88
+
89
+ def get_image_path( field_slug, size = '' )
90
+ get_image_info( field_slug, size, 'path' )
91
+ end
92
+
93
+ def get_image_info( field_slug, size, info )
94
+ # Get the object related to that field setting
95
+ obj = self.assets.find{ |t| t.field_setting_id == Binda::FieldSetting.get_id( field_slug ) }
96
+ if obj.image.present?
97
+ if obj.image.respond_to?(size) && %w[thumb medium large].include?(size)
98
+ obj.image.send(size).send(info)
99
+ else
100
+ obj.image.send(info)
101
+ end
102
+ end
103
+ end
104
+
105
+ def has_date( field_slug )
106
+ # Check if the field has an attached date
107
+ obj = self.dates.find{ |t| t.field_setting_id == Binda::FieldSetting.get_id( field_slug ) }
108
+ if obj.present?
109
+ return !obj.date.nil?
110
+ else
111
+ return false
112
+ end
113
+ end
114
+
115
+ def get_date( field_slug )
116
+ # Get the object related to that field setting
117
+ self.dates.find{ |t| t.field_setting_id == Binda::FieldSetting.get_id( field_slug ) }.date
118
+ end
119
+
120
+ def has_repeater( field_slug )
121
+ obj = self.repeaters.find_all{ |t| t.field_setting_id == Binda::FieldSetting.get_id( field_slug ) }
122
+ return obj.present?
123
+ end
124
+
125
+ def get_repeater( field_slug )
126
+ self.repeaters.find_all{ |t| t.field_setting_id == Binda::FieldSetting.get_id( field_slug ) }.sort_by(&:position)
127
+ end
128
+
129
+
130
+ # benchmark do
131
+ # id = Binda::FieldSetting.field_settings_array.find { |fs| fs.slug == 'home-slides-project-image' }.id
132
+ # obj = slide.assets.find{ |t| t.field_setting_id == id }
133
+ # if obj.image.present?
134
+ # if obj.image.respond_to?('') && %w[thumb medium large].include?('')
135
+ # obj.image.send('').send('path')
136
+ # else
137
+ # obj.image.send('path')
138
+ # end
139
+ # end
140
+ # end
141
+
142
+ # BENCHMARK GET_IMAGE METHODS
143
+ # ---------------------------
144
+ # def get_image_benchmark( field_slug, size, info )
145
+ # # Best is to run this group of test alone (i.e. without TestA and TestB)
146
+ #
147
+ # obj = self.assets.find{ |t| t.field_setting_id == Binda::FieldSetting.get_id( field_slug ) }
148
+ #
149
+ # self.class.benchmark("Check if image is present") do
150
+ # obj.image.present?
151
+ # end
152
+ # self.class.benchmark("Check if file exists") do
153
+ # obj.image.file.exists?
154
+ # end
155
+ # self.class.benchmark("Check if image respond to size") do
156
+ # obj.image.respond_to?(size)
157
+ # end
158
+ # self.class.benchmark("Check if size is in array") do
159
+ # %w[thumb medium large].include?(size)
160
+ # end
161
+ # if %w[thumb medium large].include?(size)
162
+ # self.class.benchmark("get resized image") do
163
+ # obj.image.send(size).send(info)
164
+ # end
165
+ # else
166
+ # self.class.benchmark("get default image") do
167
+ # obj.image.send(info)
168
+ # end
169
+ # end
170
+
171
+ # # Run TestA and TestB separately not one after the other
172
+ # # as the first time carrierwave runs is slower than the second time
173
+ # self.class.benchmark("TestA: Get image info (url)") do
174
+ # get_image_info( field_slug, size, 'url' )
175
+ # end
176
+ # self.class.benchmark("TestB: Get image info (path)") do
177
+ # get_image_info( field_slug, size, 'path' )
178
+ # end
179
+
180
+ # self.class.benchmark("Get field setting id") do
181
+ # self.assets.find{ |t| t.field_setting_id == Binda::FieldSetting.get_id( field_slug ) }
182
+ # end
183
+ # end
184
+
185
+ end
186
+ end
@@ -0,0 +1,9 @@
1
+ module Binda
2
+ class Date < ApplicationRecord
3
+
4
+ # Associations
5
+ belongs_to :fieldable, polymorphic: true
6
+ belongs_to :field_setting
7
+
8
+ end
9
+ end
@@ -0,0 +1,40 @@
1
+ module Binda
2
+ class FieldGroup < ApplicationRecord
3
+
4
+ # Associations
5
+ belongs_to :structure
6
+
7
+ # use destroy not delete_all otherwise the field settings
8
+ # won't be able to delete all their dependent content
9
+ has_many :field_settings, dependent: :delete_all
10
+
11
+ # Validations
12
+ validates :name, presence: true
13
+ validates :slug, uniqueness: true
14
+ accepts_nested_attributes_for :field_settings, allow_destroy: true, reject_if: :is_rejected
15
+
16
+ # Slug
17
+ extend FriendlyId
18
+ friendly_id :default_slug, use: [:slugged, :finders]
19
+
20
+
21
+ # CUSTOM METHODS
22
+ # --------------
23
+ # https://github.com/norman/friendly_id/issues/436
24
+ def should_generate_new_friendly_id?
25
+ slug.blank?
26
+ end
27
+
28
+ def default_slug
29
+ [ "#{ self.structure.name }-#{ self.name }",
30
+ "#{ self.structure.name }-#{ self.name }-1",
31
+ "#{ self.structure.name }-#{ self.name }-2",
32
+ "#{ self.structure.name }-#{ self.name }-3" ]
33
+ end
34
+
35
+ def is_rejected( attributes )
36
+ attributes['name'].blank? && attributes['field_type'].blank?
37
+ end
38
+
39
+ end
40
+ end