rails_admin_cms 0.0.7 → 0.0.9

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
  SHA1:
3
- metadata.gz: cc83df591531fab36fe6ae31d019ef6b21c5619f
4
- data.tar.gz: 4af4e3c05fa7fa5c73b50f71931d43a7fa908285
3
+ metadata.gz: bf5853464f21749a2648751253c62546a51ccb93
4
+ data.tar.gz: 57179f31f7a558b898a255a64ad0b51fab8ceb00
5
5
  SHA512:
6
- metadata.gz: eaa33d3396a9fab4069fc6b76c6c8c7b6d118208342a86d59de150c068c56717c88f007da0db4f018ca062e2b4ab4e4fd8a927f014a40fbe81ccdbb51e6aa9bd
7
- data.tar.gz: eebcb2e4f4c0a78dc50d3000f13bf2ab2ce83078b24ab3079538517135e5e5989947697dc48851d1878655f5ac8651952a0b52593f6c084c8aaf20c25d5312a5
6
+ metadata.gz: d3ef20bac7f0ce1bde7fb9ab5012113e7c5de0429037bf73a2321a701c8a98025e7855d8ea48193f5b52f4757db47ca4d7d60cea7026e8280838c23854672ea8
7
+ data.tar.gz: 75ee89c13537b749efc125c3ab885f2f6bae8cfdf58de6c9bab08d755ca7df991e8e5068d93e1182b9e5e230e2c739a59da86f7155dfa8ac592cea9e8f00359c
data/README.md CHANGED
@@ -47,6 +47,19 @@ What's going on:
47
47
  1. `cms_link_to_edit_mode`
48
48
  1. `current_admin?`
49
49
 
50
+ ## Mailchimp
51
+
52
+ First, `mailchimp_api_key` and `mailchimp_list_id_en` (and `mailchimp_list_id_xx` where `xx` is the locale) need to be defined within `config/secrets.yml`.
53
+ Then, use the partial `app/views/cms/shared/_mailchimp.html.erb` to output the mailchimp form:
54
+
55
+ ```ruby
56
+ <%= render 'cms/shared/mailchimp' %>
57
+ ```
58
+
59
+ 1. Flash messages could be overriden by the keys `flash_messages.mailchimp.subscribe.(success|error)`.
60
+ 1. Input placeholder could be overriden by the key `simple_form.placeholders.mailchimp.email`.
61
+ 1. Input and submit button are wrapper in a div tag with the class `cms-mailchimp`.
62
+
50
63
  ## TODO
51
64
 
52
65
  * Documentation
@@ -57,7 +70,6 @@ What's going on:
57
70
  * Link to image edit in edit form (for cropping)
58
71
  * Confirmation email for forms
59
72
  * Published Pages/Forms
60
- * Mailchimp integration
61
73
  * Redirector
62
74
  * Setting fetched from Yaml file
63
75
  * Pretty Url for Viewable::LinkPresenter#url as file_url
@@ -12,6 +12,7 @@ class CMS
12
12
  @ready =>
13
13
  @clear_event_handlers()
14
14
  @flash_messages()
15
+ @validate_mailchimp()
15
16
 
16
17
  @ready_with_scope 'cms-forms', =>
17
18
  @validate()
@@ -45,6 +46,9 @@ class CMS
45
46
  @validate: =>
46
47
  $.validate(validateOnBlur: false)
47
48
 
49
+ @validate_mailchimp: =>
50
+ $.validate(form: '#mailchimp_form', validateOnBlur: false)
51
+
48
52
  @with_scope_any: (body_classes..., handler) =>
49
53
  for body_class in body_classes
50
54
  if @with_scope(body_class, handler)
