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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +63 -0
- data/Rakefile +37 -0
- data/app/assets/config/binda_manifest.js +2 -0
- data/app/assets/javascripts/binda/application.js +18 -0
- data/app/assets/javascripts/binda/components/form_item.js +54 -0
- data/app/assets/javascripts/binda/components/form_item_asset.js +24 -0
- data/app/assets/javascripts/binda/components/form_item_repeater.js +66 -0
- data/app/assets/javascripts/binda/components/sortable.js +44 -0
- data/app/assets/javascripts/binda/dist/binda.bundle.js +336 -0
- data/app/assets/javascripts/binda/index.js +16 -0
- data/app/assets/stylesheets/binda/application.css +6 -0
- data/app/assets/stylesheets/binda/components/assets_manager.scss +46 -0
- data/app/assets/stylesheets/binda/components/button.scss +7 -0
- data/app/assets/stylesheets/binda/components/form_body.scss +2 -0
- data/app/assets/stylesheets/binda/components/form_item.scss +169 -0
- data/app/assets/stylesheets/binda/components/form_item_asset.scss +20 -0
- data/app/assets/stylesheets/binda/components/form_section.scss +40 -0
- data/app/assets/stylesheets/binda/components/login.scss +6 -0
- data/app/assets/stylesheets/binda/components/main_container.scss +0 -0
- data/app/assets/stylesheets/binda/components/main_content.scss +5 -0
- data/app/assets/stylesheets/binda/components/main_header.scss +25 -0
- data/app/assets/stylesheets/binda/components/main_table.scss +28 -0
- data/app/assets/stylesheets/binda/components/sidebar.scss +131 -0
- data/app/assets/stylesheets/binda/components/sortable.scss +98 -0
- data/app/assets/stylesheets/binda/index.scss +24 -0
- data/app/assets/stylesheets/binda/layout/components_index.scss +9 -0
- data/app/assets/stylesheets/binda/layout/dashboard.scss +7 -0
- data/app/assets/stylesheets/binda/layout/users_sign_in.scss +29 -0
- data/app/assets/stylesheets/binda/settings/common.scss +93 -0
- data/app/assets/stylesheets/binda/settings/fonts.scss +90 -0
- data/app/assets/stylesheets/binda/settings/variables.scss +83 -0
- data/app/assets/stylesheets/scaffolds.scss +89 -0
- data/app/controllers/binda/application_controller.rb +29 -0
- data/app/controllers/binda/assets_controller.rb +62 -0
- data/app/controllers/binda/bindings_controller.rb +62 -0
- data/app/controllers/binda/categories_controller.rb +60 -0
- data/app/controllers/binda/components_controller.rb +223 -0
- data/app/controllers/binda/dates_controller.rb +62 -0
- data/app/controllers/binda/field_groups_controller.rb +114 -0
- data/app/controllers/binda/field_settings_controller.rb +66 -0
- data/app/controllers/binda/galleries_controller.rb +62 -0
- data/app/controllers/binda/manage/users_controller.rb +97 -0
- data/app/controllers/binda/repeaters_controller.rb +67 -0
- data/app/controllers/binda/settings_controller.rb +75 -0
- data/app/controllers/binda/structures_controller.rb +89 -0
- data/app/controllers/binda/texts_controller.rb +62 -0
- data/app/controllers/binda/users/confirmations_controller.rb +33 -0
- data/app/controllers/binda/users/omniauth_callbacks_controller.rb +33 -0
- data/app/controllers/binda/users/passwords_controller.rb +37 -0
- data/app/controllers/binda/users/registrations_controller.rb +89 -0
- data/app/controllers/binda/users/sessions_controller.rb +30 -0
- data/app/controllers/binda/users/unlocks_controller.rb +33 -0
- data/app/helpers/binda/application_helper.rb +25 -0
- data/app/helpers/binda/assets_helper.rb +4 -0
- data/app/helpers/binda/bindings_helper.rb +4 -0
- data/app/helpers/binda/categories_helper.rb +10 -0
- data/app/helpers/binda/components_helper.rb +10 -0
- data/app/helpers/binda/dates_helper.rb +4 -0
- data/app/helpers/binda/field_groups_helper.rb +10 -0
- data/app/helpers/binda/field_settings_helper.rb +14 -0
- data/app/helpers/binda/galleries_helper.rb +4 -0
- data/app/helpers/binda/repeaters_helper.rb +4 -0
- data/app/helpers/binda/settings_helper.rb +13 -0
- data/app/helpers/binda/structures_helper.rb +4 -0
- data/app/helpers/binda/texts_helper.rb +4 -0
- data/app/jobs/binda/application_job.rb +4 -0
- data/app/mailers/binda/application_mailer.rb +6 -0
- data/app/models/binda/application_record.rb +5 -0
- data/app/models/binda/asset.rb +21 -0
- data/app/models/binda/binding.rb +24 -0
- data/app/models/binda/category.rb +31 -0
- data/app/models/binda/component.rb +186 -0
- data/app/models/binda/date.rb +9 -0
- data/app/models/binda/field_group.rb +40 -0
- data/app/models/binda/field_setting.rb +95 -0
- data/app/models/binda/gallery.rb +18 -0
- data/app/models/binda/repeater.rb +108 -0
- data/app/models/binda/setting.rb +42 -0
- data/app/models/binda/structure.rb +31 -0
- data/app/models/binda/text.rb +9 -0
- data/app/models/binda/user.rb +8 -0
- data/app/uploaders/binda/asset/image_uploader.rb +76 -0
- data/app/views/binda/assets/_form.html.erb +22 -0
- data/app/views/binda/assets/edit.html.erb +6 -0
- data/app/views/binda/assets/index.html.erb +29 -0
- data/app/views/binda/assets/new.html.erb +5 -0
- data/app/views/binda/assets/show.html.erb +19 -0
- data/app/views/binda/bindings/_form.html.erb +32 -0
- data/app/views/binda/bindings/edit.html.erb +6 -0
- data/app/views/binda/bindings/index.html.erb +31 -0
- data/app/views/binda/bindings/new.html.erb +5 -0
- data/app/views/binda/bindings/show.html.erb +19 -0
- data/app/views/binda/categories/_form.html.erb +58 -0
- data/app/views/binda/categories/edit.html.erb +8 -0
- data/app/views/binda/categories/index.html.erb +34 -0
- data/app/views/binda/categories/new.html.erb +8 -0
- data/app/views/binda/components/_form_body.html.erb +86 -0
- data/app/views/binda/components/_form_item_asset.html.erb +20 -0
- data/app/views/binda/components/_form_item_date.html.erb +16 -0
- data/app/views/binda/components/_form_item_gallery.html.erb +0 -0
- data/app/views/binda/components/_form_item_new_repeater.html.erb +33 -0
- data/app/views/binda/components/_form_item_repeater.html.erb +81 -0
- data/app/views/binda/components/_form_item_text.html.erb +28 -0
- data/app/views/binda/components/_form_section.html.erb +37 -0
- data/app/views/binda/components/_form_section_repeater.html.erb +31 -0
- data/app/views/binda/components/_form_sidebar.html.erb +34 -0
- data/app/views/binda/components/edit.html.erb +8 -0
- data/app/views/binda/components/index.html.erb +43 -0
- data/app/views/binda/components/new.html.erb +8 -0
- data/app/views/binda/dates/_form.html.erb +22 -0
- data/app/views/binda/dates/edit.html.erb +6 -0
- data/app/views/binda/dates/index.html.erb +27 -0
- data/app/views/binda/dates/new.html.erb +5 -0
- data/app/views/binda/dates/show.html.erb +9 -0
- data/app/views/binda/field_groups/_form_body.html.erb +71 -0
- data/app/views/binda/field_groups/_form_item.html.erb +62 -0
- data/app/views/binda/field_groups/_form_section.html.erb +37 -0
- data/app/views/binda/field_groups/_form_section_repeater.html.erb +25 -0
- data/app/views/binda/field_groups/edit.html.erb +8 -0
- data/app/views/binda/field_groups/index.html.erb +34 -0
- data/app/views/binda/field_groups/new.html.erb +8 -0
- data/app/views/binda/field_settings/_form_body.html.erb +60 -0
- data/app/views/binda/field_settings/edit.html.erb +8 -0
- data/app/views/binda/field_settings/index.html.erb +31 -0
- data/app/views/binda/field_settings/new.html.erb +8 -0
- data/app/views/binda/galleries/_form.html.erb +27 -0
- data/app/views/binda/galleries/edit.html.erb +6 -0
- data/app/views/binda/galleries/index.html.erb +29 -0
- data/app/views/binda/galleries/new.html.erb +5 -0
- data/app/views/binda/galleries/show.html.erb +14 -0
- data/app/views/binda/manage/users/_admin_manage_user.json.jbuilder +2 -0
- data/app/views/binda/manage/users/_form_body.html.erb +58 -0
- data/app/views/binda/manage/users/edit.html.erb +8 -0
- data/app/views/binda/manage/users/index.html.erb +38 -0
- data/app/views/binda/manage/users/index.json.jbuilder +1 -0
- data/app/views/binda/manage/users/new.html.erb +8 -0
- data/app/views/binda/manage/users/show.json.jbuilder +1 -0
- data/app/views/binda/repeaters/_form.html.erb +27 -0
- data/app/views/binda/repeaters/edit.html.erb +6 -0
- data/app/views/binda/repeaters/index.html.erb +29 -0
- data/app/views/binda/repeaters/new.html.erb +5 -0
- data/app/views/binda/repeaters/show.html.erb +14 -0
- data/app/views/binda/settings/_dashboard_form.html.erb +51 -0
- data/app/views/binda/settings/_form.html.erb +52 -0
- data/app/views/binda/settings/dashboard.html.erb +9 -0
- data/app/views/binda/settings/edit.html.erb +8 -0
- data/app/views/binda/settings/index.html.erb +34 -0
- data/app/views/binda/settings/new.html.erb +8 -0
- data/app/views/binda/structures/_form_body.html.erb +56 -0
- data/app/views/binda/structures/_form_section.html.erb +64 -0
- data/app/views/binda/structures/add_child.html.erb +0 -0
- data/app/views/binda/structures/edit.html.erb +8 -0
- data/app/views/binda/structures/index.html.erb +34 -0
- data/app/views/binda/structures/new.html.erb +8 -0
- data/app/views/binda/texts/_form.html.erb +22 -0
- data/app/views/binda/texts/edit.html.erb +6 -0
- data/app/views/binda/texts/index.html.erb +27 -0
- data/app/views/binda/texts/new.html.erb +5 -0
- data/app/views/binda/texts/show.html.erb +9 -0
- data/app/views/layouts/binda/_flash.html.erb +26 -0
- data/app/views/layouts/binda/_header.html.erb +9 -0
- data/app/views/layouts/binda/_sidebar.html.erb +50 -0
- data/app/views/layouts/binda/application.html.erb +29 -0
- data/app/views/users/confirmations/new.html.erb +16 -0
- data/app/views/users/mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/users/mailer/password_change.html.erb +3 -0
- data/app/views/users/mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/users/mailer/unlock_instructions.html.erb +7 -0
- data/app/views/users/passwords/edit.html.erb +31 -0
- data/app/views/users/passwords/new.html.erb +28 -0
- data/app/views/users/registrations/edit.html.erb +27 -0
- data/app/views/users/registrations/new.html.erb +17 -0
- data/app/views/users/sessions/new.html.erb +27 -0
- data/app/views/users/shared/_links.html.erb +25 -0
- data/app/views/users/unlocks/new.html.erb +16 -0
- data/config/initializers/assets.rb +3 -0
- data/config/initializers/devise.rb +278 -0
- data/config/initializers/devise_patch.rb +50 -0
- data/config/initializers/friendly_id.rb +88 -0
- data/config/initializers/simple_form.rb +165 -0
- data/config/initializers/simple_form_bootstrap.rb +149 -0
- data/config/locales/devise.en.yml +62 -0
- data/config/locales/en.yml +37 -0
- data/config/locales/simple_form.en.yml +31 -0
- data/config/routes.rb +67 -0
- data/config/tinymce.yml +15 -0
- data/db/migrate/1_create_binda_tables.rb +172 -0
- data/lib/binda.rb +5 -0
- data/lib/binda/engine.rb +30 -0
- data/lib/binda/version.rb +3 -0
- data/lib/generators/binda/install/USAGE +9 -0
- data/lib/generators/binda/install/install_generator.rb +107 -0
- data/lib/generators/binda/install/templates/config/initializers/carrierwave.rb +32 -0
- data/lib/generators/binda/install/templates/config/initializers/devise.rb +280 -0
- data/lib/generators/binda/setup/USAGE +8 -0
- data/lib/generators/binda/setup/setup_generator.rb +43 -0
- data/lib/tasks/binda.rake +25 -0
- data/lib/templates/erb/scaffold/_form.html.erb +13 -0
- metadata +637 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
module Binda
|
|
2
|
+
class FieldSetting < ApplicationRecord
|
|
3
|
+
|
|
4
|
+
# Associations
|
|
5
|
+
belongs_to :field_group
|
|
6
|
+
# has_many :field_children, class_name: ::Binda::FieldSetting, dependent: :delete_all
|
|
7
|
+
has_ancestry orphan_strategy: :destroy
|
|
8
|
+
|
|
9
|
+
# Fields Associations
|
|
10
|
+
# -------------------
|
|
11
|
+
# If you add a new field remember to update:
|
|
12
|
+
# - get_fieldables (see here below)
|
|
13
|
+
# - get_field_types (see here below)
|
|
14
|
+
# - component_params (app/controllers/binda/components_controller.rb)
|
|
15
|
+
has_many :texts, as: :fieldable
|
|
16
|
+
has_many :dates, as: :fieldable
|
|
17
|
+
has_many :galleries, as: :fieldable
|
|
18
|
+
has_many :assets, as: :fieldable
|
|
19
|
+
has_many :repeater, as: :fieldable
|
|
20
|
+
|
|
21
|
+
# The following direct association is used to securely delete associated fields
|
|
22
|
+
# Infact via `fieldable` the associated fields might not be deleted
|
|
23
|
+
# as the fieldable_id is related to the `component` rather than the `field_setting`
|
|
24
|
+
has_many :texts, dependent: :delete_all
|
|
25
|
+
has_many :dates, dependent: :delete_all
|
|
26
|
+
has_many :galleries, dependent: :delete_all
|
|
27
|
+
has_many :repeater, dependent: :delete_all
|
|
28
|
+
|
|
29
|
+
# accepts_nested_attributes_for :children, allow_destroy: true, reject_if: :is_rejected
|
|
30
|
+
|
|
31
|
+
cattr_accessor :field_settings_array
|
|
32
|
+
|
|
33
|
+
def self.get_fieldables
|
|
34
|
+
%w( Text Date Gallery Asset Repeater )
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Field types are't fieldable! watch out! They might use the same model (eg `string` and `text`)
|
|
38
|
+
def get_field_types
|
|
39
|
+
%w( string text asset gallery repeater date )
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Validations
|
|
43
|
+
validates :name, presence: true
|
|
44
|
+
# validates :field_type, presence: true, inclusion: { in: :get_field_types }
|
|
45
|
+
validates :field_group_id, presence: true
|
|
46
|
+
|
|
47
|
+
# Slug
|
|
48
|
+
extend FriendlyId
|
|
49
|
+
friendly_id :default_slug, use: [:slugged, :finders]
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
# CUSTOM METHODS
|
|
53
|
+
# --------------
|
|
54
|
+
# https://github.com/norman/friendly_id/issues/436
|
|
55
|
+
def should_generate_new_friendly_id?
|
|
56
|
+
slug.blank?
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def default_slug
|
|
60
|
+
slug = self.field_group.structure.name
|
|
61
|
+
|
|
62
|
+
slug << '-'
|
|
63
|
+
slug << self.field_group.name
|
|
64
|
+
|
|
65
|
+
unless self.parent.nil?
|
|
66
|
+
slug << '-'
|
|
67
|
+
slug << self.parent.name
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
possible_names = [
|
|
71
|
+
"#{ slug }--#{ self.name }",
|
|
72
|
+
"#{ slug }--#{ self.name }-1",
|
|
73
|
+
"#{ slug }--#{ self.name }-2",
|
|
74
|
+
"#{ slug }--#{ self.name }-3"
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
return possible_names
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def self.get_id( field_slug )
|
|
81
|
+
# Get field setting id from slug, without multiple calls to database
|
|
82
|
+
# (the query runs once and caches the result, then any further call uses the cached result)
|
|
83
|
+
@@field_settings_array = self.all if @@field_settings_array.nil?
|
|
84
|
+
@@field_settings_array.find { |fs| fs.slug == field_slug }.id
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def self.reset_field_settings_array
|
|
88
|
+
# Reset the result of the query taken with the above method,
|
|
89
|
+
# this is needed when a user creates a new field_setting but
|
|
90
|
+
# `get_field_setting_id` has already run once
|
|
91
|
+
@@field_settings_array = nil
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
end
|
|
95
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Binda
|
|
2
|
+
class Gallery < ApplicationRecord
|
|
3
|
+
|
|
4
|
+
# Associations
|
|
5
|
+
has_many :bindings
|
|
6
|
+
has_many :assets, through: :bindings
|
|
7
|
+
belongs_to :fieldable, polymorphic: true
|
|
8
|
+
belongs_to :field_setting
|
|
9
|
+
|
|
10
|
+
# Validations
|
|
11
|
+
|
|
12
|
+
# Slug
|
|
13
|
+
|
|
14
|
+
# CUSTOM METHODS
|
|
15
|
+
# --------------
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
module Binda
|
|
2
|
+
class Repeater < ApplicationRecord
|
|
3
|
+
|
|
4
|
+
# Associations
|
|
5
|
+
belongs_to :fieldable, polymorphic: true
|
|
6
|
+
belongs_to :field_setting
|
|
7
|
+
# has_many :field_settings, dependent: :delete_all
|
|
8
|
+
|
|
9
|
+
# Fields Associations
|
|
10
|
+
# -------------------
|
|
11
|
+
# If you add a new field remember to update:
|
|
12
|
+
# - get_fieldables (see here below)
|
|
13
|
+
# - get_field_types (see here below)
|
|
14
|
+
# - component_params (app/controllers/binda/components_controller.rb)
|
|
15
|
+
has_many :texts, as: :fieldable, dependent: :delete_all
|
|
16
|
+
has_many :dates, as: :fieldable, dependent: :delete_all
|
|
17
|
+
has_many :galleries, as: :fieldable, dependent: :delete_all
|
|
18
|
+
has_many :assets, as: :fieldable, dependent: :delete_all
|
|
19
|
+
# Repeaters need destroy_all, not delete_all
|
|
20
|
+
has_many :repeaters, as: :fieldable, dependent: :destroy
|
|
21
|
+
|
|
22
|
+
accepts_nested_attributes_for :texts, :dates, :assets, :galleries, :repeaters, allow_destroy: true
|
|
23
|
+
|
|
24
|
+
# The following direct association is used to securely delete associated fields
|
|
25
|
+
# Infact via `fieldable` the associated fields might not be deleted
|
|
26
|
+
# as the fieldable_id is related to the `component` rather than the `field_setting`
|
|
27
|
+
|
|
28
|
+
# # Validations
|
|
29
|
+
# validates :name, presence: true
|
|
30
|
+
|
|
31
|
+
# # Slug
|
|
32
|
+
# extend FriendlyId
|
|
33
|
+
# friendly_id :default_slug, use: [:slugged, :finders]
|
|
34
|
+
|
|
35
|
+
def find_or_create_a_field_by field_setting_id, field_type
|
|
36
|
+
if Binda::FieldSetting.get_fieldables.include?( field_type.capitalize ) && field_setting_id.is_a?( Integer )
|
|
37
|
+
self.send( field_type.pluralize ).find_or_create_by( field_setting_id: field_setting_id )
|
|
38
|
+
else
|
|
39
|
+
raise ArgumentError, "A parameter of the method 'find_or_create_a_field_by' is not correct.", caller
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def get_text( field_slug )
|
|
44
|
+
# Get the object related to that field setting
|
|
45
|
+
self.texts.find{ |t| t.field_setting_id == Binda::FieldSetting.get_id( field_slug ) }.content
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def has_text( field_slug )
|
|
49
|
+
# Get the object related to that field setting
|
|
50
|
+
obj = self.texts.find{ |t| t.field_setting_id == Binda::FieldSetting.get_id( field_slug ) }
|
|
51
|
+
if obj.present?
|
|
52
|
+
!obj.content.blank?
|
|
53
|
+
else
|
|
54
|
+
return false
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def has_image( field_slug )
|
|
59
|
+
# Check if the field has an attached image
|
|
60
|
+
self.assets.find{ |t| t.field_setting_id == Binda::FieldSetting.get_id( field_slug ) }.image.present?
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def get_image_url( field_slug, size = '' )
|
|
64
|
+
get_image_info( field_slug, size, 'url' )
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def get_image_path( field_slug, size = '' )
|
|
68
|
+
get_image_info( field_slug, size, 'path' )
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def get_image_info( field_slug, size, info )
|
|
72
|
+
# Get the object related to that field setting
|
|
73
|
+
obj = self.assets.find{ |t| t.field_setting_id == Binda::FieldSetting.get_id( field_slug ) }
|
|
74
|
+
if obj.image.present?
|
|
75
|
+
if obj.image.respond_to?(size) && %w[thumb medium large].include?(size)
|
|
76
|
+
obj.image.send(size).send(info)
|
|
77
|
+
else
|
|
78
|
+
obj.image.send(info)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def has_date( field_slug )
|
|
84
|
+
# Check if the field has an attached date
|
|
85
|
+
obj = self.dates.find{ |t| t.field_setting_id == Binda::FieldSetting.get_id( field_slug ) }
|
|
86
|
+
if obj.present?
|
|
87
|
+
!obj.date.nil?
|
|
88
|
+
else
|
|
89
|
+
return false
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def get_date( field_slug )
|
|
94
|
+
# Get the object related to that field setting
|
|
95
|
+
self.dates.find{ |t| t.field_setting_id == Binda::FieldSetting.get_id( field_slug ) }.date
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def has_repeater( field_slug )
|
|
99
|
+
obj = self.repeaters.find_all{ |t| t.field_setting_id == Binda::FieldSetting.get_id( field_slug ) }
|
|
100
|
+
return obj.present?
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def get_repeater( field_slug )
|
|
104
|
+
self.repeaters.find_all{ |t| t.field_setting_id == Binda::FieldSetting.get_id( field_slug ) }.sort_by(&:position)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
end
|
|
108
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module Binda
|
|
2
|
+
class Setting < ApplicationRecord
|
|
3
|
+
|
|
4
|
+
# Associations
|
|
5
|
+
# has_many :bindings
|
|
6
|
+
# has_many :assets, class_name: 'Admin::Asset', through: :bindings
|
|
7
|
+
|
|
8
|
+
# Validations
|
|
9
|
+
validates :name, presence: true
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# Slug
|
|
13
|
+
extend FriendlyId
|
|
14
|
+
friendly_id :name, use: [:slugged, :finders]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# CUSTOM METHODS
|
|
18
|
+
# --------------
|
|
19
|
+
# https://github.com/norman/friendly_id/issues/436
|
|
20
|
+
def should_generate_new_friendly_id?
|
|
21
|
+
slug.blank?
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.website_name
|
|
25
|
+
self.all.find { |s| s.slug == 'website-name' }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.website_description
|
|
29
|
+
self.all.find { |s| s.slug == 'website-description' }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.maintenance_mode
|
|
33
|
+
self.all.find { |s| s.slug == 'maintenance-mode' }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.is_maintenance_mode
|
|
37
|
+
# maybe this should have question mark at the end...
|
|
38
|
+
self.maintenance_mode.is_true
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module Binda
|
|
2
|
+
class Structure < ApplicationRecord
|
|
3
|
+
|
|
4
|
+
# Associations
|
|
5
|
+
has_many :components
|
|
6
|
+
has_many :categories
|
|
7
|
+
has_many :field_groups
|
|
8
|
+
|
|
9
|
+
# Validations
|
|
10
|
+
validates :name, presence: true
|
|
11
|
+
validates :slug, uniqueness: true
|
|
12
|
+
accepts_nested_attributes_for :field_groups, allow_destroy: true, reject_if: :is_rejected
|
|
13
|
+
|
|
14
|
+
# Slug
|
|
15
|
+
extend FriendlyId
|
|
16
|
+
friendly_id :name, use: [:slugged, :finders]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# CUSTOM METHODS
|
|
20
|
+
# --------------
|
|
21
|
+
# https://github.com/norman/friendly_id/issues/436
|
|
22
|
+
def should_generate_new_friendly_id?
|
|
23
|
+
slug.blank?
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def is_rejected( attributes )
|
|
27
|
+
attributes['name'].blank?
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
module Binda
|
|
2
|
+
class User < ApplicationRecord
|
|
3
|
+
# Include default devise modules. Others available are:
|
|
4
|
+
# :confirmable, :lockable, :timeoutable and :omniauthable
|
|
5
|
+
devise :database_authenticatable, :registerable,
|
|
6
|
+
:recoverable, :rememberable, :trackable, :validatable
|
|
7
|
+
end
|
|
8
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
module Binda
|
|
2
|
+
class Asset::ImageUploader < CarrierWave::Uploader::Base
|
|
3
|
+
|
|
4
|
+
# Include RMagick or MiniMagick support:
|
|
5
|
+
# include CarrierWave::RMagick
|
|
6
|
+
include CarrierWave::MiniMagick
|
|
7
|
+
|
|
8
|
+
# Choose what kind of storage to use for this uploader:
|
|
9
|
+
# storage :file
|
|
10
|
+
# storage :fog
|
|
11
|
+
|
|
12
|
+
# Override the directory where uploaded files will be stored.
|
|
13
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
|
14
|
+
def store_dir
|
|
15
|
+
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# https://github.com/carrierwaveuploader/carrierwave/wiki/How-to%3A-Make-Carrierwave-work-on-Heroku
|
|
19
|
+
def cache_dir
|
|
20
|
+
"#{Rails.root}/tmp/uploads"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Provide a default URL as a default if there hasn't been a file uploaded:
|
|
24
|
+
# def default_url
|
|
25
|
+
# # For Rails 3.1+ asset pipeline compatibility:
|
|
26
|
+
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
|
27
|
+
#
|
|
28
|
+
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
|
29
|
+
# end
|
|
30
|
+
|
|
31
|
+
# Process files as they are uploaded:
|
|
32
|
+
# process scale: [200, 300]
|
|
33
|
+
#
|
|
34
|
+
# def scale(width, height)
|
|
35
|
+
# # do something
|
|
36
|
+
# end
|
|
37
|
+
|
|
38
|
+
# Create different versions of your uploaded files:
|
|
39
|
+
# version :thumb do
|
|
40
|
+
# process resize_to_fit: [50, 50]
|
|
41
|
+
# end
|
|
42
|
+
|
|
43
|
+
# ========== IMPORTANT ===========
|
|
44
|
+
# If you change this remember to change the methods on app/models/binda/component.rb
|
|
45
|
+
|
|
46
|
+
version :thumb do
|
|
47
|
+
process resize_to_fit: [200, 200]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
version :medium do
|
|
51
|
+
process resize_to_fit: [700, 700]
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
version :large do
|
|
55
|
+
process resize_to_fit: [1400, 1400]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# ================================
|
|
59
|
+
|
|
60
|
+
# Add a white list of extensions which are allowed to be uploaded.
|
|
61
|
+
# For images you might use something like this:
|
|
62
|
+
# def extension_whitelist
|
|
63
|
+
# %w(jpg jpeg gif png)
|
|
64
|
+
# end
|
|
65
|
+
def content_type_whitelist
|
|
66
|
+
/image\//
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Override the filename of the uploaded files:
|
|
70
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
|
71
|
+
# def filename
|
|
72
|
+
# "something.jpg" if original_filename
|
|
73
|
+
# end
|
|
74
|
+
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<%= form_for(asset) do |f| %>
|
|
2
|
+
<% if asset.errors.any? %>
|
|
3
|
+
<div id="error_explanation">
|
|
4
|
+
<h2><%= pluralize(asset.errors.count, "error") %> prohibited this asset from being saved:</h2>
|
|
5
|
+
|
|
6
|
+
<ul>
|
|
7
|
+
<% asset.errors.full_messages.each do |message| %>
|
|
8
|
+
<li><%= message %></li>
|
|
9
|
+
<% end %>
|
|
10
|
+
</ul>
|
|
11
|
+
</div>
|
|
12
|
+
<% end %>
|
|
13
|
+
|
|
14
|
+
<div class="field">
|
|
15
|
+
<%= f.label :image %>
|
|
16
|
+
<%= f.text_field :image %>
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
<div class="actions">
|
|
20
|
+
<%= f.submit %>
|
|
21
|
+
</div>
|
|
22
|
+
<% end %>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
|
2
|
+
|
|
3
|
+
<h1>Assets</h1>
|
|
4
|
+
|
|
5
|
+
<table>
|
|
6
|
+
<thead>
|
|
7
|
+
<tr>
|
|
8
|
+
<th>Title</th>
|
|
9
|
+
<th>Image</th>
|
|
10
|
+
<th>Slug</th>
|
|
11
|
+
<th colspan="3"></th>
|
|
12
|
+
</tr>
|
|
13
|
+
</thead>
|
|
14
|
+
|
|
15
|
+
<tbody>
|
|
16
|
+
<% @assets.each do |asset| %>
|
|
17
|
+
<tr>
|
|
18
|
+
<td><%= asset.image %></td>
|
|
19
|
+
<td><%= link_to 'Show', asset %></td>
|
|
20
|
+
<td><%= link_to 'Edit', edit_asset_path(asset) %></td>
|
|
21
|
+
<td><%= link_to 'Destroy', asset, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
|
22
|
+
</tr>
|
|
23
|
+
<% end %>
|
|
24
|
+
</tbody>
|
|
25
|
+
</table>
|
|
26
|
+
|
|
27
|
+
<br>
|
|
28
|
+
|
|
29
|
+
<%= link_to 'New Asset', new_asset_path %>
|