Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
toastercup committed Sep 22, 2017
2 parents e2bd4bc + 164ded7 commit 3a09baf
Show file tree
Hide file tree
Showing 24 changed files with 166 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
@import 'variables/colors';
@import 'variables/typography';

@import 'components/tags-input';
@import 'components/thumbnail-placeholder';
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.bootstrap-tagsinput {
width: 100%;
border-radius: 0 !important;
border-top: none;
border-right: none;
border-left: none;
border-bottom: 1px solid $color-grey-light;
box-shadow: none;
}
.cortex-bootstrap .label {
border-radius: 0.75em;
font-weight: normal;
}

.cortex-bootstrap .label-info {
background-color: $color-grey;
}

.bootstrap-tagsinput .tag {
text-transform: uppercase;
}
2 changes: 1 addition & 1 deletion app/cells/plugins/core/asset_info/show.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- if asset_is_image?
.mdl-card__title
%h2.mdl-card__title-text
= image_tag(asset['versions']['original']['url'], style: 'max-height: 200px;')
= image_tag(asset['versions']['original']['url'], style: 'min-height: 50px; max-height: 200px;')
.mdl-card__supporting-text
%dl
%dt Original Filename
Expand Down
3 changes: 0 additions & 3 deletions app/cells/plugins/core/tree/checkboxes.haml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
= render_label
= render_tooltip unless @options[:tooltip].nil?

%p
Please select 1-2 Categories.

- @options[:metadata]["data"]["tree_array"].each do |node|
= render_field_id
= cell(Plugins::Core::CheckboxCell, nil, form: @options[:form], node: node, data: data).(:checkbox)
2 changes: 1 addition & 1 deletion app/models/asset_field_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def attacher
end

def host_alias
metadata[:storage][:host_alias] unless metadata[:storage][:host_alias].empty?
metadata&.[](:storage)&.[](:host_alias)
end

def versions_data
Expand Down
2 changes: 1 addition & 1 deletion app/models/author_field_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ def author_name_present
end

def validate_presence?
@validations.key? :presence
validations.key? :presence
end
end
2 changes: 1 addition & 1 deletion app/models/date_time_field_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ def timestamp_is_valid?
end

def validate_presence?
@validations.key? :presence
validations.key? :presence
end
end
8 changes: 4 additions & 4 deletions app/models/float_field_type.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class FloatFieldType < FieldType
attr_accessor :float

validates :float, presence: true, if: Proc.new { |float| validate_key(:presence) }
validates_numericality_of :float, unless: "float.nil?"
validate :less_than, if: Proc.new { |float| validate_key(:max) }
Expand All @@ -27,14 +27,14 @@ def mapping_field_name
end

def validate_key(key)
@validations.key? key
validations.key? key
end

def less_than
errors.add(:float, "must be less_than #{@validations[:max]}") if :float <= @validations[:max]
errors.add(:float, "must be less_than #{validations[:max]}") if :float <= validations[:max]
end

def greater_than
errors.add(:float, "must be greater_than #{@validations[:min]}") if :float >= @validations[:min]
errors.add(:float, "must be greater_than #{validations[:min]}") if :float >= validations[:min]
end
end
6 changes: 3 additions & 3 deletions app/models/integer_field_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ def mapping_field_name
end

def validate_key
@validations.key? key
validations.key? key
end

def less_than
errors.add(:integer, "must be less_than #{@validations[:max]}") if :integer <= @validations[:max]
errors.add(:integer, "must be less_than #{validations[:max]}") if :integer <= validations[:max]
end

def greater_than
errors.add(:integer, "must be greater_than #{@validations[:min]}") if :integer >= @validations[:min]
errors.add(:integer, "must be greater_than #{validations[:min]}") if :integer >= validations[:min]
end
end
2 changes: 1 addition & 1 deletion app/models/tag_field_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ def mapping_field_name
end

def validate_presence?
@validations.key? :presence
validations.key? :presence
end
end
6 changes: 3 additions & 3 deletions app/models/text_field_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ def text_unique
end

def validate_uniqueness?
@validations.key? :uniqueness
validations.key? :uniqueness
end

def validate_presence?
@validations.key? :presence
validations.key? :presence
end

def validate_length?
@validations.key? :length
validations.key? :length
end
end
10 changes: 5 additions & 5 deletions app/models/tree_field_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def mapping_field_name
end

def minimum
if !@values.nil? && @values[:values].length >= @validations[:minimum]
if !@values.nil? && @values[:values].length >= validations[:minimum]
true
else
errors.add(:minimum, "You have selected too few values.")
Expand All @@ -46,7 +46,7 @@ def minimum

def maximum
unless @values.nil?
if @values[:values].length <= @validations[:maximum]
if @values[:values].length <= validations[:maximum]
true
else
errors.add(:maximum, "You have selected too many values.")
Expand All @@ -56,14 +56,14 @@ def maximum
end

def validate_presence?
@validations.key? :presence
validations.key? :presence
end

def validate_minimum?
@validations.key? :minimum
validations.key? :minimum
end

def validate_maximum?
@validations.key? :maximum
validations.key? :maximum
end
end
2 changes: 1 addition & 1 deletion app/models/user_field_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ def valid_user_id?
end

