lib/hanami/assets/helpers.rb in hanami-assets-1.3.4 vs lib/hanami/assets/helpers.rb in hanami-assets-1.3.5
- old
+ new
@@ -1,9 +1,11 @@
-require 'uri'
-require 'hanami/helpers/html_helper'
-require 'hanami/utils/escape'
+# frozen_string_literal: true
+require "uri"
+require "hanami/helpers/html_helper"
+require "hanami/utils/escape"
+
module Hanami
module Assets
# HTML assets helpers
#
# Include this helper in a view
@@ -11,55 +13,54 @@
# @since 0.1.0
#
# @see http://www.rubydoc.info/gems/hanami-helpers/Hanami/Helpers/HtmlHelper
#
# rubocop:disable Metrics/ModuleLength
- # rubocop:disable Naming/UncommunicativeMethodParamName
module Helpers
# @since 0.1.0
# @api private
- NEW_LINE_SEPARATOR = "\n".freeze
+ NEW_LINE_SEPARATOR = "\n"
# @since 0.1.0
# @api private
- WILDCARD_EXT = '.*'.freeze
+ WILDCARD_EXT = ".*"
# @since 0.1.0
# @api private
- JAVASCRIPT_EXT = '.js'.freeze
+ JAVASCRIPT_EXT = ".js"
# @since 0.1.0
# @api private
- STYLESHEET_EXT = '.css'.freeze
+ STYLESHEET_EXT = ".css"
# @since 0.1.0
# @api private
- JAVASCRIPT_MIME_TYPE = 'text/javascript'.freeze
+ JAVASCRIPT_MIME_TYPE = "text/javascript"
# @since 0.1.0
# @api private
- STYLESHEET_MIME_TYPE = 'text/css'.freeze
+ STYLESHEET_MIME_TYPE = "text/css"
# @since 0.1.0
# @api private
- FAVICON_MIME_TYPE = 'image/x-icon'.freeze
+ FAVICON_MIME_TYPE = "image/x-icon"
# @since 0.1.0
# @api private
- STYLESHEET_REL = 'stylesheet'.freeze
+ STYLESHEET_REL = "stylesheet"
# @since 0.1.0
# @api private
- FAVICON_REL = 'shortcut icon'.freeze
+ FAVICON_REL = "shortcut icon"
# @since 0.1.0
# @api private
- DEFAULT_FAVICON = 'favicon.ico'.freeze
+ DEFAULT_FAVICON = "favicon.ico"
# @since 0.3.0
# @api private
- CROSSORIGIN_ANONYMOUS = 'anonymous'.freeze
+ CROSSORIGIN_ANONYMOUS = "anonymous"
# @since 0.3.0
# @api private
ABSOLUTE_URL_MATCHER = URI::DEFAULT_PARSER.make_regexp
@@ -138,17 +139,19 @@
#
# @example Subresource Integrity
#
# <%= javascript 'application' %>
#
- # # <script src="/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.js" type="text/javascript" integrity="sha384-oqVu...Y8wC" crossorigin="anonymous"></script>
+ # # <script src="/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.js"
+ # # type="text/javascript" integrity="sha384-oqVu...Y8wC" crossorigin="anonymous"></script>
#
# @example Subresource Integrity for 3rd Party Scripts
#
# <%= javascript 'https://example.com/assets/example.js', integrity: 'sha384-oqVu...Y8wC' %>
#
- # # <script src="https://example.com/assets/example.js" type="text/javascript" integrity="sha384-oqVu...Y8wC" crossorigin="anonymous"></script>
+ # # <script src="https://example.com/assets/example.js" type="text/javascript"
+ # # integrity="sha384-oqVu...Y8wC" crossorigin="anonymous"></script>
#
# @example Deferred Execution
#
# <%= javascript 'application', defer: true %>
#
@@ -168,17 +171,18 @@
#
# @example CDN Mode
#
# <%= javascript 'application' %>
#
- # # <script src="https://assets.bookshelf.org/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.js" type="text/javascript"></script>
+ # # <script src="https://assets.bookshelf.org/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.js"
+ # # type="text/javascript"></script>
#
# @example Disable Push Promise/Early Hints
#
# <%= javascript 'application', push: false %>
# <%= javascript 'http://cdn.example.test/jquery.js', 'dashboard', push: false %>
- def javascript(*sources, push: true, **options) # rubocop:disable Metrics/MethodLength
+ def javascript(*sources, push: true, **options)
options = options.reject { |k, _| k.to_sym == :src }
_safe_tags(*sources) do |source|
attributes = {
src: _typed_asset_path(source, JAVASCRIPT_EXT, push: push, as: :script),
@@ -245,23 +249,26 @@
#
# @example Subresource Integrity
#
# <%= stylesheet 'application' %>
#
- # # <link href="/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.css" type="text/css" integrity="sha384-oqVu...Y8wC" crossorigin="anonymous"></script>
+ # # <link href="/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.css"
+ # # type="text/css" integrity="sha384-oqVu...Y8wC" crossorigin="anonymous"></script>
#
# @example Subresource Integrity for 3rd Party Assets
#
# <%= stylesheet 'https://example.com/assets/example.css', integrity: 'sha384-oqVu...Y8wC' %>
#
- # # <link href="https://example.com/assets/example.css" type="text/css" rel="stylesheet" integrity="sha384-oqVu...Y8wC" crossorigin="anonymous"></script>
+ # # <link href="https://example.com/assets/example.css"
+ # # type="text/css" rel="stylesheet" integrity="sha384-oqVu...Y8wC" crossorigin="anonymous"></script>
#
# @example Absolute URL
#
# <%= stylesheet 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css' %>
#
- # # <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" type="text/css" rel="stylesheet">
+ # # <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
+ # # type="text/css" rel="stylesheet">
#
# @example Fingerprint Mode
#
# <%= stylesheet 'application' %>
#
@@ -269,17 +276,18 @@
#
# @example CDN Mode
#
# <%= stylesheet 'application' %>
#
- # # <link href="https://assets.bookshelf.org/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.css" type="text/css" rel="stylesheet">
+ # # <link href="https://assets.bookshelf.org/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.css"
+ # # type="text/css" rel="stylesheet">
#
# @example Disable Push Promise/Early Hints
#
# <%= stylesheet 'application', push: false %>
# <%= stylesheet 'http://cdn.example.test/bootstrap.css', 'dashboard', push: false %>
- def stylesheet(*sources, push: true, **options) # rubocop:disable Metrics/MethodLength
+ def stylesheet(*sources, push: true, **options)
options = options.reject { |k, _| k.to_sym == :href }
_safe_tags(*sources) do |source|
attributes = {
href: _typed_asset_path(source, STYLESHEET_EXT, push: push, as: :style),
@@ -433,11 +441,12 @@
#
# @example CDN Mode
#
# <%= favicon %>
#
- # # <link href="https://assets.bookshelf.org/assets/favicon-28a6b886de2372ee3922fcaf3f78f2d8.ico" rel="shortcut icon" type="image/x-icon">
+ # # <link href="https://assets.bookshelf.org/assets/favicon-28a6b886de2372ee3922fcaf3f78f2d8.ico"
+ # rel="shortcut icon" type="image/x-icon">
#
# @example Enable Push Promise/Early Hints
#
# <%= favicon 'favicon.ico', push: true %>
def favicon(source = DEFAULT_FAVICON, options = {})
@@ -861,11 +870,11 @@
asset_path(source, push: push, as: as)
end
# @api private
def _subresource_integrity?
- !!self.class.assets_configuration.subresource_integrity # rubocop:disable Style/DoubleNegation
+ !!self.class.assets_configuration.subresource_integrity
end
# @api private
def _subresource_integrity_value(source, ext)
source = "#{source}#{ext}" unless source =~ /#{Regexp.escape(ext)}\z/
@@ -907,29 +916,30 @@
options = src.to_hash
elsif src
options[:src] = asset_path(src, push: options.delete(:push) || false, as: as)
end
- raise ArgumentError.new('You should provide a source via `src` option or with a `source` HTML tag') if !options[:src] && !block_given?
+ if !options[:src] && !block_given?
+ raise ArgumentError.new("You should provide a source via `src` option or with a `source` HTML tag")
+ end
options
end
# @since 0.1.0
# @api private
def _push_promise(url, as: nil)
Thread.current[:__hanami_assets] ||= {}
- Thread.current[:__hanami_assets][url.to_s] = { as: as, crossorigin: _crossorigin?(url) }
+ Thread.current[:__hanami_assets][url.to_s] = {as: as, crossorigin: _crossorigin?(url)}
url
end
# @since 1.1.0
# @api private
def _append_extension?(source, ext)
source !~ QUERY_STRING_MATCHER && source !~ /#{Regexp.escape(ext)}\z/
end
end
- # rubocop:enable Naming/UncommunicativeMethodParamName
# rubocop:enable Metrics/ModuleLength
end
end