cortex-field_types-core 0.1.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a95a9760ef9da3d7c1767c6a28810d70335004b3
4
- data.tar.gz: 02caf09f710575ed84bca4449e1d3129cae981e5
3
+ metadata.gz: d622d2df75d0378b884c23ed38ceba18e7315008
4
+ data.tar.gz: 44912b2b9a88135affb847f794c426abeae9bfb5
5
5
  SHA512:
6
- metadata.gz: 3792d9e07408642ea4cccdba1da1ef34047de4f3f151dfaac33a78c2d508faecf04e1b50043fd0714d49b14d9e363e6cb8743cc4ae61ab0869963cdc2b3746b6
7
- data.tar.gz: ab26b2831a6b04bf2da4440d15c59b9b084622e1631864f2fca06fda8610b27b61bfe82ac74f3b66ae311bb633f5f8d42f3c56f8d06c3c1548fc02e1d5e9297b
6
+ metadata.gz: dea571f5593fd6d0b6693a117e8f5595d091a3a18229ba5d7a85d2c469f1afcc4668f39bae5d92dcaea656c862ce28dc31b94c26181e34cfee24a36618989117
7
+ data.tar.gz: a6219121d7eaf4996a2301334edcd70009518649dd5961cbaad08d563c5071fdb5d1d5a82fdf9ae46b41fb354f2c35a9954edc8242a5ebc0782cca8e774bb0de
@@ -0,0 +1,3 @@
1
+ = render_field_id
2
+ = render_label
3
+ = render_input
@@ -0,0 +1,19 @@
1
+ module FieldTypes
2
+ module Core
3
+ class AssetCell < FieldTypes::Core::Cell
4
+ def input
5
+ render
6
+ end
7
+
8
+ private
9
+
10
+ def render_label
11
+ @options[:form].label 'data[asset]', field.name
12
+ end
13
+
14
+ def render_input
15
+ @options[:form].file_field 'data[asset]'
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,84 @@
1
+ class AssetFieldType < FieldType
2
+ VALIDATION_TYPES = {
3
+ presence: :valid_presence_validation?,
4
+ size: :valid_size_validation?,
5
+ content_type: :valid_content_type_validation?
6
+ }.freeze
7
+
8
+ attr_accessor :asset_file_name,
9
+ :asset_content_type,
10
+ :asset_file_size,
11
+ :asset_updated_at,
12
+ :field_name
13
+
14
+ attr_reader :data, :validations
15
+
16
+ has_attached_file :asset
17
+ do_not_validate_attachment_file_type :asset
18
+
19
+ validates :asset, attachment_presence: true, if: :validate_presence?
20
+
21
+ def validations=(validations_hash)
22
+ @validations = validations_hash.deep_symbolize_keys
23
+ end
24
+
25
+ def data=(data_hash)
26
+ self.asset = data_hash.deep_symbolize_keys[:asset]
27
+ end
28
+
29
+ def acceptable_validations?
30
+ valid_types? && valid_options?
31
+ end
32
+
33
+ def field_item_as_indexed_json_for_field_type(field_item, options = {})
34
+ json = {}
35
+ json[mapping_field_name] = asset_file_name
36
+ json
37
+ end
38
+
39
+ def mapping
40
+ {name: mapping_field_name, type: :string, analyzer: :keyword}
41
+ end
42
+
43
+ private
44
+
45
+ def mapping_field_name
46
+ "#{field_name.parameterize('_')}_asset_file_name"
47
+ end
48
+
49
+ def valid_types?
50
+ validations.all? do |type, options|
51
+ VALIDATION_TYPES.include?(type.to_sym)
52
+ end
53
+ end
54
+
55
+ def valid_options?
56
+ validations.all? do |type, options|
57
+ self.send(VALIDATION_TYPES[type])
58
+ end
59
+ end
60
+
61
+ def validate_presence?
62
+ @validations.key? :presence
63
+ end
64
+
65
+ alias_method :valid_presence_validation?, :validate_presence?
66
+
67
+ def valid_size_validation?
68
+ begin
69
+ AttachmentSizeValidator.new(validations[:size].merge(attributes: :asset))
70
+ true
71
+ rescue ArgumentError, NoMethodError
72
+ false
73
+ end
74
+ end
75
+
76
+ def valid_content_type_validation?
77
+ begin
78
+ AttachmentContentTypeValidator.new(validations[:content_type].merge(attributes: :asset))
79
+ true
80
+ rescue ArgumentError, NoMethodError
81
+ false
82
+ end
83
+ end
84
+ end
@@ -7,7 +7,7 @@ class DateTimeFieldType < FieldType
7
7
  attr_reader :validations, :metadata
