udongo 5.7.0 → 5.8.0

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: a533eec4e517a96747f4933567fc71892c76c25f
4
- data.tar.gz: bf6fe21d215d9f065081c836b344afffcf04b2da
3
+ metadata.gz: e012e2dccbe75d74ea00c84ab30ae20423be0be1
4
+ data.tar.gz: b7b476f535941b05b5b7d857f15819af1c5f2753
5
5
  SHA512:
6
- metadata.gz: 3334640c6d1adcaf63ba4133e1f7f1c3f32e5c0f646bf6a74630d13bdaeff8b7efd356a2c55e93376e34f1de3c1e2b4f4e48a306bda89b3fd79779cb02a718f9
7
- data.tar.gz: 4ae9622b209f8d27bb14c896a2c2f7603dad8db21a5dd39eef42102aee5424150b69a9dbbc66bfec39112f5a5bfa9c547de4beef0b9bb524702c53eb109be94a
6
+ metadata.gz: e1e04b226920a07f783df0bd889920bc137905ce349df750acd05f9b056462cf55addd1f357e6b966cb200a0b65cb6fe585a40a4d398572a751bd94d1be7e047
7
+ data.tar.gz: 90bed388b48beb7a0e1a19b44209558cfc01928b112490064f251dfade8204bbd2065995f6c612d96bf9c9a9362c9f7fd40204c5011e33df480a76df022ffaaa
@@ -0,0 +1,51 @@
1
+ class Backend::Content::Rows::PicturesController < Backend::BaseController
2
+ include Concerns::Backend::ContentTypeController
3
+ before_action :redirect_unless_has_asset, only: [:edit, :update]
4
+ before_action :redirect_if_has_asset, only: [:link_or_upload, :link, :upload]
5
+ before_action :prepare_upload, only: [:link_or_upload, :upload]
6
+
7
+ model ContentPicture
8
+ allowed_params :caption, :url
9
+
10
+ def link
11
+ @model.asset = Asset.find params[:asset_id]
12
+ @model.save!
13
+
14
+ redirect_to edit_backend_content_picture_path
15
+ end
16
+
17
+ def upload
18
+ @asset.filename = params[:asset][:filename]
19
+ @asset.description = params[:asset][:description]
20
+
21
+ if @asset.filename && @asset.filename.content_type.to_s.include?('image') && @asset.save
22
+ @model.asset = @asset
23
+ @model.save
24
+
25
+ redirect_to edit_backend_content_picture_path(@model)
26
+ else
27
+ @asset.errors.add :filename, t('b.msg.please_select_a_valid_image')
28
+ render :link_or_upload
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def redirect_unless_has_asset
35
+ unless @model.asset
36
+ redirect_to link_or_upload_backend_content_picture_path(@model)
37
+ end
38
+ end
39
+
40
+ def redirect_if_has_asset
41
+ if @model.asset
42
+ redirect_to edit_backend_content_picture_path(@model)
43
+ end
44
+ end
45
+
46
+ def prepare_upload
47
+ @asset = Asset.new
48
+ @search = Asset.ransack params[:q]
49
+ @assets = @search.result(distinct: true).image.where.not(id: @model.asset_id).order('id DESC')
50
+ end
51
+ end
@@ -1,7 +1,3 @@
1
1
  class ContentImageDecorator < ApplicationDecorator
2
2
  delegate_all
3
-
4
- def content_type_is?(value)
5
- value.to_sym == :image
6
- end
7
3
  end
@@ -0,0 +1,3 @@
1
+ class ContentPictureDecorator < ApplicationDecorator
2
+ delegate_all
3
+ end
@@ -4,8 +4,4 @@ class ContentTextDecorator < ApplicationDecorator
4
4
  def render
5
5
  content.to_s.html_safe
6
6
  end
7
-
8
- def content_type_is?(value)
9
- value.to_sym == :text
10
- end
11
7
  end
