active_content 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 54dd08b5ee40815a48b44705c2b9bd79186b6c3be077a5631da9c6fd1d976d1f
4
- data.tar.gz: '00259475624098116bd05bf7609eb9e83566c7b1d6ba88efcb8f2644dead8abb'
3
+ metadata.gz: 5921c69275718cf8e771e0ae70f219db54c293c285f4447f1f4405c77cda9fff
4
+ data.tar.gz: 244d5a04bd03d11214eacdc3dba57a9777364b0e65c308dce0993b3b039ab91b
5
5
  SHA512:
6
- metadata.gz: 071d74c8c0106b0915ee5906fe6ac6601670db09db01c52eef2eba30140348f34d48ed98c5e1270f7b6ce90b6fe2c31031ef2975cf33dc917355d53bc971b5d7
7
- data.tar.gz: b8b9341b078962dbfcff04eef8c2a156ba67150a84996452b43283d3cc20f49e6e64deb413e69c38641288a939451a4d7e64749b08450e70598aba367a4b9b28
6
+ metadata.gz: 0c887059448f2a4efb5feb62f23abd020f40cc671a7c0c06894b94d0e946e1657a6c61a02406c94d42d591797d8b0f3671bda89e1ace8166c462259a438ce379
7
+ data.tar.gz: c0aaf3033d63ea2b5480a046a1b587a165b2f1ca7f9aa3d6666bbbc75d5325d18bec31e139810e8ee66bc9a3ef4bbbf864189b1abe60633bfb6cd788978f4250
data/README.md CHANGED
@@ -32,12 +32,8 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
32
32
 
33
33
  ## Contributing
34
34
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/hardpixel/active-content. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hardpixel/active-content.
36
36
 
37
37
  ## License
38
38
 
39
39
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
40
-
41
- ## Code of Conduct
42
-
43
- Everyone interacting in the ActiveContent project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hardpixel/active-content/blob/master/CODE_OF_CONDUCT.md).
@@ -1,13 +1,23 @@
1
1
  require 'active_support'
2
+ require 'active_record'
2
3
  require 'ancestry'
3
4
  require 'enumerize'
4
5
  require 'carrierwave'
5
6
  require 'active_delegate'
7
+ require 'active_content/config'
6
8
  require 'active_content/version'
7
9
 
8
10
  module ActiveContent
9
11
  extend ActiveSupport::Concern
10
12
 
13
+ mattr_accessor :config
14
+
15
+ @@config = Config.new
16
+
17
+ def self.setup
18
+ yield config
19
+ end
20
+
11
21
  autoload :Taxonomizable, 'active_content/taxonomizable'
12
22
  autoload :Templatable, 'active_content/templatable'
13
23
  autoload :Uploadable, 'active_content/uploadable'
@@ -4,7 +4,7 @@ module ActiveContent
4
4
 
5
5
  class_methods do
6
6
  def has_attachment(name, field, options={})
7
- assoc_opts = { as: :attachable, class_name: 'ActiveContent::Attachment', autosave: true, dependent: :destroy }
7
+ assoc_opts = { as: :attachable, class_name: ActiveContent.config.attachment_class_name, autosave: true, dependent: :destroy }
8
8
  assoc_proc = -> { where field: field }
9
9
 
10
10
  multiple = options.delete(:multiple)
@@ -0,0 +1,16 @@
1
+ module ActiveContent
2
+ class Config
3
+ include ActiveSupport::Configurable
4
+
5
+ config_accessor(:metum_class_name) { 'ActiveContent::Metum' }
6
+ config_accessor(:profile_class_name) { 'ActiveContent::Profile' }
7
+ config_accessor(:template_class_name) { 'ActiveContent::Template' }
8
+ config_accessor(:relation_class_name) { 'ActiveContent::Relation' }
9
+ config_accessor(:attachment_class_name) { 'ActiveContent::Attachment' }
10
+ config_accessor(:taxonomization_class_name) { 'ActiveContent::Taxonomization' }
11
+
12
+ config_accessor(:profile_image_uploader)
13
+ config_accessor(:profile_locale_accessors)
14
+ config_accessor(:metum_locale_accessors)
15
+ end
16
+ end
@@ -6,9 +6,9 @@ module ActiveContent
6
6
  def has_meta(field, cast_type, options={})