8
8
 
9
9
  validates :timestamp, presence: true, if: :validate_presence?
10
- validate :timestamp_is_allowed?
10
+ validate :timestamp_is_valid?
11
11
 
12
12
  def validations=(validations_hash)
13
13
  @validations = validations_hash.deep_symbolize_keys
@@ -41,13 +41,17 @@ class DateTimeFieldType < FieldType
41
41
  "#{field_name.parameterize('_')}_date_time"
42
42
  end
43
43
 
44
- def timestamp_is_allowed?
45
- begin
46
- DateTime.parse(@timestamp)
44
+ def timestamp_is_valid?
45
+ if @timestamp.nil?
47
46
  true
48
- rescue ArgumentError
49
- errors.add(:timestamp, 'must be a valid date')
50
- false
47
+ else
48
+ begin
49
+ DateTime.parse(@timestamp)
50
+ true
51
+ rescue ArgumentError
52
+ errors.add(:timestamp, 'must be a valid date')
53
+ false
54
+ end
51
55
  end
52
56
  end
53
57
 
@@ -1,7 +1,7 @@
1
1
  module Cortex
2
2
  module FieldTypes
3
3
  module Core
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.1'
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,30 @@
1
+ Bundler.require(:default, Rails.env)
2
+
3
+ namespace :cortex do
4
+ namespace :core do
5
+ namespace :db do
6
+ desc 'Re-Seeds (will wipe existing ContentTypes!) Cortex with Core Custom Content Seed Data'
7
+ task reseed: :environment do
8
+ Rake::Task['cortex:core:db:clear'].execute
9
+ Rake::Task['cortex:core:media:seed'].execute
10
+ Rake::Task['employer:blog:seed'].execute # TODO: Extract
11
+ end
12
+
13
+ desc 'Clear Existing Custom Content Data From DB'
14
+ task clear: :environment do
15
+ puts "Clearing ContentTypes..."
16
+ ContentType.destroy_all
17
+ puts "Clearing Fields..."
18
+ Field.destroy_all
19
+ puts "Clearing ContentItems..."
20
+ ContentItem.destroy_all
21
+ puts "Clearing FieldItems..."
22
+ FieldItem.destroy_all
23
+ puts "Clearing ContentableDecorators..."
24
+ ContentableDecorator.destroy_all
25
+ puts "Clearing Decorators..."
26
+ Decorator.destroy_all
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,165 @@
1
+ Bundler.require(:default, Rails.env)
2
+
3
+ namespace :cortex do
4
+ namespace :core do
5
+ namespace :media do
6
+ desc 'Seed Cortex Media ContentType and Fields'
7
+ task seed: :environment do
8
+ puts "Creating Media ContentType..."
9
+ media = ContentType.new({
10
+ name: "Media",
11
+ description: "Media for Cortex",
12
+ icon: "collections",
13
+ creator_id: 1,
14
+ contract_id: 1
15
+ })
16
+ media.save
17
+
18
+ puts "Creating Fields..."
19
+ media.fields.new(name: 'Asset', field_type: 'asset_field_type', order_position: 1, validations: { presence: true })
20
+ media.fields.new(name: 'Title', field_type: 'text_field_type', order_position: 2, validations: { presence: true })
21
+ media.fields.new(name: 'Description', field_type: 'text_field_type', order_position: 3, validations: { presence: true })
22
+ media.fields.new(name: 'Tags', field_type: 'tag_field_type', order_position: 4, validations: {})
23
+ media.fields.new(name: 'Expiration Date', field_type: 'date_time_field_type', order_position: 5, validations: {})
24
+ media.fields.new(name: 'Alt Tag', field_type: 'text_field_type', order_position: 6, validations: {})
25
+ media.save
26
+
27
+ puts "Creating Wizard Decorators..."
28
+ wizard_hash = {
29
+ "steps": [
30
+ {
31
+ "name": "Upload",
32
+ "heading": "First thing's first..",
33
+ "description": "Add your media asset.",
34
+ "columns": [
35
+ {
36
+ "grid_width": 12,
37
+ "fields": [
38
+ {
39
+ "id": media.fields[0].id
40
+ }
41
+ ]
42
+ }
43
+ ]
44
+ },
45
+ {
46
+ "name": "Metadata",
47
+ "heading": "Let's talk about your asset..",
48
+ "description": "Provide details and metadata that will enhance search or inform end-users.",
49
+ "columns": [
50
+ {
51
+ "grid_width": 12,
52
+ "fields": [
53
+ {
54
+ "id": media.fields[1].id
55
+ },
56
+ {
57
+ "id": media.fields[2].id
58
+ },
59
+ {
60
+ "id": media.fields[3].id
61
+ },
62
+ {
63
+ "id": media.fields[4].id
64
+ },
65
+ {
66
+ "id": media.fields[5].id
67
+ }
68
+ ]
69
+ }
70
+ ]
71
+ }
72
+ ]
73
+ }
74
+
75
+ media_wizard_decorator = Decorator.new(name: "Wizard", data: wizard_hash)
76
+ media_wizard_decorator.save
77
+
78
+ ContentableDecorator.create({
79
+ decorator_id: media_wizard_decorator.id,
80
+ contentable_id: media.id,
81
+ contentable_type: 'ContentType'
82
+ })
83
+
84
+ puts "Creating Index Decorators..."
85
+ index_hash = {
86
+ "columns":
87
+ [
88
+ {
89
+ "name": "Thumbnail",
90
+ "cells": [{
91
+ "field": {
92
+ "method": "author_image"
93
+ },
94
+ "display": {
95
+ "classes": [
96
+ "circular"
97
+ ]
98
+ }
99
+ }]
100
+ },
101
+ {
102
+ "name": "Creator",
103
+ "cells": [{
104
+ "field": {
105
+ "method": "author_image"
106
+ },
107
+ "display": {
108
+ "classes": [
109
+ "circular"
110
+ ]
111
+ }
112
+ }]
113
+ },
114
+ {
115
+ "name": "Details",
116
+ "cells": [
117
+ {
118
+ "field": {
119
+ "id": media.fields[0].id
120
+ },
121
+ "display": {
122
+ "classes": [
123
+ "bold",
124
+ "upcase"
125
+ ]
126
+ }
127
+ },
128
+ {
129
+ "field": {
130
+ "id": media.fields[1].id
131
+ }
132
+ }
133
+ ]
134
+ },
135
+ {
136
+ "name": "Tags",
137
+ "cells": [
138
+ {
139
+ "field": {
140
+ "id": media.fields[2].id
141
+ },
142
+ "display": {
143
+ "classes": [
144
+ "tag",
145
+ "rounded"
146
+ ]
147
+ }
148
+ }
149
+ ]
150
+ }
151
+ ]
152
+ }
153
+
154
+ media_index_decorator = Decorator.new(name: "Index", data: index_hash)
155
+ media_index_decorator.save
156
+
157
+ ContentableDecorator.create({
158
+ decorator_id: media_index_decorator.id,
159
+ contentable_id: media.id,
160
+ contentable_type: 'ContentType'
161
+ })
162
+ end
163
+ end
164
+ end
165
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cortex-field_types-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - CareerBuilder Employer Site & Content Products
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-16 00:00:00.000000000 Z
11
+ date: 2016-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -90,6 +90,8 @@ files:
90
90
  - LICENSE.md