@@ -5,5 +5,11 @@ module Backend
5
5
  [I18n.t("b.msg.content_types.#{content_type}"), "Content#{content_type.to_s.camelcase}"]
6
6
  end
7
7
  end
8
+
9
+ def options_for_column_widths
10
+ (1..12).to_a.reverse.map do |i|
11
+ ["#{(i.to_f / 12.0 * 100).to_i}%", i]
12
+ end
13
+ end
8
14
  end
9
15
  end
data/app/models/asset.rb CHANGED
@@ -4,6 +4,7 @@ class Asset < ApplicationRecord
4
4
  mount_uploader :filename, AssetUploader
5
5
 
6
6
  has_many :images, dependent: :destroy
7
+ has_many :content_pictures, dependent: :destroy
7
8
 
8
9
  scope :image, -> { where(content_type: %w(image/gif image/jpeg image/png)) }
9
10
 
@@ -24,7 +25,7 @@ class Asset < ApplicationRecord
24
25
  end
25
26
 
26
27
  def deletable?
27
- images.empty?
28
+ images.empty? && content_pictures.empty?
28
29
  end
29
30
 
30
31
  private
@@ -13,5 +13,9 @@ module Concerns
13
13
  def parent
14
14
  column.row.rowable
15
15
  end
16
+
17
+ def content_type_is?(value)
18
+ value.to_sym == content_type.to_sym
19
+ end
16
20
  end
17
21
  end
@@ -93,7 +93,7 @@ module Concerns
93
93
  translatable_fields_list.each { |f| result << f }
94
94
  end
95
95
 
96
- result << :flexible_content if flexible_content?
96
+ result << :flexible_content if respond_to?(:flexible_content?)
97
97
  result
98
98
  end
99
99
  end
@@ -0,0 +1,9 @@
1
+ class ContentPicture < ApplicationRecord
2
+ include Concerns::ContentType
3
+
4
+ belongs_to :asset
5
+
6
+ def content_type
7
+ :picture
8
+ end
9
+ end
@@ -3,7 +3,7 @@
3
3
  <%= image_tag object.file.size_1024x640.url, alt: '', class: 'img-fluid' %>
4
4
 
5
5
  <% if object.caption.present? %>
6
- <div class="text-center">
6
+ <div class="text-xs-center">
7
7
  <%= object.caption.html_safe %>
8
8
  </div>
9
9
  <% end %>
@@ -0,0 +1,13 @@
1
+ <% if object.present? && object.asset.present? %>
2
+
3
+ <%= image_tag object.asset.image.url(1100, 1100, quality: 65), alt: '', class: 'img-fluid' %>
4
+
5
+ <% if object.caption.present? %>
6
+ <div class="text-xs-center">
7
+ <%= object.caption.html_safe %>
8
+ </div>
9
+ <% end %>
10
+
11
+ <% else %>
12
+ <%= t 'b.msg.flexible_content.no_picture_present' %>
13
+ <% end %>
@@ -1,3 +1,11 @@
1
1
  <% Udongo::Configs::FlexibleContent::BREAKPOINTS.each do |bp| %>
2
- <%= form.input "width_#{bp}", as: :integer, wrapper_html: { hidden: !Udongo.config.flexible_content.allowed_breakpoint?(bp) } %>
2
+ <%=
3
+ form.input(
4
+ "width_#{bp}",
5
+ as: :select,
6
+ collection: options_for_column_widths,
7
+ include_blank: false,
8
+ wrapper_html: { hidden: !Udongo.config.flexible_content.allowed_breakpoint?(bp) }
9
+ )
10
+ %>
3
11
  <% end %>