7
7
  include ActiveDelegate
8
8
 
9
- assoc_opts = { as: :metable, class_name: 'ActiveContent::Metum', autosave: true, dependent: :destroy }
9
+ assoc_opts = { as: :metable, class_name: ActiveContent.config.metum_class_name, autosave: true, dependent: :destroy }
10
10
  assoc_proc = -> { where field: field }
11
- value_opts = options.merge(to: :"#{field}_metum", prefix: field, alias: field, cast: true)
11
+ value_opts = options.merge(to: :"#{field}_metum", prefix: field, alias: field, cast: true, localized: ActiveContent.config.metum_locale_accessors)
12
12
 
13
13
  has_one :"#{field}_metum", assoc_proc, assoc_opts
14
14
  delegate_attribute :value, cast_type, value_opts
@@ -1,8 +1,6 @@
1
1
  class ActiveContent::Attachment < ActiveRecord::Base
2
- # Set table name
3
2
  self.table_name = 'attachments'
4
3
 
5
- # Belongs associations
6
4
  belongs_to :upload
7
5
  belongs_to :attachable, polymorphic: true, optional: true
8
6
  end
@@ -1,7 +1,5 @@
1
1
  class ActiveContent::Content < ActiveRecord::Base
2
- # Set table name
3
2
  self.table_name = 'contents'
4
3
 
5
- # Define validations
6
4
  validates :title, presence: true
7
5
  end
@@ -1,7 +1,5 @@
1
1
  class ActiveContent::Metum < ActiveRecord::Base
2
- # Set table name
3
2
  self.table_name = 'meta'
4
3
 
5
- # Belongs associations
6
4
  belongs_to :metable, polymorphic: true, optional: true
7
5
  end
@@ -1,14 +1,10 @@
1
1
  class ActiveContent::Profile < ActiveRecord::Base
2
- # Define class attributes
3
2
  class_attribute :image_uploaders
4
3
 
5
- # Set table name
6
4
  self.table_name = 'profiles'
7
5
 
8
- # Belongs associations
9
6
  belongs_to :profileable, polymorphic: true, optional: true
10
7
 
11
- # Pick correct uploader after initialize for profileable class
12
8
  after_initialize do
13
9
  unless profileable.nil?
14
10
  class_name = :"#{profileable.class.name.underscore}_image"
@@ -22,25 +18,23 @@ class ActiveContent::Profile < ActiveRecord::Base
22
18
  end
23
19
  end
24
20
 
25
- # Build new image uploader class
26
21
  def self.build_image_uploader(assoc_name, uploader_class)
27
- if uploader_class
28
- uploader = Class.new(uploader_class)
29
- const_set("#{assoc_name}#{uploader_class}", uploader)
22
+ return unless uploader_class
30
23
 
31
- uploader.class_eval do
32
- alias :original_model :model
24
+ uploader = Class.new(uploader_class)
25
+ const_set("#{assoc_name}#{uploader_class}", uploader)
33
26
 
34
- def model
35
- original_model.profileable
36
- end
37
- end
27
+ uploader.class_eval do
28
+ alias :original_model :model
38
29
 
39
- uploader
30
+ def model
31
+ original_model.profileable
32
+ end
40
33
  end
34
+
35
+ uploader
41
36
  end
42
37
 
43
- # Add uploader for a profilable class
44
38
  def self.add_image_uploader(assoc_name, uploader)
45
39
  self.image_uploaders ||= {}
46
40
  self.mount_uploader :image, build_image_uploader(assoc_name, uploader)
@@ -49,10 +43,7 @@ class ActiveContent::Profile < ActiveRecord::Base
49
43
  self.image_uploaders[class_name] = self.uploaders[:image]
50
44
  end
51
45
 
52
- # Name composed by first and last name
53
46
  def name
54
- if first_name or last_name
55
- "#{first_name} #{last_name}".strip
56
- end
47
+ "#{first_name} #{last_name}".strip if first_name || last_name
57
48
  end
58
49
  end
@@ -1,8 +1,6 @@
1
1
  class ActiveContent::Relation < ActiveRecord::Base
2
- # Set table name
3
2
  self.table_name = 'relations'
4
3
 
5
- # Belongs associations
6
4
  belongs_to :item, polymorphic: true, optional: true