@@ -0,0 +1,24 @@
1
+ module CMS
2
+ class MailchimpController < RailsAdminCMS::Config.parent_controller
3
+ invisible_captcha only: [:subscribe]
4
+
5
+ def subscribe
6
+ respond_to do |format|
7
+ format.js do
8
+ begin
9
+ gb = Gibbon::API.new(Rails.application.secrets.mailchimp_api_key, { timeout: 15 })
10
+ gb.lists.subscribe(
11
+ id: Rails.application.secrets.send(:"mailchimp_list_id_#{I18n.locale}"),
12
+ email: { email: params[:mailchimp][:email] },
13
+ double_optin: false
14
+ )
15
+ flash_now!(:success)
16
+ rescue Gibbon::MailChimpError => exception
17
+ cms_logger exception, 'mailchimp'
18
+ flash_now!(:error)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,6 +1,6 @@
1
1
  module CMS
2
2
  class PagesController < RailsAdminCMS::Config.parent_controller
3
- after_action :allow_iframe, if: RailsAdminCMS::Config.allow_iframe_from
3
+ after_action :allow_iframe
4
4
 
5
5
  def show
6
6
  @cms_view = Viewable::Page.find(params[:id]) if params[:id].present?
@@ -15,7 +15,9 @@ module CMS
15
15
  private
16
16
 
17
17
  def allow_iframe
18
- response.headers['X-FRAME-OPTIONS'] = RailsAdminCMS::Config.allow_iframe_from
18
+ if RailsAdminCMS::Config.allow_iframe_from.present?
19
+ response.headers['X-FRAME-OPTIONS'] = RailsAdminCMS::Config.allow_iframe_from
20
+ end
19
21
  end
20
22
  end
21
23
  end
@@ -2,6 +2,7 @@ module CMS
2
2
  class ViewablesController < RailsAdminCMS::Config.parent_controller
3
3
  before_action :authenticate_admin_user!
4
4
 
5
+ # used by the add viewable link
5
6
  def create
6
7
  current_count = UniqueKey.where(list_key_params).count
7
8
 
@@ -22,6 +23,7 @@ module CMS
22
23
  end
23
24
  end
24
25
 
26
+ # used by [data-js-cms-sortable] element to modify the viewable position within the list
25
27
  def update
26
28
  unique_key = UniqueKey.find(params[:id])
27
29
 
@@ -14,6 +14,7 @@ module CMS
14
14
 
15
15
  def render_500(exception = nil)
16
16
  cms_logger exception
17
+ self.response_body = nil # make sure that there is no DoubleRenderError
17
18
  render file: 'public/500.html', status: 500, layout: false
18
19
  end
19
20
  end
@@ -11,7 +11,7 @@ module CMS
11
11
  ::Naming::Viewable::Block.names.each do |type|
12
12
  define_cms_view_helper(type)
13
13
 
14
- define_method "cms_#{type}" do |name = 'cms', min = 1, max = nil| # max = FLOAT::INFINITY
14
+ define_method "cms_#{type}" do |name = 'cms', min = 1, max = nil|
15
15
  name, min, max = adjust_arguments(name, min, max)
16
16
 
17
17
  cms_block("#{type}/#{name}", min, max)
@@ -21,6 +21,11 @@ module CMS
21
21
  ::Naming::Viewable.names.each do |type|
22
22
  define_cms_view_helper(type)
23
23
 
24
+ # access a Viewable within the current context
25
+ # name(optional):
26
+ # min (optional): defines how many viewables are created by default
27
+ # max (optional): defines the limit of viewables that could added (must be greater than min)
28
+ # * if min = 1, then a single ViewablePresenter is returned, otherwise, a ViewablePresenterList is returned
24
29
  define_method "cms_#{type}" do |name = 'cms', min = 1, max = nil| # max = FLOAT::INFINITY
25
30
  name, min, max = adjust_arguments(name, min, max)
26
31
 
@@ -0,0 +1,15 @@
1
+ module Admin
2
+ module Viewable
3
+ module String
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ rails_admin do
8
+ visible false
9
+
10
+ field :string
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ module Viewable
2
+ class String < ActiveRecord::Base
3
+ include Viewable
4
+ include Admin::Viewable::String
5
+ end
6
+ end
@@ -0,0 +1 @@
1
+ <%= render 'cms/shared/flash_messages' %>
@@ -1,2 +1,2 @@
1
- CMS.element('cms-flash').replaceWith("<%= j cms_flash_messages %>");
1
+ CMS.data_js('cms-flash').replaceWith("<%= j cms_flash_messages %>");
2
2
  CMS.flash_messages();
