beyond_canvas 0.12.0.pre → 0.13.0.pre

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
  SHA256:
3
- metadata.gz: a704eb8fc8c4b55d55948f72b6f694d67bac4c4fd668a3542f1c2e0a3826bfdb
4
- data.tar.gz: 9521ae434f1eeee686b9f3421a79057cf807ad854f881be29e2d8ccffceab5e1
3
+ metadata.gz: 81a4312a7836c6b4e45b70a2516f1b8cf1a81c2a5a147b84794f4b81ca91fca9
4
+ data.tar.gz: e6dfcf1d2ae33991106021e0d6118b6bf5048d34cdffd419226594ede89d7986
5
5
  SHA512:
6
- metadata.gz: bd1726b41d4a3e55a4704660b2056dad15a4ec191b35377bb4275b2396885fa1591dd4402f2ff21b29035ae61a4719d54d137ab509efcd04287a400674616f3a
7
- data.tar.gz: fa0bec465852750728d95e985a61797fde9625d38c771fe2a97f367475f8ffbfbeaff17bba23e12c30869b0c3583b6b7fb6f6eba57fe82a47eedf9a9f3aadc90
6
+ metadata.gz: 3c90f578bd17802c1822b26412bf5c41c2342b948162ade9d23b4c8591aef7e2ce96a8712d3f56bec21fb8388d18e4478412e0f310a728682193bd9714267050
7
+ data.tar.gz: 3af58493e12b49d298cbea416a668d1442d8c366ee8cea84df7a928f876f50625205118a51607dce44bd6061c459d9884bcdf5f49f3bb7c7261e6b9ee4bf85ef
data/README.md CHANGED
@@ -49,26 +49,7 @@
49
49
  $ rails g beyond_canvas:install