7
5
  belongs_to :relatable, polymorphic: true, optional: true
8
6
  end
@@ -1,8 +1,6 @@
1
1
  class ActiveContent::Taxonomization < ActiveRecord::Base
2
- # Set table name
3
2
  self.table_name = 'taxonomizations'
4
3
 
5
- # Belongs associations
6
4
  belongs_to :taxonomy
7
5
  belongs_to :taxonomizable, polymorphic: true, optional: true
8
6
  end
@@ -1,10 +1,7 @@
1
1
  class ActiveContent::Taxonomy < ActiveRecord::Base
2
- # Set table name
3
2
  self.table_name = 'taxonomies'
4
3
 
5
- # Define validations
6
4
  validates :name, presence: true
7
5
 
8
- # Has associations
9
6
  has_many :taxonomizations
10
7
  end
@@ -1,12 +1,15 @@
1
1
  class ActiveContent::Template < ActiveRecord::Base
2
- # Set table name
3
2
  self.table_name = 'templates'
4
3
 
5
- # Belongs associations
6
4
  belongs_to :templatable, polymorphic: true, optional: true
7
5
 
8
- # Redefine name reader
9
6
  def name
10
- super.nil? ? super : ActiveSupport::StringInquirer.new(super)
7
+ ActiveSupport::StringInquirer.new(super || default_template || 'default')
8
+ end
9
+
10
+ private
11
+
12
+ def default_template
13
+ templatable.class.template.default_value if templatable.present?
11
14
  end
12
15
  end
@@ -1,10 +1,7 @@
1
1
  class ActiveContent::Upload < ActiveRecord::Base
2
- # Set table name
3
2
  self.table_name = 'uploads'
4
3
 
5
- # Mount carrierwave uploader
6
4
  has_uploader
7
5
 
8
- # Define validations
9
6
  validates :file, presence: true
10
7
  end
@@ -6,11 +6,11 @@ module ActiveContent
6
6
  def has_profile(options={})
7
7
  include ActiveDelegate
8
8
 
9
- assoc_class = options.delete(:class_name) || 'ActiveContent::Profile'
10
- image_uploader = options.delete(:uploader)
9
+ assoc_class = options.delete(:class_name) || ActiveContent.config.profile_class_name
10
+ image_uploader = options.delete(:uploader) || ActiveContent.config.profile_image_uploader
11
11
 
12
12
  has_one :profile, as: :profileable, class_name: assoc_class, autosave: true, dependent: :destroy
13
- delegate_attributes options.except(:to).merge(to: :profile, allow_nil: true)
13
+ delegate_attributes options.except(:to).merge(to: :profile, allow_nil: true, localized: ActiveContent.config.profile_locale_accessors)
14
14
 
15
15
  ActiveContent::Profile.add_image_uploader name, image_uploader
16
16
 
@@ -5,7 +5,7 @@ module ActiveContent
5
5
  class_methods do
6
6
  def has_related(name, field, options={})
7
7
  assoc_type = "#{name}".classify.constantize.base_class.to_s
8
- assoc_opts = { as: :relatable, class_name: 'ActiveContent::Relation', autosave: true, dependent: :destroy }
8
+ assoc_opts = { as: :relatable, class_name: ActiveContent.config.relation_class_name, autosave: true, dependent: :destroy }
9
9
  assoc_proc = -> { where field: field }
10
10
 
11
11
  default = options.delete(:default)
@@ -6,7 +6,7 @@ module ActiveContent
6
6
  def has_taxonomy(name, options={})
7
7
  options = options.reverse_merge(class_name: "#{name}".classify, source: :taxonomy)
8
8
  options = options.merge(through: :"#{name}_taxonomizations")
9
- setting = { as: :taxonomizable, class_name: 'ActiveContent::Taxonomization', autosave: true, dependent: :destroy }
9
+ setting = { as: :taxonomizable, class_name: ActiveContent.config.taxonomization_class_name, autosave: true, dependent: :destroy }
10
10
 
11
11
  has_many options[:through], -> { where field: "#{name}".downcase }, setting
12
12
  has_many name, options
@@ -13,7 +13,7 @@ module ActiveContent
13
13
 
14
14
  enumerize :template, in: templates, predicates: { prefix: true }, default: default
15
15
 