@@ -0,0 +1,7 @@
1
+ <%= simple_form_for :mailchimp, url: main_app.mailchimp_url(format: :js), remote: true, html: { id: 'mailchimp_form' } do |f| %>
2
+ <%= invisible_captcha %>
3
+ <div class="cms-mailchimp">
4
+ <%= f.input :email, label: false, wrapper: false, input_html: cms_validate_email %>
5
+ <%= f.submit cms_form_send, cms_form_sending %>
6
+ </div>
7
+ <% end %>
@@ -18,6 +18,10 @@ en:
18
18
  # error: "Something went wrong. Please take a look at the form to see what went wrong."
19
19
  #
20
20
  # Add flash messages for controller actions:
21
+ mailchimp:
22
+ subscribe:
23
+ success: Thanks for subscribing to our newsletter.
24
+ error: Sorry, an error happened (you might already be subscribed or your email is not valid).
21
25
  # products:
22
26
  # create:
23
27
  # success: "This is a notification"
@@ -18,6 +18,10 @@ fr:
18
18
  # error: "Something went wrong. Please take a look at the form to see what went wrong."
19
19
  #
20
20
  # Add flash messages for controller actions:
21
+ mailchimp:
22
+ subscribe:
23
+ success: Merci pour votre inscription à notre infolettre.
24
+ error: Désolé, une erreur est survenue (vous êtes peut-être déjà inscrit, veuillez vérifier votre boîte de courriels).
21
25
  # products:
22
26
  # create:
23
27
  # success: "This is a notification"
@@ -0,0 +1,5 @@
1
+ en:
2
+ simple_form:
3
+ placeholders:
4
+ mailchimp:
5
+ email: Email address
@@ -0,0 +1,5 @@
1
+ fr:
2
+ simple_form:
3
+ placeholders:
4
+ mailchimp:
5
+ email: Entrez votre adresse courriel
data/config/routes.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  Rails.application.routes.draw do
2
2
  scope module: 'cms' do
3
+ post 'mailchimp/subscribe' => 'mailchimp#subscribe', format: true, constraints: { format: :js }, as: :mailchimp
4
+
3
5
  get 'viewables/new' => 'viewables#create', format: false, as: :new_viewable
4
6
  post 'viewables/edit' => 'viewables#update', format: true, constraints: { format: :js }, as: :edit_viewable
5
7
 
@@ -0,0 +1,9 @@
1
+ class CreateViewableString < ActiveRecord::Migration
2
+ def change
3
+ create_table :viewable_strings do |t|
4
+ t.string :string
5
+
6
+ t.timestamps null: false
7
+ end
8
+ end
9
+ end
@@ -8,18 +8,21 @@ module CMS
8
8
  rb_names(dirname)
9
9
  end
10
10
 
11
+ # list the ruby file names within a directory (ex.: used to get all viewable names)
11
12
  def rb_names(dirname)
12
13
  Dir["#{Rails.root}/#{dirname}/*.rb"].map do |name|
13
14
  File.basename(name).sub(/\.rb$/, '')
14
15
  end
15
16
  end
16
17
 
18
+ # list the html file names within a directory (ex.: used to get all page templates)
17
19
  def html_names(dirname)
18
20
  Dir["#{Rails.root}/#{dirname}/*.html.*"].map do |name|
19
21
  File.basename(name).sub(/\.html\..+$/, '').sub(/^_/, '')
20
22
  end
21
23
  end
22
24
 
25
+ # list the folder names within a directory (ex.: used to get all form models)
23
26
  def dir_names(dirname)
