active_content 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +10 -0
- data/lib/active_content.rb +42 -0
- data/lib/active_content/attachable.rb +35 -0
- data/lib/active_content/metable.rb +27 -0
- data/lib/active_content/models/attachment.rb +7 -0
- data/lib/active_content/models/content.rb +3 -0
- data/lib/active_content/models/metum.rb +6 -0
- data/lib/active_content/models/profile.rb +9 -0
- data/lib/active_content/models/relation.rb +7 -0
- data/lib/active_content/models/taxonomization.rb +7 -0
- data/lib/active_content/models/taxonomy.rb +3 -0
- data/lib/active_content/models/template.rb +11 -0
- data/lib/active_content/models/upload.rb +6 -0
- data/lib/active_content/profileable.rb +23 -0
- data/lib/active_content/relatable.rb +36 -0
- data/lib/active_content/taxonomizable.rb +42 -0
- data/lib/active_content/templatable.rb +34 -0
- data/lib/active_content/uploadable.rb +23 -0
- data/lib/active_content/version.rb +3 -0
- data/lib/generators/active_content/install_generator.rb +26 -0
- data/lib/generators/active_content/model_generator.rb +46 -0
- data/lib/generators/active_content/templates/content.rb +15 -0
- data/lib/generators/active_content/templates/metum.rb +13 -0
- data/lib/generators/active_content/templates/model.rb +5 -0
- data/lib/generators/active_content/templates/profile.rb +24 -0
- data/lib/generators/active_content/templates/relation.rb +13 -0
- data/lib/generators/active_content/templates/taxonomy.rb +23 -0
- data/lib/generators/active_content/templates/template.rb +12 -0
- data/lib/generators/active_content/templates/upload.rb +24 -0
- metadata +191 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e1514763e6708c791c73b89c1b7b845d4f635bcd
|
4
|
+
data.tar.gz: 2689c2be2f014ca5e74a08aaa3c7442d44ca572a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 07177b8ccad87382c536b6d1a9457b989c9f7d2ce3021ae7552e18f734491f690332e0a13aa74cc83ad2e88a7a5b5b22f286b7e5aa85b7d2ef18984678ccaf18
|
7
|
+
data.tar.gz: 197defa087e36083bf4df0142297221906dfdaf95ccea07e9f08607a0ab4b3d7b842f780857e4c69633855fbffc533cf49b966e88763995d7f4572616878fb2f
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
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/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Olibia Tsati
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# ActiveContent
|
2
|
+
|
3
|
+
Generates base inheritable models Content, Taxonomy, Upload, Meta, Profile and Template.
|
4
|
+
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/active_content.svg)](https://badge.fury.io/rb/active_content)
|
6
|
+
[![Build Status](https://travis-ci.org/hardpixel/active-content.svg?branch=master)](https://travis-ci.org/hardpixel/active-content)
|
7
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/e459d91f56445e525a3d/maintainability)](https://codeclimate.com/github/hardpixel/active-content/maintainability)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'active_content'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install active_content
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
TODO: Write usage instructions here
|
28
|
+
|
29
|
+
## Development
|
30
|
+
|
31
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`.
|
32
|
+
|
33
|
+
## Contributing
|
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.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
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).
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'ancestry'
|
3
|
+
require 'enumerize'
|
4
|
+
require 'carrierwave'
|
5
|
+
require 'active_delegate'
|
6
|
+
require 'active_content/version'
|
7
|
+
|
8
|
+
module ActiveContent
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
autoload :Taxonomizable, 'active_content/taxonomizable'
|
12
|
+
autoload :Templatable, 'active_content/templatable'
|
13
|
+
autoload :Uploadable, 'active_content/uploadable'
|
14
|
+
autoload :Attachable, 'active_content/attachable'
|
15
|
+
autoload :Relatable, 'active_content/relatable'
|
16
|
+
autoload :Metable, 'active_content/metable'
|
17
|
+
autoload :Profileable, 'active_content/profileable'
|
18
|
+
|
19
|
+
autoload :Attachment, 'active_content/models/attachment'
|
20
|
+
autoload :Content, 'active_content/models/content'
|
21
|
+
autoload :Metum, 'active_content/models/metum'
|
22
|
+
autoload :Profile, 'active_content/models/profile'
|
23
|
+
autoload :Relation, 'active_content/models/relation'
|
24
|
+
autoload :Taxonomization, 'active_content/models/taxonomization'
|
25
|
+
autoload :Taxonomy, 'active_content/models/taxonomy'
|
26
|
+
autoload :Template, 'active_content/models/template'
|
27
|
+
autoload :Upload, 'active_content/models/upload'
|
28
|
+
|
29
|
+
included do
|
30
|
+
include ActiveContent::Taxonomizable
|
31
|
+
include ActiveContent::Templatable
|
32
|
+
include ActiveContent::Uploadable
|
33
|
+
include ActiveContent::Attachable
|
34
|
+
include ActiveContent::Relatable
|
35
|
+
include ActiveContent::Metable
|
36
|
+
include ActiveContent::Profileable
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
ActiveSupport.on_load(:active_record) do
|
41
|
+
include ActiveContent
|
42
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module ActiveContent
|
2
|
+
module Attachable
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
class_methods do
|
6
|
+
def has_attachment(name, field, options={})
|
7
|
+
assoc_opts = { as: :attachable, class_name: 'ActiveContent::Attachment', autosave: true, dependent: :destroy }
|
8
|
+
assoc_proc = -> { where field: field }
|
9
|
+
|
10
|
+
multiple = options.delete(:multiple)
|
11
|
+
defaults = options.reverse_merge(class_name: "#{name}".classify, source: :upload)
|
12
|
+
|
13
|
+
if multiple
|
14
|
+
options = defaults.merge(through: :"#{field}_attachments")
|
15
|
+
|
16
|
+
has_many options[:through], assoc_proc, assoc_opts
|
17
|
+
has_many :"#{field}", options
|
18
|
+
else
|
19
|
+
options = defaults.merge(through: :"#{field}_attachment")
|
20
|
+
|
21
|
+
has_one options[:through], assoc_proc, assoc_opts
|
22
|
+
has_one :"#{field}", options
|
23
|
+
|
24
|
+
define_method :"#{field}_id" do
|
25
|
+
send(:"#{field}").try :id
|
26
|
+
end
|
27
|
+
|
28
|
+
define_method :"#{field}_id=" do |value|
|
29
|
+
send :"#{field}=", Upload.find_by_id(value)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ActiveContent
|
2
|
+
module Metable
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
class_methods do
|
6
|
+
def has_meta(field, cast_type, options={})
|
7
|
+
include ActiveDelegate
|
8
|
+
|
9
|
+
assoc_opts = { as: :metable, class_name: 'ActiveContent::Metum', autosave: true, dependent: :destroy }
|
10
|
+
assoc_proc = -> { where field: field }
|
11
|
+
value_opts = { to: :"#{field}_metum", prefix: field, alias: field, default: options[:default] }
|
12
|
+
|
13
|
+
has_one :"#{field}_metum", assoc_proc, assoc_opts
|
14
|
+
delegate_attribute :value, cast_type, value_opts
|
15
|
+
|
16
|
+
before_save do
|
17
|
+
current = send(field)
|
18
|
+
default = self.class.column_defaults["#{field}"]
|
19
|
+
|
20
|
+
if current.blank? or current == default
|
21
|
+
send :"#{field}_metum=", nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class ActiveContent::Template < ApplicationRecord
|
2
|
+
self.table_name = 'templates'
|
3
|
+
|
4
|
+
# Belongs associations
|
5
|
+
belongs_to :templatable, polymorphic: true, optional: true
|
6
|
+
|
7
|
+
# Redefine name reader
|
8
|
+
def name
|
9
|
+
super.nil? ? super : ActiveSupport::StringInquirer.new(super)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ActiveContent
|
2
|
+
module Profileable
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
class_methods do
|
6
|
+
def has_profile
|
7
|
+
include ActiveDelegate
|
8
|
+
|
9
|
+
has_one :profile, as: :profileable, class_name: 'ActiveContent::Profile', autosave: true, dependent: :destroy
|
10
|
+
delegate_attributes to: :profile, allow_nil: true
|
11
|
+
|
12
|
+
define_method :name do
|
13
|
+
"#{first_name} #{last_name}".strip
|
14
|
+
end
|
15
|
+
|
16
|
+
define_method :gravatar do |size=48, default='mm'|
|
17
|
+
hash = Digest::MD5::hexdigest(try(:email))
|
18
|
+
"https://www.gravatar.com/avatar/#{hash}?rating=PG&size=#{size}&default=#{default}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ActiveContent
|
2
|
+
module Relatable
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
class_methods do
|
6
|
+
def has_related(name, field, options={})
|
7
|
+
assoc_type = "#{name}".classify.constantize.base_class.to_s
|
8
|
+
assoc_opts = { as: :relatable, class_name: 'ActiveContent::Relation', autosave: true, dependent: :destroy }
|
9
|
+
assoc_proc = -> { where field: field }
|
10
|
+
|
11
|
+
multiple = options.delete(:multiple)
|
12
|
+
defaults = options.reverse_merge(class_name: "#{name}".classify, source: :item, source_type: assoc_type)
|
13
|
+
|
14
|
+
if multiple
|
15
|
+
options = defaults.merge(through: :"#{field}_relations")
|
16
|
+
|
17
|
+
has_many options[:through], assoc_proc, assoc_opts
|
18
|
+
has_many :"#{field}", options
|
19
|
+
else
|
20
|
+
options = defaults.merge(through: :"#{field}_relation")
|
21
|
+
|
22
|
+
has_one options[:through], assoc_proc, assoc_opts
|
23
|
+
has_one :"#{field}", options
|
24
|
+
|
25
|
+
define_method :"#{field}_id" do
|
26
|
+
send(:"#{field}").try :id
|
27
|
+
end
|
28
|
+
|
29
|
+
define_method :"#{field}_id=" do |value|
|
30
|
+
send :"#{field}=", "#{name}".classify.constantize.find_by_id(value)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module ActiveContent
|
2
|
+
module Taxonomizable
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
class_methods do
|
6
|
+
def has_taxonomy(name, options={})
|
7
|
+
options = options.reverse_merge(class_name: name.to_s.classify, source: :taxonomy)
|
8
|
+
options = options.merge(through: :"#{name}_taxonomizations")
|
9
|
+
setting = { as: :taxonomizable, class_name: 'ActiveContent::Taxonomization', autosave: true, dependent: :destroy }
|
10
|
+
|
11
|
+
has_many options[:through], setting
|
12
|
+
has_many name, options
|
13
|
+
|
14
|
+
define_method :"#{name}_list" do
|
15
|
+
self.send name
|
16
|
+
end
|
17
|
+
|
18
|
+
define_method :"#{name}_list=" do |names|
|
19
|
+
model = options[:class_name].classify.constantize
|
20
|
+
names = Array(names).map do |n|
|
21
|
+
model.find_by_name(n) || model.new(name: n)
|
22
|
+
end
|
23
|
+
|
24
|
+
self.send :"#{name}=", names
|
25
|
+
end
|
26
|
+
|
27
|
+
query = self.includes(name)
|
28
|
+
blank = { taxonomies: { id: nil } }
|
29
|
+
|
30
|
+
scope :"with_#{name}", -> (*ids) do
|
31
|
+
id = { taxonomies: { id: ids } }
|
32
|
+
ids.empty? ? query.where.not(blank) : query.where(id)
|
33
|
+
end
|
34
|
+
|
35
|
+
scope :"without_#{name}", -> (*ids) do
|
36
|
+
id = { taxonomies: { id: ids } }
|
37
|
+
ids.empty? ? query.where(blank) : query.where(blank).or(query.where.not(id))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ActiveContent
|
2
|
+
module Templatable
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
class_methods do
|
6
|
+
def has_templates(*templates)
|
7
|
+
extend Enumerize
|
8
|
+
include ActiveDelegate
|
9
|
+
|
10
|
+
enumerize :template, in: templates, predicates: { prefix: true }
|
11
|
+
|
12
|
+
has_one :view_template, as: :templatable, class_name: 'ActiveContent::Template', autosave: true, dependent: :destroy
|
13
|
+
delegate_attribute :name, :string, to: :view_template, prefix: 'template', alias: :template
|
14
|
+
|
15
|
+
before_save do
|
16
|
+
self.view_template = nil if template.blank?
|
17
|
+
end
|
18
|
+
|
19
|
+
query = self.includes(:view_template)
|
20
|
+
blank = { templates: { name: nil } }
|
21
|
+
|
22
|
+
scope :with_template, -> (*names) do
|
23
|
+
named = { templates: { name: names } }
|
24
|
+
names.empty? ? query.where.not(blank) : query.where(named)
|
25
|
+
end
|
26
|
+
|
27
|
+
scope :without_template, -> (*names) do
|
28
|
+
named = { templates: { name: names } }
|
29
|
+
names.empty? ? query.where(blank) : query.where(blank).or(query.where.not(named))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ActiveContent
|
2
|
+
module Uploadable
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
class_methods do
|
6
|
+
def has_uploader(name=nil)
|
7
|
+
mount_uploader :file, name
|
8
|
+
|
9
|
+
define_method :mime_type do
|
10
|
+
@mime_type ||= MIME::Types[file.content_type].first
|
11
|
+
end
|
12
|
+
|
13
|
+
before_save do
|
14
|
+
if file_identifier.present?
|
15
|
+
self.name = file_identifier.split('.').first.titleize unless name?
|
16
|
+
self.media_type = mime_type.media_type
|
17
|
+
self.sub_type = mime_type.sub_type
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
require 'rails/generators/active_record'
|
4
|
+
|
5
|
+
module ActiveContent
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
include Rails::Generators::Migration
|
8
|
+
|
9
|
+
# Model names
|
10
|
+
MODEL_NAMES = ['content', 'taxonomy', 'upload', 'template', 'relation', 'metum', 'profile'].freeze
|
11
|
+
|
12
|
+
desc 'Generates migrations to add CMS tables.'
|
13
|
+
source_root File.expand_path('../templates', __FILE__)
|
14
|
+
argument :models, type: :array, default: MODEL_NAMES, enum: MODEL_NAMES, desc: 'Add CMS models tables.'
|
15
|
+
|
16
|
+
def create_migration_file
|
17
|
+
models.each do |model|
|
18
|
+
migration_template "#{model}.rb", "db/migrate/create_#{model.pluralize}.rb"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.next_migration_number(dirname)
|
23
|
+
::ActiveRecord::Generators::Base.next_migration_number(dirname)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module ActiveContent
|
4
|
+
class ModelGenerator < Rails::Generators::Base
|
5
|
+
|
6
|
+
desc 'Generates a new ActiveContent class in models folder.'
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
|
9
|
+
argument :type, type: :string, required: true
|
10
|
+
argument :name, type: :string, required: true
|
11
|
+
|
12
|
+
def create_migration_file
|
13
|
+
template 'model.rb', "app/models/#{model_file}.rb"
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def model_class
|
19
|
+
name.camelize
|
20
|
+
end
|
21
|
+
|
22
|
+
def type_class
|
23
|
+
type.camelize
|
24
|
+
end
|
25
|
+
|
26
|
+
def model_file
|
27
|
+
"#{name.downcase.underscore}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def model_meta
|
31
|
+
args.map do |arg|
|
32
|
+
field, cast_type, default = arg.split(':')
|
33
|
+
|
34
|
+
items = [":#{field.to_sym}", ":#{cast_type.to_sym}"]
|
35
|
+
items << ["default: #{value_type_cast(cast_type.to_sym, default)}"] if default.present?
|
36
|
+
|
37
|
+
items.join(', ')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def value_type_cast(cast_type, value)
|
42
|
+
strings = [:string, :date, :datetime, :time]
|
43
|
+
cast_type.in?(strings) ? "'#{value}'" : value
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateContents < ActiveRecord::Migration[5.0]
|
2
|
+
def change
|
3
|
+
create_table :contents do |t|
|
4
|
+
t.string :type
|
5
|
+
t.string :title, null: false
|
6
|
+
t.text :content
|
7
|
+
t.text :excerpt
|
8
|
+
t.string :ancestry
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
|
13
|
+
add_index :contents, :ancestry
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateMeta < ActiveRecord::Migration[5.0]
|
2
|
+
def change
|
3
|
+
create_table :meta do |t|
|
4
|
+
t.string :field, null: false
|
5
|
+
t.text :value, null: false
|
6
|
+
t.references :metable, null: false, polymorphic: true, index: false
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
|
11
|
+
add_index :meta, [:metable_id, :metable_type, :field, :value], unique: true, name: :index_meta_on_metable_attribute
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class CreateProfiles < ActiveRecord::Migration[5.0]
|
2
|
+
def change
|
3
|
+
create_table :profiles do |t|
|
4
|
+
t.string :first_name
|
5
|
+
t.string :last_name
|
6
|
+
t.text :bio
|
7
|
+
t.string :website
|
8
|
+
t.string :phone
|
9
|
+
t.string :mobile
|
10
|
+
t.string :fax
|
11
|
+
t.string :address
|
12
|
+
t.string :city
|
13
|
+
t.string :province
|
14
|
+
t.string :country
|
15
|
+
t.string :postal_code
|
16
|
+
t.string :image
|
17
|
+
t.references :profileable, polymorphic: true, index: false
|
18
|
+
|
19
|
+
t.timestamps
|
20
|
+
end
|
21
|
+
|
22
|
+
add_index :profiles, [:profileable_type, :profileable_id], unique: true, name: :index_profiles_on_profilable_attribute
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateRelations < ActiveRecord::Migration[5.0]
|
2
|
+
def change
|
3
|
+
create_table :relations do |t|
|
4
|
+
t.string :field, null: false
|
5
|
+
t.references :item, null: false, polymorphic: true, index: false
|
6
|
+
t.references :relatable, null: false, polymorphic: true, index: false
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
|
11
|
+
add_index :relations, [:relatable_id, :relatable_type, :item_id, :item_type, :field], unique: true, name: :index_relations_on_relatable_attribute
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class CreateTaxonomies < ActiveRecord::Migration[5.0]
|
2
|
+
def change
|
3
|
+
create_table :taxonomies do |t|
|
4
|
+
t.string :type
|
5
|
+
t.string :name, null: false
|
6
|
+
t.text :description
|
7
|
+
t.string :ancestry
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
|
12
|
+
add_index :taxonomies, :ancestry
|
13
|
+
|
14
|
+
create_table :taxonomizations do |t|
|
15
|
+
t.references :taxonomy
|
16
|
+
t.references :taxonomizable, null: false, polymorphic: true, index: false
|
17
|
+
|
18
|
+
t.timestamps
|
19
|
+
end
|
20
|
+
|
21
|
+
add_index :taxonomizations, [:taxonomizable_id, :taxonomizable_type, :taxonomy_id], unique: true, name: :index_taxonomizations_on_taxonomizable_attribute
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class CreateTemplates < ActiveRecord::Migration[5.0]
|
2
|
+
def change
|
3
|
+
create_table :templates do |t|
|
4
|
+
t.string :name, null: false
|
5
|
+
t.references :templatable, null: false, polymorphic: true, index: false
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index :templates, [:templatable_id, :templatable_type, :name], unique: true, name: :index_templates_on_templatable_attribute
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class CreateUploads < ActiveRecord::Migration[5.0]
|
2
|
+
def change
|
3
|
+
create_table :uploads do |t|
|
4
|
+
t.string :type
|
5
|
+
t.string :file, null: false
|
6
|
+
t.string :name, null: false
|
7
|
+
t.text :description
|
8
|
+
t.string :media_type
|
9
|
+
t.string :sub_type
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
|
14
|
+
create_table :attachments do |t|
|
15
|
+
t.string :field
|
16
|
+
t.references :upload
|
17
|
+
t.references :attachable, null: false, polymorphic: true, index: false
|
18
|
+
|
19
|
+
t.timestamps
|
20
|
+
end
|
21
|
+
|
22
|
+
add_index :attachments, [:attachable_id, :attachable_type, :upload_id, :field], unique: true, name: :index_attachments_on_attachable_attribute
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_content
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Olibia Tsati
|
8
|
+
- Jonian Guveli
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2017-11-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activerecord
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '5.0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '5.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: active_delegate
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0.1'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0.1'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: ancestry
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: enumerize
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '2.1'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.1'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: carrierwave
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1.2'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '1.2'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: bundler
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '1.14'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '1.14'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rake
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '10.0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '10.0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: minitest
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - "~>"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '5.0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '5.0'
|
126
|
+
description: Generates base inheritable models Content, Taxonomy, Upload, Meta, Profile
|
127
|
+
and Template.
|
128
|
+
email:
|
129
|
+
- info@hardpixel.eu
|
130
|
+
executables: []
|
131
|
+
extensions: []
|
132
|
+
extra_rdoc_files: []
|
133
|
+
files:
|
134
|
+
- CODE_OF_CONDUCT.md
|
135
|
+
- Gemfile
|
136
|
+
- LICENSE.txt
|
137
|
+
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- lib/active_content.rb
|
140
|
+
- lib/active_content/attachable.rb
|
141
|
+
- lib/active_content/metable.rb
|
142
|
+
- lib/active_content/models/attachment.rb
|
143
|
+
- lib/active_content/models/content.rb
|
144
|
+
- lib/active_content/models/metum.rb
|
145
|
+
- lib/active_content/models/profile.rb
|
146
|
+
- lib/active_content/models/relation.rb
|
147
|
+
- lib/active_content/models/taxonomization.rb
|
148
|
+
- lib/active_content/models/taxonomy.rb
|
149
|
+
- lib/active_content/models/template.rb
|
150
|
+
- lib/active_content/models/upload.rb
|
151
|
+
- lib/active_content/profileable.rb
|
152
|
+
- lib/active_content/relatable.rb
|
153
|
+
- lib/active_content/taxonomizable.rb
|
154
|
+
- lib/active_content/templatable.rb
|
155
|
+
- lib/active_content/uploadable.rb
|
156
|
+
- lib/active_content/version.rb
|
157
|
+
- lib/generators/active_content/install_generator.rb
|
158
|
+
- lib/generators/active_content/model_generator.rb
|
159
|
+
- lib/generators/active_content/templates/content.rb
|
160
|
+
- lib/generators/active_content/templates/metum.rb
|
161
|
+
- lib/generators/active_content/templates/model.rb
|
162
|
+
- lib/generators/active_content/templates/profile.rb
|
163
|
+
- lib/generators/active_content/templates/relation.rb
|
164
|
+
- lib/generators/active_content/templates/taxonomy.rb
|
165
|
+
- lib/generators/active_content/templates/template.rb
|
166
|
+
- lib/generators/active_content/templates/upload.rb
|
167
|
+
homepage: https://github.com/hardpixel/active-content
|
168
|
+
licenses:
|
169
|
+
- MIT
|
170
|
+
metadata: {}
|
171
|
+
post_install_message:
|
172
|
+
rdoc_options: []
|
173
|
+
require_paths:
|
174
|
+
- lib
|
175
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
|
+
requirements:
|
182
|
+
- - ">="
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
version: '0'
|
185
|
+
requirements: []
|
186
|
+
rubyforge_project:
|
187
|
+
rubygems_version: 2.6.13
|
188
|
+
signing_key:
|
189
|
+
specification_version: 4
|
190
|
+
summary: STI ActiveRecord models for dynamic CMS models
|
191
|
+
test_files: []
|