91
91
  - README.md
92
92
  - Rakefile
93
+ - app/cells/field_types/core/asset/input.haml
94
+ - app/cells/field_types/core/asset_cell.rb
93
95
  - app/cells/field_types/core/boolean/checkbox.haml
94
96
  - app/cells/field_types/core/boolean/switch.haml
95
97
  - app/cells/field_types/core/boolean_cell.rb
@@ -108,6 +110,7 @@ files:
108
110
  - app/cells/field_types/core/tree_cell.rb
109
111
  - app/cells/field_types/core/user/dropdown.haml
110
112
  - app/cells/field_types/core/user_cell.rb
113
+ - app/models/asset_field_type.rb
111
114
  - app/models/boolean_field_type.rb
112
115
  - app/models/date_time_field_type.rb
113
116
  - app/models/tag_field_type.rb
@@ -117,7 +120,8 @@ files:
117
120
  - lib/cortex/field_types/core.rb
118
121
  - lib/cortex/field_types/core/engine.rb
119
122
  - lib/cortex/field_types/core/version.rb
120
- - lib/tasks/cortex/field_types/core_tasks.rake
123
+ - lib/tasks/cortex/core/db.rake
124
+ - lib/tasks/cortex/core/media.rake
121
125
  homepage: https://github.com/cortex-cms/cortex-field_types-core
122
126
  licenses:
123
127
  - Apache-2.0
@@ -138,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
142
  version: '0'
139
143
  requirements: []
140
144
  rubyforge_project:
141
- rubygems_version: 2.6.4
145
+ rubygems_version: 2.5.1
142
146
  signing_key:
143
147
  specification_version: 4
144
148
  summary: The combined set of Core FieldTypes for the Cortex CMS platform
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :cortex_field_types_core do
3
- # # Task goes here
4
- # end