24
27
  Dir["#{Rails.root}/#{dirname}/*"].select{ |name|
25
28
  File.directory? name
@@ -1,3 +1,3 @@
1
1
  module RailsAdminCMS
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_admin_cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrice Lebel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-01 00:00:00.000000000 Z
11
+ date: 2016-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -392,6 +392,20 @@ dependencies:
392
392
  - - ">="
393
393
  - !ruby/object:Gem::Version
394
394
  version: 1.0.1
395
+ - !ruby/object:Gem::Dependency
396
+ name: gibbon
397
+ requirement: !ruby/object:Gem::Requirement
398
+ requirements:
399
+ - - "~>"
400
+ - !ruby/object:Gem::Version
401
+ version: '1.1'
402
+ type: :runtime
403
+ prerelease: false
404
+ version_requirements: !ruby/object:Gem::Requirement
405
+ requirements:
406
+ - - "~>"
407
+ - !ruby/object:Gem::Version
408
+ version: '1.1'
395
409
  - !ruby/object:Gem::Dependency
396
410
  name: paper_trail
397
411
  requirement: !ruby/object:Gem::Requirement
@@ -660,6 +674,7 @@ files:
660
674
  - app/controllers/cms/attachments_controller.rb
661
675
  - app/controllers/cms/files_controller.rb
662
676
  - app/controllers/cms/forms_controller.rb
677
+ - app/controllers/cms/mailchimp_controller.rb
663
678
  - app/controllers/cms/pages_controller.rb
664
679
  - app/controllers/cms/viewables_controller.rb
665
680
  - app/controllers/concerns/cms/editing.rb
@@ -688,6 +703,7 @@ files:
688
703
  - app/models/admin/viewable/link.rb
689
704
  - app/models/admin/viewable/page.rb
690
705
  - app/models/admin/viewable/select.rb
706
+ - app/models/admin/viewable/string.rb
691
707
  - app/models/admin/viewable/text.rb
692
708
  - app/models/callbacks/form/field_after_create.rb
693
709
  - app/models/callbacks/form/field_after_destroy.rb
@@ -723,6 +739,7 @@ files:
723
739
  - app/models/viewable/link.rb
724
740
  - app/models/viewable/page.rb
725
741
  - app/models/viewable/select.rb
742
+ - app/models/viewable/string.rb
726
743
  - app/models/viewable/text.rb
727
744
  - app/presenters/base_list_presenter.rb
728
745
  - app/presenters/base_presenter.rb
@@ -739,7 +756,9 @@ files:
739
756
  - app/presenters/viewable_list_presenter.rb
740
757
  - app/presenters/viewable_presenter.rb
741
758
  - app/views/cms/forms/create.js.erb
759
+ - app/views/cms/mailchimp/subscribe.js.erb
742
760
  - app/views/cms/shared/_flash_messages.js.erb
761
+ - app/views/cms/shared/_mailchimp.html.erb
743
762
  - app/views/cms/viewables/update.js.erb
744
763
  - app/views/layouts/rails_admin/_secondary_navigation.html.haml
745
764
  - config/initializers/assets.rb
@@ -750,6 +769,8 @@ files:
750
769
  - config/locales/flash.fr.yml
751
770
  - config/locales/routes.en.yml
752
771
  - config/locales/routes.fr.yml
772
+ - config/locales/simple_form.en.yml
773
+ - config/locales/simple_form.fr.yml
753
774
  - config/routes.rb
754
775
  - config/spring.rb
755
776
  - db/migrate/20150111082038_create_versions.rb
@@ -771,6 +792,7 @@ files:
771
792
  - db/migrate/20160102010317_create_form_field.rb
772
793
  - db/migrate/20160103120544_create_form_email.rb
773
794
  - db/migrate/20160111072418_add_cms_og_tags_settings.rb
795
+ - db/migrate/20160201181310_create_viewable_string.rb
774
796
  - lib/active_type/virtual_attributes_decorator.rb
775
797
  - lib/generators/cms/install/USAGE
776
798
  - lib/generators/cms/install/install_generator.rb