16
- has_one :view_template, as: :templatable, class_name: 'ActiveContent::Template', autosave: true, dependent: :destroy
16
+ has_one :view_template, as: :templatable, class_name: ActiveContent.config.template_class_name, autosave: true, dependent: :destroy
17
17
  delegate_attribute :name, :string, to: :view_template, prefix: 'template', alias: :template, finder: true, scope: true
18
18
  end
19
19
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveContent
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -6,8 +6,7 @@ module ActiveContent
6
6
  class InstallGenerator < Rails::Generators::Base
7
7
  include Rails::Generators::Migration
8
8
 
9
- # Model names
10
- MODEL_NAMES = ['content', 'taxonomy', 'upload', 'template', 'relation', 'metum', 'profile'].freeze
9
+ MODEL_NAMES = ['content', 'taxonomy', 'upload', 'template', 'relation', 'metum', 'profile'].freeze
11
10
 
12
11
  desc 'Generates migrations to add CMS tables.'
13
12
  source_root File.expand_path('../templates', __FILE__)
@@ -15,32 +15,32 @@ module ActiveContent
15
15
 
16
16
  private
17
17
 
18
- def model_class
19
- name.camelize
20
- end
18
+ def model_class
19
+ name.camelize
20
+ end
21
21
 
22
- def type_class
23
- type.camelize
24
- end
22
+ def type_class
23
+ type.camelize
24
+ end
25
25
 
26
- def model_file
27
- "#{name.downcase.underscore}"
28
- end
26
+ def model_file
27
+ "#{name.downcase.underscore}"
28
+ end
29
29
 
30
- def model_meta
31
- args.map do |arg|
32
- field, cast_type, default = arg.split(':')
30
+ def model_meta
31
+ args.map do |arg|
32
+ field, cast_type, default = arg.split(':')
33
33
 
34
- items = [":#{field.to_sym}", ":#{cast_type.to_sym}"]
35
- items << ["default: #{value_type_cast(cast_type.to_sym, default)}"] if default.present?
34
+ items = [":#{field.to_sym}", ":#{cast_type.to_sym}"]
35
+ items << ["default: #{value_type_cast(cast_type.to_sym, default)}"] if default.present?
36
36
 
37
- items.join(', ')
38
- end
37
+ items.join(', ')
39
38
  end
39
+ end
40
40
 
41
- def value_type_cast(cast_type, value)
42
- strings = [:string, :date, :datetime, :time]
43
- cast_type.in?(strings) ? "'#{value}'" : value
44
- end
41
+ def value_type_cast(cast_type, value)
42
+ strings = [:string, :date, :datetime, :time]
43
+ cast_type.in?(strings) ? "'#{value}'" : value
44
+ end
45
45
  end
46
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_content
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Olibia Tsati
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-07-19 00:00:00.000000000 Z
12
+ date: 2020-03-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '0.1'
34
+ version: '1.0'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '0.1'
41
+ version: '1.0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: ancestry
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -101,14 +101,14 @@ dependencies:
101
101
  requirements:
102
102
  - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: '10.0'
104
+ version: '13.0'
105
105
  type: :development
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
- version: '10.0'
111
+ version: '13.0'
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: minitest
114
114
  requirement: !ruby/object:Gem::Requirement
@@ -131,13 +131,13 @@ executables: []
131
131
  extensions: []
132
132
  extra_rdoc_files: []
133
133
  files:
134
- - CODE_OF_CONDUCT.md
135
134
  - Gemfile
136
135
  - LICENSE.txt
137
136
  - README.md
138
137
  - Rakefile
139
138
  - lib/active_content.rb
140
139
  - lib/active_content/attachable.rb
140
+ - lib/active_content/config.rb
141
141
  - lib/active_content/metable.rb
142
142
  - lib/active_content/models/attachment.rb
143
143
  - lib/active_content/models/content.rb
@@ -183,8 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
183
  - !ruby/object:Gem::Version
184
184
  version: '0'
185
185
  requirements: []
186
- rubyforge_project:
187
- rubygems_version: 2.7.7
186
+ rubygems_version: 3.0.6
188
187
  signing_key:
189
188
  specification_version: 4
190
189
  summary: STI ActiveRecord models for dynamic CMS models
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at olibia@hardpixel.eu. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/