@@ -0,0 +1,10 @@
1
+ <%= search_form_for @search, url: link_or_upload_backend_content_picture_path(@model) do |f| %>
2
+ <div class="row m-b-2">
3
+ <div class="col-md-6">
4
+ <%= f.search_field :description_cont, placeholder: t('b.description'), class: 'form-control' %>
5
+ </div>
6
+ <div class="col-md-6">
7
+ <%= f.submit class: 'btn btn-sn' %>
8
+ </div>
9
+ </div>
10
+ <% end %>
@@ -0,0 +1,17 @@
1
+ <%= render 'backend/general_form_error', object: @model %>
2
+
3
+ <div class="card">
4
+ <div class="card-header">
5
+ <%= t 'b.msg.flexible_content.edit_picture' %>
6
+ </div>
7
+
8
+ <div class="card-block">
9
+ <%= image_tag @model.asset.image.url(1700, 1700, quality: 65), alt: '', class: 'img-fluid' %>
10
+
11
+ <%= simple_form_for [:backend, @model] do |f| %>
12
+ <%= f.input :url, as: :string %>
13
+ <%= f.input :caption, as: :text %>
14
+ <%= render 'backend/form_actions', cancel_url: content_path %>
15
+ <% end %>
16
+ </div>
17
+ </div>
@@ -0,0 +1,34 @@
1
+ <%= simple_form_for @asset, url: upload_backend_content_picture_path(@model) do |f| %>
2
+ <div class="card">
3
+ <div class="card-header">
4
+ <%= t 'b.upload_a_new_image' %>
5
+ </div>
6
+
7
+ <div class="card-block">
8
+ <%= f.input :filename, as: :file, label: false, required: false %>
9
+ <%= f.input :description, as: :text, required: false %>
10
+
11
+ <%= render 'backend/form_actions', cancel_url: content_path %>
12
+ </div>
13
+ </div>
14
+ <% end %>
15
+
16
+ <div class="card">
17
+ <div class="card-header">
18
+ <%= t 'b.choose_an_existing_image' %>
19
+ </div>
20
+
21
+ <div class="card-block">
22
+ <%= render 'filter' %>
23
+
24
+ <div class="row">
25
+ <% @assets.each do |a| %>
26
+ <div class="col-sm-6 col-md-4 col-lg-3 col-xl-2">
27
+ <%= link_to link_backend_content_picture_path(@model, asset_id: a.id), style: '' do %>
28
+ <%= image_tag a.image.url(550, 550, action: :resize_and_pad, background: :white), alt: '', class: 'img-fluid' %>
29
+ <% end %>
30
+ </div>
31
+ <% end %>
32
+ </div>
33
+ </div>
34
+ </div>
data/changelog.md CHANGED
@@ -1,8 +1,21 @@
1
+ 5.8.0 - 2017-04-12
2
+ --
3
+ * Add missing ```author``` key to form translations.
4
+ * The ContentImage/Text decorators have been simplified.
5
+ * Fixed bug where you couldn't include ```Concerns::Searchable``` on models
6
+ without flexible content without getting an unknown method error.
7
+ * The column widths for flexible content are displayed in percentages.
8
+ * An extra widget ```ContentPicture``` has been added. This is the replacement
9
+ for the ````ContentImage```` which has now been deprecated.
10
+
11
+
1
12
  5.7.0 - 2017-03-22
2
13
  --
3
14
  * The ```Navigation``` model now includes the cacheable concern.
4
15
  * A ```NavigationHelper``` module was added which makes it easier to fetch a
5
16
  navigation by identifier.
17
+ * You can now include ```Concerns::Searchable``` on models without flexible
18
+ content and not receive errors as a result.
6
19
 
7
20
 
8
21
  5.6.0 - 2017-03-18
@@ -98,7 +98,8 @@ en:
98
98
  changes_saved: The changes have been saved.
99
99
  confirm: Are you sure?
100
100
  content_types:
101
- image: Image
101
+ image: Image (deprecated!)
102
+ picture: Picture
102
103
  text: Text
103
104
  deleted: '%{actor} was deleted.'
104
105
  dirty_inputs_warning: "You are about to leave the page but your changes aren't saved yet.\nDo you still want to leave the page?"
@@ -110,8 +111,10 @@ en:
110
111
  delete_row: Delete row