50
50
  ```
51
51
 
52
- This will generate `config/initializers/beyond_canvas.rb` file, used for general Beyond Canvas configuration
53
-
54
- ## Style Customization
55
-
56
- Beyond Canvas comes with _out-of-the-box_ styles to make your app look like as a Beyond integrated one. If you want to customize the gem styles, follow these instructions:
57
-
58
- 1. Run the custom style generator:
59
-
60
- ```bash
61
- $ rails g beyond_canvas:custom_styles
62
- ```
63
-
64
- This command will generate a file (`app/assets/stylesheets/_beyond_canvas_custom_styles.sass`) that contains all variables you can customize.
65
-
66
- 1. Import the custom styles **before** Beyond Canvas itself (to override the default styles) on `application.scss`:
67
-
68
- ```scss
69
- @import 'beyond_canvas_custom_styles'
70
- @import 'beyond_canvas'
71
- ```
52
+ This will generate `config/initializers/beyond_canvas.rb` file, used for general Beyond Canvas configuration. Read [this wiki entry](https://github.com/ePages-de/beyond_canvas/wiki/Initializer) to get more information about the different configuration options.
72
53
 
73
54
  ## Documentation
74
55
 
@@ -54,16 +54,16 @@ select
54
54
  &__text
55
55
  margin-left: 20px
56
56
  font-weight: 500
57
+ text-overflow: ellipsis
58
+ overflow: hidden
59
+ white-space: nowrap
60
+ max-width: 200px
57
61
 
58
62
  &__icon
59
63
  margin-right: 5px
60
64
  position: relative
61
65
  top: 1px
62
66
 
63
-
64
- // &__with-error
65
- // border-left: 2px solid $input-errors-color
66
-
67
67
  label.input__error
68
68
  +padding(5px 7px)
69
69
  +position(absolute, calc(100% + 8px) null null 0)
@@ -4,22 +4,6 @@ module BeyondCanvas
4
4
  class ApplicationController < ActionController::Base
5
5
  protect_from_forgery with: :exception
6
6
 
7
- include ::BeyondCanvas::LocaleManagement
8
-
9
- def update_locale
10
- cookies[:locale] = { value: app_locale_params[:locale], expires: 1.day.from_now }
11
- set_locale
12
-
13
- redirect_back(fallback_location: main_app.root_path)
14
- end
15
-
16
- private
17
-
18
- #
19
- # Strong parameters for locale switch
20
- #
21
- def app_locale_params
22
- params.require(:app).permit(:locale)
23
- end
7
+ include ::BeyondCanvas::StatusCodes
24
8
  end
25
9
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_dependency 'beyond_canvas/application_controller'
4
+
5
+ module BeyondCanvas
6
+ class SystemController < ApplicationController
7
+ include ::BeyondCanvas::LocaleManagement
8
+
9
+ def update_locale
10
+ cookies[:locale] = { value: system_locale_params[:locale], expires: 1.day.from_now }
11
+
12
+ redirect_back(fallback_location: main_app.root_path)
13
+ end
14
+
15
+ private
16
+
17
+ #
18
+ # Strong parameters for locale switch
19
+ #
20
+ def system_locale_params
21
+ params.require(:system).permit(:locale)
22
+ end
23
+ end
24
+ end
@@ -5,23 +5,23 @@ module BeyondCanvas
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  included do
8
- before_action :set_locale, except: :update_locale
8
+ around_action :switch_locale, except: :update_locale
9
9
  end
10
10
 
11
11
  private
12
12
 
13
13
  #
14
- # Sets the I18n.locale to either +cookies[ :locale ]+ or the browser
15
- # compatible locale (if +cookies[ :locale ]+ is not set)
14
+ # Sets the cookie locale as default locale if it is a valid locale. If it is not a valid locale, searches for a
15
+ # browser compatible locale, sets the value to the cookie and set that locale as default locale.
16
16
  #
17
- def set_locale
17
+ def switch_locale(&action)
18
18
  unless valid_locale?(cookies[:locale])
19
19
  cookies[:locale] = { value: browser_compatible_locale, expires: 1.day.from_now }
20
20
  end
21
21
 
22
- I18n.locale = cookies[:locale]
22
+ I18n.with_locale(cookies[:locale], &action)
23
23
 
24
- logger.debug "[BeyondCanvas] Locale set to: #{I18n.locale}".yellow
24
+ logger.debug "[BeyondCanvas] Locale set to: #{cookies[:locale]}".yellow
25
25
  end
26
26
 
27
27
  #
@@ -0,0 +1,35 @@
1
+ module BeyondCanvas
2
+ module RequestValidation
3
+ extend ActiveSupport::Concern
4
+
5
+ private
6
+
7
+ def validate_app_installation_request!
8
+ bad_request unless app_installation_params? && valid_signature?(params[:signature],
9
+ app_installation_data,
10
+ BeyondApi.configuration.client_secret)
11
+ end
12
+
13
+ def app_installation_params?
14
+ if params[:code].nil? ||
15
+ params[:signature].nil? ||
16
+ params[:return_url].nil? ||
17
+ params[:api_url].nil? ||
18
+ params[:access_token_url].nil?
19
+ false
20
+ else
21
+ true
22
+ end
23
+ end
24
+
25
+ def app_installation_data
26
+ "#{params[:code]}:#{params[:access_token_url]}"
27
+ end
28
+
29
+ def valid_signature?(signature, data, secret)
30
+ digest = OpenSSL::Digest.new('SHA1')
31
+ hmac = OpenSSL::HMAC.digest(digest, secret, data)
32
+ signature == Base64.encode64(hmac).chop
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ module BeyondCanvas
2
+ module StatusCodes
3
+ extend ActiveSupport::Concern
4
+
5
+ private
6
+
7
+ def bad_request
8
+ raise ActionController::BadRequest.new 'Bad Request'
9
+ end
10
+
11
+ def not_found
12
+ raise ActionController::RoutingError.new 'Not Found'
13
+ end
14
+ end
15
+ end
@@ -17,7 +17,7 @@ module BeyondCanvas
17
17
  end
18
18
  end
19
19
 
20
- [:email, :text, :password, :file].each do |method|
20
+ [:email, :text, :number, :password].each do |method|
21
21
  define_method :"#{method}_field" do |attribute, args = {}|
22
22
  field_wrapper(attribute, args) do
23
23
  super(attribute, args)
@@ -1,6 +1,6 @@
1
1
  - if defined?(I18n) && I18n.available_locales.count > 1
2
- = form_for :app, url: beyond_canvas.update_locale_path, method: :put do |f|
2
+ = form_for :system, url: beyond_canvas.update_locale_path, method: :put do |f|
3
3
  = f.select :locale, I18n.available_locales.collect { |l| [translate_locale(l), l] },
4
- { selected: I18n.locale },
4
+ { selected: cookies[:locale] },
5
5
  class: 'select--locale',
6
6
  onchange: 'this.form.submit()'
@@ -6,7 +6,7 @@ html
6
6
  body.body--public
7
7
  main.main class=("#{params[:controller].gsub(/[\/_]/, "-")}--#{params[:action]}")
8
8
  = render 'beyond_canvas/shared/flash'
9
- = render 'beyond_canvas/shared/locale_switch'
9
+ = render 'beyond_canvas/locales/edit'
10
10
  .main-wrapper
11
11
  = render 'beyond_canvas/shared/logo'
12
12
  = yield
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Filter app installation parameters
4
+ Rails.application.config.filter_parameters += [
5
+ :access_token_url,
6
+ :code,
7
+ :return_url,
8
+ :signature
9
+ ]
data/config/routes.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  BeyondCanvas::Engine.routes.draw do
4
- put '/locale', to: 'application#update_locale', as: :update_locale
4
+ put '/locale', to: 'system#update_locale', as: :update_locale
5
5
  end
data/lib/beyond_canvas.rb CHANGED
@@ -10,6 +10,8 @@ require 'inline_svg'
10
10
  require 'http/accept'
11
11
  require 'premailer/rails'
12
12
 
13
+ require 'beyond_api'
14
+
13
15
  module BeyondCanvas
14
16
  class << self
15
17
  attr_accessor :configuration
@@ -7,6 +7,8 @@ module BeyondCanvas
7
7
  config.before_initialize do
8
8
  ActiveSupport.on_load :action_controller do
9
9
  include ::BeyondCanvas::LocaleManagement
10
+ include ::BeyondCanvas::RequestValidation
11
+ include ::BeyondCanvas::StatusCodes
10
12
 
11
13
  ::ActionController::Base.helper BeyondCanvas::Engine.helpers
12
14
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BeyondCanvas
4
- VERSION = '0.12.0.pre'
4
+ VERSION = '0.13.0.pre'
5
5
  end
@@ -8,6 +8,18 @@ module BeyondCanvas
8
8
  def copy_initializer
9
9
  template 'beyond_canvas.rb', 'config/initializers/beyond_canvas.rb'
10
10
  end
11
+
12
+ def install_beyond_api
13
+ require 'beyond_api'
14
+
15
+ initializer_file = File.join(destination_root, 'config/initializers/beyond_api.rb')
16
+
17
+ if File.exist?(initializer_file)
18
+ log :generate, 'No need to install beyond_api, already done.'
19
+ else
20
+ invoke 'beyond_api:install'
21
+ end
22
+ end
11
23
  end
12
24
  end
13
25
  end
@@ -1,8 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  BeyondCanvas.setup do |config|
4
- # config.public_logo = "logo.png"
4
+ # ==> Site configuration
5
5
 
6
+ # Configure an optional logo image to be displayed on the public layout. By
7
+ # default no image is set. It accepts any string supported by image_tag's
8
+ # source parameter.
9
+ # config.public_logo = 'logo.png'
10
+
11
+ # ==> CSS and JS configuration
12
+
13
+ # Configure the parent app's main stylesheet file. Default value is
14
+ # 'application'.
6
15
  # config.stylesheet_link_tag = 'application'
16
+
17
+ # Configure the parent app's main javascript file. Default value is
18
+ # 'application'.
7
19
  # config.javascript_include_tag = 'application'
8
20
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beyond_canvas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0.pre
4
+ version: 0.13.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Unai Abrisketa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-01 00:00:00.000000000 Z
11
+ date: 2020-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: beyond_api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bourbon
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -183,22 +197,26 @@ files:
183
197
  - app/assets/stylesheets/beyond_canvas/settings/_variables.sass
184
198
  - app/assets/stylesheets/beyond_canvas/utilities/_mixins.sass
185
199
  - app/controllers/beyond_canvas/application_controller.rb
200
+ - app/controllers/beyond_canvas/system_controller.rb
186
201
  - app/controllers/concerns/beyond_canvas/locale_management.rb
202
+ - app/controllers/concerns/beyond_canvas/request_validation.rb
203
+ - app/controllers/concerns/beyond_canvas/status_codes.rb
187
204
  - app/form_builders/beyond_canvas/form_builder.rb
188
205
  - app/helpers/beyond_canvas/application_helper.rb
189
206
  - app/helpers/beyond_canvas/locale_switch_helper.rb
190
207
  - app/views/beyond_canvas/custom/_public_head.html.slim
208
+ - app/views/beyond_canvas/locales/_edit.html.slim
191
209
  - app/views/beyond_canvas/mailer/_button.html.erb
192
210
  - app/views/beyond_canvas/mailer/_footer.html.erb
193
211
  - app/views/beyond_canvas/mailer/_header.html.erb
194
212
  - app/views/beyond_canvas/mailer/_text.html.erb
195
213
  - app/views/beyond_canvas/shared/_flash.html.slim
196
214
  - app/views/beyond_canvas/shared/_head.html.slim
197
- - app/views/beyond_canvas/shared/_locale_switch.html.slim
198
215
  - app/views/beyond_canvas/shared/_logo.html.slim
199
216
  - app/views/layouts/beyond_canvas/mailer.html.erb
200
217
  - app/views/layouts/beyond_canvas/public.html.slim
201
218
  - config/initializers/beyond_canvas/assets.rb
219
+ - config/initializers/beyond_canvas/filter_parameter_logging.rb
202
220
  - config/initializers/beyond_canvas/form_utils.rb
203
221
  - config/routes.rb
204
222
  - lib/beyond_canvas.rb
@@ -208,7 +226,6 @@ files:
208
226
  - lib/generators/beyond_canvas/install_generator.rb
209
227
  - lib/generators/templates/beyond_canvas.rb
210
228
  - lib/generators/templates/beyond_canvas_custom_styles.sass
211
- - lib/generators/templates/beyond_canvas_form_utils.rb
212
229
  homepage: https://github.com/ePages-de/beyond_canvas
213
230
  licenses:
214
231
  - MIT
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Adds form__error class to the inputs after sending a form when errors
4
- ActionView::Base.field_error_proc = proc do |html_tag, _instance|
5
- include ActionView::Helpers::SanitizeHelper
6
-
7
- if html_tag =~ /<(input|textarea|select)/
8
- error_class = 'form__error'
9
-
10
- doc = Nokogiri::XML(html_tag)
11
- doc.children.each do |field|
12
- next if field['type'] == 'hidden'
13
-
14
- next if field['class'] =~ /\berror\b/
15
-
16
- field['class'] = "#{field['class']} #{error_class}".strip
17
- end
18
-
19
- sanitize doc.to_html
20
- else
21
- html_tag
22
- end
23
- end