def validate_presence?
@validations.key? :presence
validations.key? :presence
end
end
6 changes: 6 additions & 0 deletions app/transactions/concerns/update_tags.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module UpdateTags
extend ActiveSupport::Concern

included do
end
end
Empty file.
18 changes: 18 additions & 0 deletions app/transactions/get_field_tree_list_transaction.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class GetFieldTreeListTransaction < ApplicationTransaction
step :init
step :process

def init(input)
field = Field.find_by_id(input[:args]['field_id'])

field ? Right({ content_item: input[:content_item], field: field }) : Left(:not_found)
end

def process(input)
tree_array = input[:field].metadata['allowed_values']['data']['tree_array']
tree_values = input[:content_item].field_items.find {|field_item| field_item.field_id == input[:field].id}.data['values']

tree_list = tree_values.map {|value| tree_array.find {|node| node['id'] == value.to_i}['node']['name']}.join(',')
Right(tree_list)
end
end
7 changes: 7 additions & 0 deletions app/transactions/new_tag_field_item_transaction.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class NewTagFieldItemTransaction < ApplicationTransaction
step :process

def process(field_item)
Right(field_item)
end
end
7 changes: 7 additions & 0 deletions app/transactions/new_user_field_item_transaction.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class NewUserFieldItemTransaction < ApplicationTransaction
step :process

def process(field_item)
Right(field_item)
end
end
7 changes: 7 additions & 0 deletions app/transactions/update_tag_field_item_transaction.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class UpdateTagFieldItemTransaction < ApplicationTransaction
step :process

def process(field_item)
Right(field_item)
end
end
11 changes: 5 additions & 6 deletions app/uploaders/asset_uploader.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'image_processing/mini_magick'
require 'image_optim'

class AssetUploader < Shrine
include ImageProcessing::MiniMagick
include Imageable

plugin :determine_mime_type
plugin :store_dimensions
Expand All @@ -25,14 +27,15 @@ class AssetUploader < Shrine
end

process(:store) do |io, context|
# TODO: Perform image optimizations (build plugin), support versions without processors or formatters
# TODO: support versions without processors
context[:generated_hex] = SecureRandom.hex(8)
versions = { original: io.download }

if image?(io)
image_optim = image_optim_for(context[:config][:metadata][:image_optim_config])
versions.merge!(context[:config][:metadata][:versions].transform_values do |version|
processed_version = send("#{version[:process][:method]}!", io.download, *version[:process][:config].values)
convert!(processed_version, version[:format])
optimize_image!(processed_version, image_optim) # TODO: per-version image_optim_config
end)
end

Expand All @@ -48,8 +51,4 @@ def generate_location(io, context)

ERB.new(context[:config][:metadata][:path]).result(binding)
end

def image?(io)
MimeMagic.new(io.data['metadata']['mime_type']).mediatype == 'image'
end
end
30 changes: 30 additions & 0 deletions app/uploaders/concerns/imageable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module Imageable
extend ActiveSupport::Concern

included do
def image?(io)
MimeMagic.new(io.data['metadata']['mime_type']).mediatype == 'image'
end

def optimize_image!(image, image_optim)
pathname = image_optim.optimize_image!(image) # TODO: move to ActiveJob
pathname ? pathname.open : image
end

def image_optim_for(image_optim_config)
ImageOptim.new(process_image_optim_config(image_optim_config))
end

def process_image_optim_config(image_optim_config)
processed_image_optim_config = image_optim_config.merge(pngout: false, svgo: false, verbose: true, skip_missing_workers: false)
processed_image_optim_config.extend(Hashie::Extensions::DeepLocate)
quality_range_hashes = processed_image_optim_config.deep_locate -> (key, value, object) { key == :quality_range }
quality_range_hashes.each do |quality_range_hash|
quality_range_hash[:quality] = quality_range_hash[:quality_range][:begin]..quality_range_hash[:quality_range][:end]
quality_range_hash.delete(:quality_range)
end

processed_image_optim_config
end
end
end
8 changes: 5 additions & 3 deletions cortex-plugins-core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ Gem::Specification.new do |s|
s.add_dependency "cells", "~> 4.1"
s.add_dependency "cells-rails", "~> 0.0"
s.add_dependency "cells-haml", "~> 0.0"
s.add_dependency "jsonb_accessor", "~> 1.0.0.beta"
s.add_dependency "jsonb_accessor", "~> 1.0"

# AssetFieldType
s.add_dependency "shrine", "~> 2.6"
s.add_dependency "shrine", "~> 2.7"
s.add_dependency "mimemagic", "~> 0.3"
s.add_dependency "image_processing", "~> 0.4"
s.add_dependency "mini_magick", "~> 4.7"
s.add_dependency "mini_magick", "~> 4.8"
s.add_dependency "fastimage", "~> 2.1"
s.add_dependency "image_optim", "~> 0.25"
s.add_dependency "image_optim_pack", "~> 0.5"
end
2 changes: 1 addition & 1 deletion lib/cortex/plugins/core/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Cortex
module Plugins
module Core
VERSION = '0.12.4'
VERSION = '1.0.0'
end
end
end
Loading

0 comments on commit 3a09baf

Please sign in to comment.