111
112
  edit_column: Edit column
112
113
  edit_image: Edit image
114
+ edit_picture: Edit picture
113
115
  edit_text: Edit text
114
116
  explanation: With this module you can create flexible responsive content. Click the button below to create the first row.
117
+ no_picture_present: No picture has been uploaded/linked yet.
115
118
  forgot_password: Forgot password?
116
119
  general_form_error: Something went wrong. Please check the marked fields.
117
120
  help_texts:
@@ -14,6 +14,7 @@ en:
14
14
  labels:
15
15
  defaults:
16
16
  active: Active
17
+ author: Author
17
18
  bcc: BCC
18
19
  caption: Caption
19
20
  category: Category
@@ -98,7 +98,8 @@ nl:
98
98
  changes_saved: De wijzigingen werden opgeslagen.
99
99
  confirm: Ben je zeker?
100
100
  content_types:
101
- image: Afbeelding
101
+ image: Afbeelding (niet meer gebruiken!)
102
+ picture: Foto
102
103
  text: Tekst
103
104
  deleted: '%{actor} werd verwijderd.'
104
105
  dirty_inputs_warning: "Je gaat de pagina verlaten maar je aanpassingen zijn nog niet bewaard.\nWil je nog steeds de pagina verlaten?"
@@ -110,8 +111,10 @@ nl:
110
111
  delete_row: Rij verwijderen
111
112
  edit_column: Kolom bewerken
112
113
  edit_image: Afbeelding bewerken
114
+ edit_picture: Foto bewerken
113
115
  edit_text: Tekst bewerken
114
116
  explanation: Met deze module kan je flexibele, responsive inhoud toevoegen. Klik op onderstaande knop om een eerste rij toe te voegen.
117
+ no_picture_present: Er werd nog geen foto geüpload of gelinkt.
115
118
  forgot_password: Wachtwoord vergeten?
116
119
  general_form_error: Er trad een fout op. Controleer de gemarkeerde velden.
117
120
  help_texts:
@@ -14,6 +14,7 @@ nl:
14
14
  labels:
15
15
  defaults:
16
16
  active: Actief
17
+ author: Auteur
17
18
  bcc: BCC
18
19
  caption: Beschrijving
19
20
  category: Categorie
data/config/routes.rb CHANGED
@@ -83,8 +83,16 @@ Rails.application.routes.draw do
83
83
 
84
84
  scope module: 'rows' do
85
85
  Udongo.config.flexible_content.types.each do |content_type|
86
+ next if content_type == 'picture'
86
87
  resources content_type.to_s.pluralize.to_sym, only: [:edit, :update]
87
88
  end
89
+
90
+ resources :pictures, only: [:edit, :update] do
91
+ member do
92
+ get :link_or_upload, :link
93
+ post :upload
94
+ end
95
+ end
88
96
  end
89
97
  end
90
98
 
@@ -0,0 +1,11 @@
1
+ class CreateContentPictures < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :content_pictures do |t|
4
+ t.references :asset
5
+ t.text :caption
6
+ t.text :url
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -5,7 +5,7 @@ module Udongo
5
5
 
6
6
  BREAKPOINTS = %w(xs sm md lg xl)
7
7
 
8
- attribute :types, Array, default: %w(text image)
8
+ attribute :types, Array, default: %w(text picture image)
9
9
  attribute :allowed_breakpoints, Array, default: BREAKPOINTS
10
10
 
11
11
  def allowed_breakpoint?(value)
@@ -1,3 +1,3 @@
1
1
  module Udongo
2
- VERSION = '5.7.0'
2
+ VERSION = '5.8.0'
3
3
  end
data/readme.md CHANGED
@@ -116,7 +116,7 @@ You can also override the default message with your own:
116
116
  ## Flexible content
117
117
  ### types
118
118
  ```ruby
119
- Udongo.config.flexible_content.types = %w(text image)
119
+ Udongo.config.flexible_content.types = %w(text picture)
120
120
  ```
121
121
 
122
122
  ### allowed_breakpoints
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :content_picture do
3
+ asset
4
+ end
5
+ end
@@ -15,6 +15,6 @@ shared_examples_for :content_type do
15
15
  end
16
16
 
17
17
  it '#respond_to?' do
18
- expect(build(klass)).to respond_to(:column)
18
+ expect(build(klass)).to respond_to(:column, :parent, :content_type_is?)
19
19
  end
20
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: udongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.7.0
4
+ version: 5.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Davy Hellemans
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-03-22 00:00:00.000000000 Z
12
+ date: 2017-04-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -460,6 +460,7 @@ files:
460
460
  - app/controllers/backend/base_controller.rb
461
461
  - app/controllers/backend/content/rows/columns_controller.rb
462
462
  - app/controllers/backend/content/rows/images_controller.rb
463
+ - app/controllers/backend/content/rows/pictures_controller.rb
463
464
  - app/controllers/backend/content/rows/texts_controller.rb
464
465
  - app/controllers/backend/content/rows_controller.rb
465
466
  - app/controllers/backend/dashboard_controller.rb
@@ -486,6 +487,7 @@ files:
486
487
  - app/controllers/redirects_controller.rb
487
488
  - app/decorators/application_decorator.rb
488
489
  - app/decorators/content_image_decorator.rb
490
+ - app/decorators/content_picture_decorator.rb
489
491
  - app/decorators/content_row_decorator.rb
490
492
  - app/decorators/content_text_decorator.rb
491
493
  - app/decorators/navigation_item_decorator.rb
@@ -549,6 +551,7 @@ files:
549
551
  - app/models/concerns/visible.rb
550
552
  - app/models/content_column.rb
551
553
  - app/models/content_image.rb
554
+ - app/models/content_picture.rb
552
555
  - app/models/content_row.rb
553
556
  - app/models/content_text.rb
554
557
  - app/models/email.rb
@@ -602,12 +605,16 @@ files:
602
605
  - app/views/backend/assets/index.html.erb
603
606
  - app/views/backend/assets/new.html.erb
604
607
  - app/views/backend/content/_image.html.erb
608
+ - app/views/backend/content/_picture.html.erb
605
609
  - app/views/backend/content/_rows.html.erb
606
610
  - app/views/backend/content/_text.html.erb
607
611
  - app/views/backend/content/rows/columns/_dimension_fields.html.erb
608
612
  - app/views/backend/content/rows/columns/edit.html.erb
609
613
  - app/views/backend/content/rows/columns/new.html.erb
610
614
  - app/views/backend/content/rows/images/edit.html.erb
615
+ - app/views/backend/content/rows/pictures/_filter.html.erb
616
+ - app/views/backend/content/rows/pictures/edit.html.erb
617
+ - app/views/backend/content/rows/pictures/link_or_upload.html.erb
611
618
  - app/views/backend/content/rows/texts/edit.html.erb
612
619
  - app/views/backend/dashboard/show.html.erb
613
620
  - app/views/backend/email_templates/_form.html.erb
@@ -756,6 +763,7 @@ files:
756
763
  - db/migrate/20170228183831_create_images.rb
757
764
  - db/migrate/20170305125627_create_articles.rb
758
765
  - db/migrate/20170318184654_add_title_and_content_disabled_to_snippet.rb
766
+ - db/migrate/20170412074304_create_content_pictures.rb
759
767
  - lib/tasks/task_extras.rb
760
768
  - lib/tasks/udongo_tasks.rake
761
769
  - lib/udongo.rb
@@ -808,6 +816,7 @@ files:
808
816
  - spec/factories/comments.rb
809
817
  - spec/factories/content_columns.rb
810
818
  - spec/factories/content_images.rb
819
+ - spec/factories/content_pictures.rb
811
820
  - spec/factories/content_rows.rb
812
821
  - spec/factories/content_texts.rb
813
822
  - spec/factories/email_templates.rb