Enforce rubocop rules for 2.0
This commit is contained in:
parent
695e54f131
commit
317319641d
|
@ -1,7 +1,7 @@
|
|||
# Please keep AllCops, Bundler, Style, Metrics groups and then order cops
|
||||
# alphabetically
|
||||
inherit_from:
|
||||
- https://raw.githubusercontent.com/hanami/devtools/master/.rubocop.yml
|
||||
- https://raw.githubusercontent.com/hanami/devtools/master/.rubocop-unstable.yml
|
||||
AllCops:
|
||||
Exclude:
|
||||
- "vendor/**/*"
|
||||
|
|
26
Gemfile
26
Gemfile
|
@ -1,18 +1,20 @@
|
|||
source 'https://rubygems.org'
|
||||
# frozen_string_literal: true
|
||||
|
||||
source "https://rubygems.org"
|
||||
gemspec
|
||||
|
||||
unless ENV['TRAVIS']
|
||||
gem 'byebug', require: false, platforms: :mri
|
||||
gem 'yard', require: false
|
||||
unless ENV["TRAVIS"]
|
||||
gem "byebug", require: false, platforms: :mri
|
||||
gem "yard", require: false
|
||||
end
|
||||
|
||||
gem 'hanami-utils', '2.0.0.alpha1', git: 'https://github.com/hanami/utils.git', branch: 'unstable'
|
||||
gem 'hanami-helpers', '2.0.0.alpha1', git: 'https://github.com/hanami/helpers.git', branch: 'unstable'
|
||||
gem 'hanami-view', '2.0.0.alpha1', git: 'https://github.com/hanami/view.git', branch: 'unstable'
|
||||
gem "hanami-utils", "2.0.0.alpha1", git: "https://github.com/hanami/utils.git", branch: "unstable"
|
||||
gem "hanami-helpers", "2.0.0.alpha1", git: "https://github.com/hanami/helpers.git", branch: "unstable"
|
||||
gem "hanami-view", "2.0.0.alpha1", git: "https://github.com/hanami/view.git", branch: "unstable"
|
||||
|
||||
gem 'hanami-emberjs', path: 'spec/support/fixtures/hanami-emberjs', require: false
|
||||
gem 'hanami-compass', path: 'spec/support/fixtures/hanami-compass', require: false
|
||||
gem 'hanami-foo-compressor', path: 'spec/support/fixtures/hanami-foo-compressor', require: false
|
||||
gem "hanami-emberjs", path: "spec/support/fixtures/hanami-emberjs", require: false
|
||||
gem "hanami-compass", path: "spec/support/fixtures/hanami-compass", require: false
|
||||
gem "hanami-foo-compressor", path: "spec/support/fixtures/hanami-foo-compressor", require: false
|
||||
|
||||
gem 'hanami-devtools', require: false, git: 'https://github.com/hanami/devtools.git'
|
||||
gem 'coveralls', require: false
|
||||
gem "hanami-devtools", require: false, git: "https://github.com/hanami/devtools.git"
|
||||
gem "coveralls", require: false
|
||||
|
|
24
Rakefile
24
Rakefile
|
@ -1,13 +1,15 @@
|
|||
require 'rake'
|
||||
require 'bundler/gem_tasks'
|
||||
require 'rspec/core/rake_task'
|
||||
require 'rake/testtask'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rake"
|
||||
require "bundler/gem_tasks"
|
||||
require "rspec/core/rake_task"
|
||||
require "rake/testtask"
|
||||
|
||||
Rake::TestTask.new do |t|
|
||||
t.pattern = 'test/**/*_test.rb'
|
||||
t.libs.push 'test'
|
||||
t.pattern = "test/**/*_test.rb"
|
||||
t.libs.push "test"
|
||||
|
||||
if ENV['TRAVIS']
|
||||
if ENV["TRAVIS"]
|
||||
t.verbose = false
|
||||
t.warning = false
|
||||
end
|
||||
|
@ -16,15 +18,15 @@ end
|
|||
RSpec::Core::RakeTask.new(:spec)
|
||||
namespace :spec do
|
||||
RSpec::Core::RakeTask.new(:unit) do |task|
|
||||
file_list = FileList['spec/**/*_spec.rb']
|
||||
file_list = FileList["spec/**/*_spec.rb"]
|
||||
file_list = file_list.exclude("spec/{integration,isolation}/**/*_spec.rb")
|
||||
|
||||
task.pattern = file_list
|
||||
end
|
||||
|
||||
task :coverage do
|
||||
ENV['COVERAGE'] = 'true'
|
||||
Rake::Task['spec:unit'].invoke
|
||||
ENV["COVERAGE"] = "true"
|
||||
Rake::Task["spec:unit"].invoke
|
||||
end
|
||||
end
|
||||
task default: 'spec'
|
||||
task default: "spec"
|
||||
|
|
|
@ -1,22 +1,23 @@
|
|||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'optparse'
|
||||
require 'pathname'
|
||||
require "optparse"
|
||||
require "pathname"
|
||||
|
||||
options = {}
|
||||
OptionParser.new do |opts|
|
||||
opts.banner = 'Usage: hanami-assets --config=path/to/config.rb'
|
||||
opts.banner = "Usage: hanami-assets --config=path/to/config.rb"
|
||||
|
||||
opts.on('-c', '--config FILE', 'Path to config') do |c|
|
||||
opts.on("-c", "--config FILE", "Path to config") do |c|
|
||||
options[:config] = c
|
||||
end
|
||||
end.parse!
|
||||
|
||||
config = options.fetch(:config) { raise ArgumentError.new('You must specify a configuration file') }
|
||||
config = options.fetch(:config) { raise ArgumentError.new("You must specify a configuration file") }
|
||||
config = Pathname.new(config)
|
||||
config.exist? or raise ArgumentError.new("Cannot find configuration file: #{config}")
|
||||
|
||||
require 'hanami/assets'
|
||||
require "hanami/assets"
|
||||
load config
|
||||
|
||||
Hanami::Assets.deploy
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
require 'thread'
|
||||
require 'hanami/utils/class_attribute'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "thread"
|
||||
require "hanami/utils/class_attribute"
|
||||
|
||||
# Hanami
|
||||
#
|
||||
|
@ -17,10 +19,10 @@ module Hanami
|
|||
class Error < ::StandardError
|
||||
end
|
||||
|
||||
require 'hanami/assets/version'
|
||||
require 'hanami/assets/configuration'
|
||||
require 'hanami/assets/config/global_sources'
|
||||
require 'hanami/assets/helpers'
|
||||
require "hanami/assets/version"
|
||||
require "hanami/assets/configuration"
|
||||
require "hanami/assets/config/global_sources"
|
||||
require "hanami/assets/helpers"
|
||||
|
||||
include Utils::ClassAttribute
|
||||
|
||||
|
@ -49,8 +51,8 @@ module Hanami
|
|||
#
|
||||
# @since 0.1.0
|
||||
def self.deploy
|
||||
require 'hanami/assets/precompiler'
|
||||
require 'hanami/assets/bundler'
|
||||
require "hanami/assets/precompiler"
|
||||
require "hanami/assets/bundler"
|
||||
|
||||
Precompiler.new(configuration, duplicates).run
|
||||
Bundler.new(configuration, duplicates).run
|
||||
|
@ -60,8 +62,8 @@ module Hanami
|
|||
#
|
||||
# @since 0.4.0
|
||||
def self.precompile(configurations)
|
||||
require 'hanami/assets/precompiler'
|
||||
require 'hanami/assets/bundler'
|
||||
require "hanami/assets/precompiler"
|
||||
require "hanami/assets/bundler"
|
||||
|
||||
Precompiler.new(configuration, configurations).run
|
||||
Bundler.new(configuration, configurations).run
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
require 'fileutils'
|
||||
require 'json'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'hanami/assets/bundler/compressor'
|
||||
require 'hanami/assets/bundler/asset'
|
||||
require 'hanami/assets/bundler/manifest_entry'
|
||||
require "fileutils"
|
||||
require "json"
|
||||
|
||||
require "hanami/assets/bundler/compressor"
|
||||
require "hanami/assets/bundler/asset"
|
||||
require "hanami/assets/bundler/manifest_entry"
|
||||
|
||||
module Hanami
|
||||
module Assets
|
||||
|
@ -18,11 +20,11 @@ module Hanami
|
|||
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
URL_SEPARATOR = '/'.freeze
|
||||
URL_SEPARATOR = "/"
|
||||
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
URL_REPLACEMENT = ''.freeze
|
||||
URL_REPLACEMENT = ""
|
||||
|
||||
# Return a new instance
|
||||
#
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
require 'openssl'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "openssl"
|
||||
|
||||
module Hanami
|
||||
module Assets
|
||||
|
@ -20,7 +22,7 @@ module Hanami
|
|||
|
||||
# @since 0.3.0
|
||||
# @api private
|
||||
WILDCARD_EXT = '.*'.freeze
|
||||
WILDCARD_EXT = ".*"
|
||||
|
||||
# Return a new instance
|
||||
#
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Hanami
|
||||
module Assets
|
||||
class Bundler
|
||||
|
@ -8,11 +10,11 @@ module Hanami
|
|||
class Compressor
|
||||
# @since 0.3.0
|
||||
# @api private
|
||||
JAVASCRIPT_EXT = '.js'.freeze
|
||||
JAVASCRIPT_EXT = ".js"
|
||||
|
||||
# @since 0.3.0
|
||||
# @api private
|
||||
STYLESHEET_EXT = '.css'.freeze
|
||||
STYLESHEET_EXT = ".css"
|
||||
|
||||
# Return a new instance
|
||||
#
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Hanami
|
||||
module Assets
|
||||
class Bundler
|
||||
|
@ -8,7 +10,7 @@ module Hanami
|
|||
class ManifestEntry
|
||||
# @since 0.3.0
|
||||
# @api private
|
||||
SUBRESOURCE_INTEGRITY_SEPARATOR = '-'.freeze
|
||||
SUBRESOURCE_INTEGRITY_SEPARATOR = "-"
|
||||
|
||||
# Return a new instance
|
||||
#
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
require 'thread'
|
||||
require 'pathname'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "thread"
|
||||
require "pathname"
|
||||
|
||||
module Hanami
|
||||
module Assets
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
require 'set'
|
||||
require 'find'
|
||||
require 'hanami/utils/class_attribute'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "set"
|
||||
require "find"
|
||||
require "hanami/utils/class_attribute"
|
||||
|
||||
module Hanami
|
||||
module Assets
|
||||
# Missing Asset error
|
||||
class MissingAsset < Error
|
||||
def initialize(name, sources)
|
||||
sources = sources.map(&:to_s).join(', ')
|
||||
sources = sources.map(&:to_s).join(", ")
|
||||
super("Missing asset: `#{name}' (sources: #{sources})")
|
||||
end
|
||||
end
|
||||
|
@ -35,11 +37,11 @@ module Hanami
|
|||
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
COMPILE_PATTERN = '*.*.*'.freeze # Example hello.js.es6
|
||||
COMPILE_PATTERN = "*.*.*" # Example hello.js.es6
|
||||
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
EXTENSIONS = { '.js' => true, '.css' => true, '.map' => true }.freeze
|
||||
EXTENSIONS = { ".js" => true, ".css" => true, ".map" => true }.freeze
|
||||
|
||||
include Utils::ClassAttribute
|
||||
|
||||
|
@ -67,10 +69,10 @@ module Hanami
|
|||
def self.compile(configuration, name)
|
||||
return unless configuration.compile
|
||||
|
||||
require 'tilt'
|
||||
require 'hanami/assets/cache'
|
||||
require 'hanami/assets/compilers/sass'
|
||||
require 'hanami/assets/compilers/less'
|
||||
require "tilt"
|
||||
require "hanami/assets/cache"
|
||||
require "hanami/assets/compilers/sass"
|
||||
require "hanami/assets/compilers/less"
|
||||
fabricate(configuration, name).compile
|
||||
end
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Hanami
|
||||
module Assets
|
||||
module Compilers
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Hanami
|
||||
module Assets
|
||||
module Compilers
|
||||
|
@ -13,7 +15,7 @@ module Hanami
|
|||
# @since 0.1.0
|
||||
# @api private
|
||||
CACHE_LOCATION = Pathname(Hanami.respond_to?(:root) ? # rubocop:disable Style/MultilineTernaryOperator
|
||||
Hanami.root : Dir.pwd).join('tmp', 'sass-cache')
|
||||
Hanami.root : Dir.pwd).join("tmp", "sass-cache")
|
||||
|
||||
# @since 0.3.0
|
||||
# @api private
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
require 'hanami/utils/load_paths'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "hanami/utils/load_paths"
|
||||
|
||||
module Hanami
|
||||
module Assets
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Hanami
|
||||
module Assets
|
||||
# This error is raised when the application starts but can't be load the
|
||||
|
@ -83,11 +85,11 @@ module Hanami
|
|||
class Manifest
|
||||
# @since 0.4.0
|
||||
# @api private
|
||||
TARGET = 'target'.freeze
|
||||
TARGET = "target"
|
||||
|
||||
# @since 0.3.0
|
||||
# @api private
|
||||
SUBRESOURCE_INTEGRITY = 'sri'.freeze
|
||||
SUBRESOURCE_INTEGRITY = "sri"
|
||||
|
||||
# Return a new instance
|
||||
#
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
require 'hanami/utils/load_paths'
|
||||
require 'hanami/utils/file_list'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "hanami/utils/load_paths"
|
||||
require "hanami/utils/file_list"
|
||||
|
||||
module Hanami
|
||||
module Assets
|
||||
|
@ -20,7 +22,7 @@ module Hanami
|
|||
class Sources < Utils::LoadPaths
|
||||
# @since 0.3.0
|
||||
# @api private
|
||||
SKIPPED_FILE_PREFIX = '_'.freeze
|
||||
SKIPPED_FILE_PREFIX = "_"
|
||||
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
require 'pathname'
|
||||
require 'json'
|
||||
require 'hanami/utils/string'
|
||||
require 'hanami/utils/class'
|
||||
require 'hanami/utils/path_prefix'
|
||||
require 'hanami/utils/basic_object'
|
||||
require 'hanami/assets/config/manifest'
|
||||
require 'hanami/assets/config/sources'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "pathname"
|
||||
require "json"
|
||||
require "hanami/utils/string"
|
||||
require "hanami/utils/class"
|
||||
require "hanami/utils/path_prefix"
|
||||
require "hanami/utils/basic_object"
|
||||
require "hanami/assets/config/manifest"
|
||||
require "hanami/assets/config/sources"
|
||||
|
||||
module Hanami
|
||||
module Assets
|
||||
|
@ -15,47 +17,47 @@ module Hanami
|
|||
class Configuration # rubocop:disable Metrics/ClassLength
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
DEFAULT_SCHEME = 'http'.freeze
|
||||
DEFAULT_SCHEME = "http"
|
||||
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
DEFAULT_HOST = 'localhost'.freeze
|
||||
DEFAULT_HOST = "localhost"
|
||||
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
DEFAULT_PORT = '2300'.freeze
|
||||
DEFAULT_PORT = "2300"
|
||||
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
DEFAULT_PUBLIC_DIRECTORY = 'public'.freeze
|
||||
DEFAULT_PUBLIC_DIRECTORY = "public"
|
||||
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
DEFAULT_MANIFEST = 'assets.json'.freeze
|
||||
DEFAULT_MANIFEST = "assets.json"
|
||||
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
DEFAULT_PREFIX = '/assets'.freeze
|
||||
DEFAULT_PREFIX = "/assets"
|
||||
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
URL_SEPARATOR = '/'.freeze
|
||||
URL_SEPARATOR = "/"
|
||||
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
HTTP_SCHEME = 'http'.freeze
|
||||
HTTP_SCHEME = "http"
|
||||
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
HTTP_PORT = '80'.freeze
|
||||
HTTP_PORT = "80"
|
||||
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
HTTPS_SCHEME = 'https'.freeze
|
||||
HTTPS_SCHEME = "https"
|
||||
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
HTTPS_PORT = '443'.freeze
|
||||
HTTPS_PORT = "443"
|
||||
|
||||
# @since 0.3.0
|
||||
# @api private
|
||||
|
@ -63,7 +65,7 @@ module Hanami
|
|||
|
||||
# @since 0.3.0
|
||||
# @api private
|
||||
SUBRESOURCE_INTEGRITY_SEPARATOR = ' '.freeze
|
||||
SUBRESOURCE_INTEGRITY_SEPARATOR = " "
|
||||
|
||||
# Return a copy of the configuration of the framework instance associated
|
||||
# with the given class.
|
||||
|
@ -463,7 +465,7 @@ module Hanami
|
|||
# @see Hanami::Assets::Configuration#javascript_compressor
|
||||
# @see Hanami::Assets::Compressors::Javascript#for
|
||||
def js_compressor
|
||||
require 'hanami/assets/compressors/javascript'
|
||||
require "hanami/assets/compressors/javascript"
|
||||
Hanami::Assets::Compressors::Javascript.for(javascript_compressor)
|
||||
end
|
||||
|
||||
|
@ -480,7 +482,7 @@ module Hanami
|
|||
# @see Hanami::Assets::Configuration#stylesheet_compressor
|
||||
# @see Hanami::Assets::Compressors::Stylesheet#for
|
||||
def css_compressor
|
||||
require 'hanami/assets/compressors/stylesheet'
|
||||
require "hanami/assets/compressors/stylesheet"
|
||||
Hanami::Assets::Compressors::Stylesheet.for(stylesheet_compressor)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
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
|
||||
|
@ -14,47 +16,47 @@ module Hanami
|
|||
module Helpers # rubocop:disable Metrics/ModuleLength
|
||||
# @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
|
||||
|
@ -848,7 +850,7 @@ module Hanami
|
|||
|
||||
# @api private
|
||||
def _subresource_integrity_value(source, ext)
|
||||
source = "#{source}#{ext}" unless source =~ /#{Regexp.escape(ext)}\z/
|
||||
source = "#{source}#{ext}" unless source.match?(/#{Regexp.escape(ext)}\z/)
|
||||
self.class.assets_configuration.subresource_integrity_value(source) unless _absolute_url?(source)
|
||||
end
|
||||
|
||||
|
@ -889,7 +891,7 @@ module Hanami
|
|||
end
|
||||
|
||||
if !options[:src] && !block_given?
|
||||
raise ArgumentError.new('You should provide a source via `src` option or with a `source` HTML tag')
|
||||
raise ArgumentError.new("You should provide a source via `src` option or with a `source` HTML tag")
|
||||
end
|
||||
|
||||
options
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
require 'fileutils'
|
||||
require 'hanami/assets/compiler'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "fileutils"
|
||||
require "hanami/assets/compiler"
|
||||
|
||||
module Hanami
|
||||
module Assets
|
||||
|
@ -48,11 +50,11 @@ module Hanami
|
|||
# @api private
|
||||
def clear_manifest(manifest)
|
||||
JSON.parse(manifest).each_value do |asset_hash|
|
||||
asset_file_name = @configuration.public_directory.join(asset_hash['target'])
|
||||
asset_file_name = @configuration.public_directory.join(asset_hash["target"])
|
||||
asset_file_name.unlink if asset_file_name.exist?
|
||||
end
|
||||
rescue JSON::ParserError
|
||||
$stderr.puts 'Non JSON manifest found and unlinked.'
|
||||
$stderr.puts "Non JSON manifest found and unlinked."
|
||||
ensure
|
||||
manifest.unlink
|
||||
end
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Hanami
|
||||
module Assets
|
||||
# Defines the version
|
||||
#
|
||||
# @since 0.1.0
|
||||
VERSION = '1.1.0'.freeze
|
||||
VERSION = "1.1.0"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
require 'tilt/sass'
|
||||
require 'tilt/coffee'
|
||||
require 'hanami/assets/compiler'
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe 'Compiler' do
|
||||
require "tilt/sass"
|
||||
require "tilt/coffee"
|
||||
require "hanami/assets/compiler"
|
||||
|
||||
describe "Compiler" do
|
||||
before do
|
||||
require 'hanami/compass'
|
||||
require "hanami/compass"
|
||||
fixtures = __dir__ + "/../../../support/fixtures"
|
||||
TMP.rmtree if TMP.exist?
|
||||
TMP.mkdir
|
||||
|
@ -12,11 +14,11 @@ describe 'Compiler' do
|
|||
Hanami::Assets.configure do
|
||||
compile true
|
||||
root fixtures
|
||||
public_directory TMP.join('public')
|
||||
public_directory TMP.join("public")
|
||||
|
||||
sources << [
|
||||
'javascripts',
|
||||
Pathname.new(fixtures).join('stylesheets'),
|
||||
"javascripts",
|
||||
Pathname.new(fixtures).join("stylesheets"),
|
||||
TMP
|
||||
]
|
||||
end
|
||||
|
@ -28,112 +30,112 @@ describe 'Compiler' do
|
|||
@config.reset!
|
||||
end
|
||||
|
||||
it 'copies javascript asset from source to destination' do
|
||||
Hanami::Assets::Compiler.compile(@config, 'greet.js')
|
||||
it "copies javascript asset from source to destination" do
|
||||
Hanami::Assets::Compiler.compile(@config, "greet.js")
|
||||
|
||||
target = @config.public_directory.join('assets', 'greet.js')
|
||||
target = @config.public_directory.join("assets", "greet.js")
|
||||
expect(target.read).to include %(alert("Hello!");)
|
||||
expect(target.stat.mode.to_s(8)).to eq('100644')
|
||||
expect(target.stat.mode.to_s(8)).to eq("100644")
|
||||
end
|
||||
|
||||
it 'copies javascript source map from source to destination' do
|
||||
Hanami::Assets::Compiler.compile(@config, 'precompiled.min.map')
|
||||
it "copies javascript source map from source to destination" do
|
||||
Hanami::Assets::Compiler.compile(@config, "precompiled.min.map")
|
||||
|
||||
target = @config.public_directory.join('assets', 'precompiled.min.map')
|
||||
target = @config.public_directory.join("assets", "precompiled.min.map")
|
||||
expect(target.read).to match %(//source map of precompiled.min)
|
||||
expect(target.stat.mode.to_s(8)).to eq('100644')
|
||||
expect(target.stat.mode.to_s(8)).to eq("100644")
|
||||
end
|
||||
|
||||
it 'copies asset from nested source to destination' do
|
||||
Hanami::Assets::Compiler.compile(@config, 'bootstrap.js')
|
||||
it "copies asset from nested source to destination" do
|
||||
Hanami::Assets::Compiler.compile(@config, "bootstrap.js")
|
||||
|
||||
target = @config.public_directory.join('assets', 'bootstrap.js')
|
||||
target = @config.public_directory.join("assets", "bootstrap.js")
|
||||
expect(target.read).to match %(// Bootstrap)
|
||||
expect(target.stat.mode.to_s(8)).to eq('100644')
|
||||
expect(target.stat.mode.to_s(8)).to eq("100644")
|
||||
end
|
||||
|
||||
it 'compiles coffeescript asset' do
|
||||
Hanami::Assets::Compiler.compile(@config, 'hello.js')
|
||||
it "compiles coffeescript asset" do
|
||||
Hanami::Assets::Compiler.compile(@config, "hello.js")
|
||||
|
||||
target = @config.public_directory.join('assets', 'hello.js')
|
||||
target = @config.public_directory.join("assets", "hello.js")
|
||||
expect(target.read).to include %(alert("Hello, World!");)
|
||||
expect(target.stat.mode.to_s(8)).to eq('100644')
|
||||
expect(target.stat.mode.to_s(8)).to eq("100644")
|
||||
end
|
||||
|
||||
it 'compiles es6 asset' do
|
||||
Hanami::Assets::Compiler.compile(@config, 'person.js')
|
||||
it "compiles es6 asset" do
|
||||
Hanami::Assets::Compiler.compile(@config, "person.js")
|
||||
|
||||
target = @config.public_directory.join('assets', 'person.js')
|
||||
target = @config.public_directory.join("assets", "person.js")
|
||||
expect(target.read).to include %(function Person(firstName, lastName))
|
||||
expect(target.stat.mode.to_s(8)).to eq('100644')
|
||||
expect(target.stat.mode.to_s(8)).to eq("100644")
|
||||
end
|
||||
|
||||
it 'compiles babel asset' do
|
||||
Hanami::Assets::Compiler.compile(@config, 'country.js')
|
||||
it "compiles babel asset" do
|
||||
Hanami::Assets::Compiler.compile(@config, "country.js")
|
||||
|
||||
target = @config.public_directory.join('assets', 'country.js')
|
||||
target = @config.public_directory.join("assets", "country.js")
|
||||
expect(target.read).to include %(function Country(name))
|
||||
expect(target.stat.mode.to_s(8)).to eq('100644')
|
||||
expect(target.stat.mode.to_s(8)).to eq("100644")
|
||||
end
|
||||
|
||||
it 'compiles jsx asset' do
|
||||
Hanami::Assets::Compiler.compile(@config, 'react-component.js')
|
||||
it "compiles jsx asset" do
|
||||
Hanami::Assets::Compiler.compile(@config, "react-component.js")
|
||||
|
||||
target = @config.public_directory.join('assets', 'react-component.js')
|
||||
target = @config.public_directory.join("assets", "react-component.js")
|
||||
expect(target.read).to include %(React.createElement(MyComponent, { someProperty: true });)
|
||||
expect(target.stat.mode.to_s(8)).to eq('100644')
|
||||
expect(target.stat.mode.to_s(8)).to eq("100644")
|
||||
end
|
||||
|
||||
it 'compiles sass asset' do
|
||||
Hanami::Assets::Compiler.compile(@config, 'compile-sass.css')
|
||||
it "compiles sass asset" do
|
||||
Hanami::Assets::Compiler.compile(@config, "compile-sass.css")
|
||||
|
||||
target = @config.public_directory.join('assets', 'compile-sass.css')
|
||||
target = @config.public_directory.join("assets", "compile-sass.css")
|
||||
content = target.read
|
||||
expect(content).to match %(body {\n font: 100% Helvetica, sans-serif;\n color: #333; }\n)
|
||||
expect(content).to match %(p {\n white-space: pre;)
|
||||
end
|
||||
|
||||
it 'compiles sass asset if a direct dependency has changed' do
|
||||
dependency = TestFile.new(path: '_background.scss') do
|
||||
write '$background-color: green'
|
||||
it "compiles sass asset if a direct dependency has changed" do
|
||||
dependency = TestFile.new(path: "_background.scss") do
|
||||
write "$background-color: green"
|
||||
end
|
||||
|
||||
Hanami::Assets::Compiler.compile(@config, 'sass-dependencies.css')
|
||||
Hanami::Assets::Compiler.compile(@config, "sass-dependencies.css")
|
||||
|
||||
target = @config.public_directory.join('assets', 'sass-dependencies.css')
|
||||
target = @config.public_directory.join("assets", "sass-dependencies.css")
|
||||
content = target.read
|
||||
expect(content).to match %(body {\n background-color: green; }\n)
|
||||
|
||||
dependency.touch('$background-color: blue') do
|
||||
Hanami::Assets::Compiler.compile(@config, 'sass-dependencies.css')
|
||||
dependency.touch("$background-color: blue") do
|
||||
Hanami::Assets::Compiler.compile(@config, "sass-dependencies.css")
|
||||
content = target.read
|
||||
expect(content).to match %(body {\n background-color: blue; }\n)
|
||||
end
|
||||
end
|
||||
|
||||
if CI.enabled?
|
||||
it 'compiles sass asset if a transitive dependency has changed'
|
||||
it "compiles sass asset if a transitive dependency has changed"
|
||||
else
|
||||
it 'compiles sass asset if a transitive dependency has changed' do
|
||||
dependency = TestFile.new(path: '_grid.scss') do
|
||||
write '$framework-padding: 0'
|
||||
it "compiles sass asset if a transitive dependency has changed" do
|
||||
dependency = TestFile.new(path: "_grid.scss") do
|
||||
write "$framework-padding: 0"
|
||||
end
|
||||
|
||||
Hanami::Assets::Compiler.compile(@config, 'sass-transitive-dependencies.css')
|
||||
Hanami::Assets::Compiler.compile(@config, "sass-transitive-dependencies.css")
|
||||
|
||||
target = @config.public_directory.join('assets', 'sass-transitive-dependencies.css')
|
||||
target = @config.public_directory.join("assets", "sass-transitive-dependencies.css")
|
||||
content = target.read
|
||||
expect(content).to match %(body {\n padding: 0; }\n)
|
||||
|
||||
dependency.touch('$framework-padding: 1') do
|
||||
Hanami::Assets::Compiler.compile(@config, 'sass-transitive-dependencies.css')
|
||||
dependency.touch("$framework-padding: 1") do
|
||||
Hanami::Assets::Compiler.compile(@config, "sass-transitive-dependencies.css")
|
||||
content = target.read
|
||||
expect(content).to match %(body {\n padding: 1; }\n)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'compiles sass asset if a dependency is added' do
|
||||
it "compiles sass asset if a dependency is added" do
|
||||
asset_name = "#{SecureRandom.uuid}.css"
|
||||
asset = TestFile.new(path: "#{asset_name}.sass") do
|
||||
write "body\n margin: 0"
|
||||
|
@ -141,7 +143,7 @@ describe 'Compiler' do
|
|||
|
||||
Hanami::Assets::Compiler.compile(@config, asset_name)
|
||||
|
||||
target = @config.public_directory.join('assets', asset_name)
|
||||
target = @config.public_directory.join("assets", asset_name)
|
||||
content = target.read
|
||||
expect(content).to match %(body {\n margin: 0; }\n)
|
||||
|
||||
|
@ -157,7 +159,7 @@ describe 'Compiler' do
|
|||
end
|
||||
end
|
||||
|
||||
it 'compiles sass asset if a dependency is removed' do
|
||||
it "compiles sass asset if a dependency is removed" do
|
||||
dependency_name = SecureRandom.uuid
|
||||
_ = TestFile.new(path: "_#{dependency_name}.sass") do
|
||||
write "html\n padding: 0"
|
||||
|
@ -170,7 +172,7 @@ describe 'Compiler' do
|
|||
|
||||
Hanami::Assets::Compiler.compile(@config, asset_name)
|
||||
|
||||
target = @config.public_directory.join('assets', asset_name)
|
||||
target = @config.public_directory.join("assets", asset_name)
|
||||
content = target.read
|
||||
expect(content).to match %(html {\n padding: 0; }\n\nbody {\n margin: 0; }\n)
|
||||
|
||||
|
@ -181,82 +183,82 @@ describe 'Compiler' do
|
|||
end
|
||||
end
|
||||
|
||||
it 'compiles scss asset' do
|
||||
Hanami::Assets::Compiler.compile(@config, 'compile-scss.css')
|
||||
it "compiles scss asset" do
|
||||
Hanami::Assets::Compiler.compile(@config, "compile-scss.css")
|
||||
|
||||
target = @config.public_directory.join('assets', 'compile-scss.css')
|
||||
target = @config.public_directory.join("assets", "compile-scss.css")
|
||||
expect(target.read).to match %(body {\n font: 100% Helvetica, sans-serif;\n color: #fff; }\n)
|
||||
end
|
||||
|
||||
it 'uses defined sass cache directory' do
|
||||
directory = Pathname.new(Dir.pwd).join('tmp', 'sass-cache')
|
||||
it "uses defined sass cache directory" do
|
||||
directory = Pathname.new(Dir.pwd).join("tmp", "sass-cache")
|
||||
directory.rmtree if directory.exist?
|
||||
|
||||
Hanami::Assets::Compiler.compile(@config, 'compile-sass.css')
|
||||
Hanami::Assets::Compiler.compile(@config, "compile-sass.css")
|
||||
|
||||
expect(directory.exist?).to eq(true)
|
||||
end
|
||||
|
||||
it 'compiles scss asset if direct dependency has changed' do
|
||||
dependency = TestFile.new(path: '_background.scss') do
|
||||
write 'body { background-color: purple; }'
|
||||
it "compiles scss asset if direct dependency has changed" do
|
||||
dependency = TestFile.new(path: "_background.scss") do
|
||||
write "body { background-color: purple; }"
|
||||
end
|
||||
|
||||
Hanami::Assets::Compiler.compile(@config, 'scss-dependencies.css')
|
||||
Hanami::Assets::Compiler.compile(@config, "scss-dependencies.css")
|
||||
|
||||
target = @config.public_directory.join('assets', 'scss-dependencies.css')
|
||||
target = @config.public_directory.join("assets", "scss-dependencies.css")
|
||||
content = target.read
|
||||
expect(content).to match %(body {\n background-color: purple; }\n)
|
||||
|
||||
dependency.touch('body { background-color: turquoise; }') do
|
||||
Hanami::Assets::Compiler.compile(@config, 'scss-dependencies.css')
|
||||
dependency.touch("body { background-color: turquoise; }") do
|
||||
Hanami::Assets::Compiler.compile(@config, "scss-dependencies.css")
|
||||
content = target.read
|
||||
expect(content).to match %(body {\n background-color: turquoise; }\n)
|
||||
end
|
||||
end
|
||||
|
||||
if CI.enabled?
|
||||
it 'compiles scss asset if transitive dependency has changed'
|
||||
it "compiles scss asset if transitive dependency has changed"
|
||||
else
|
||||
it 'compiles scss asset if transitive dependency has changed' do
|
||||
dependency = TestFile.new(path: '_grid.scss') do
|
||||
write 'body { padding: 0; }'
|
||||
it "compiles scss asset if transitive dependency has changed" do
|
||||
dependency = TestFile.new(path: "_grid.scss") do
|
||||
write "body { padding: 0; }"
|
||||
end
|
||||
|
||||
Hanami::Assets::Compiler.compile(@config, 'scss-transitive-dependencies.css')
|
||||
Hanami::Assets::Compiler.compile(@config, "scss-transitive-dependencies.css")
|
||||
|
||||
target = @config.public_directory.join('assets', 'scss-transitive-dependencies.css')
|
||||
target = @config.public_directory.join("assets", "scss-transitive-dependencies.css")
|
||||
content = target.read
|
||||
expect(content).to match %(body {\n padding: 0; }\n)
|
||||
|
||||
dependency.touch('body { padding: 1; }') do
|
||||
Hanami::Assets::Compiler.compile(@config, 'scss-transitive-dependencies.css')
|
||||
dependency.touch("body { padding: 1; }") do
|
||||
Hanami::Assets::Compiler.compile(@config, "scss-transitive-dependencies.css")
|
||||
content = target.read
|
||||
expect(content).to match %(body {\n padding: 1; }\n)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'copies unknown asset' do
|
||||
Hanami::Assets::Compiler.compile(@config, 'style.foobar')
|
||||
it "copies unknown asset" do
|
||||
Hanami::Assets::Compiler.compile(@config, "style.foobar")
|
||||
|
||||
target = @config.public_directory.join('assets', 'style.foobar')
|
||||
target = @config.public_directory.join("assets", "style.foobar")
|
||||
content = target.read
|
||||
expect(content).to eq("This is a foobar file.\n")
|
||||
end
|
||||
|
||||
it 'copies unknown asset in folder with a dot in it' do
|
||||
Hanami::Assets::Compiler.compile(@config, 'other_style.foobar')
|
||||
it "copies unknown asset in folder with a dot in it" do
|
||||
Hanami::Assets::Compiler.compile(@config, "other_style.foobar")
|
||||
|
||||
target = @config.public_directory.join('assets', 'other_style.foobar')
|
||||
target = @config.public_directory.join("assets", "other_style.foobar")
|
||||
content = target.read
|
||||
expect(content).to eq("This is a foobar file.\n")
|
||||
end
|
||||
|
||||
it "won't compile/copy if the source hasn't changed" do
|
||||
Hanami::Assets::Compiler.compile(@config, 'unchanged.js')
|
||||
Hanami::Assets::Compiler.compile(@config, "unchanged.js")
|
||||
|
||||
compiled = @config.public_directory.join('assets', 'unchanged.js')
|
||||
compiled = @config.public_directory.join("assets", "unchanged.js")
|
||||
content = compiled.read
|
||||
modified_at = compiled.mtime
|
||||
|
||||
|
@ -264,15 +266,15 @@ describe 'Compiler' do
|
|||
|
||||
sleep 1
|
||||
|
||||
Hanami::Assets::Compiler.compile(@config, 'unchanged.js')
|
||||
compiled = @config.public_directory.join('assets', 'unchanged.js')
|
||||
Hanami::Assets::Compiler.compile(@config, "unchanged.js")
|
||||
compiled = @config.public_directory.join("assets", "unchanged.js")
|
||||
|
||||
expect(compiled.read).to include %(alert("Still the same");)
|
||||
expect(compiled.mtime.to_i).to eq(modified_at.to_i)
|
||||
end
|
||||
|
||||
it 'truncates files when copying from source to destination' do
|
||||
source = @config.root.join('javascripts', 'truncate.js')
|
||||
it "truncates files when copying from source to destination" do
|
||||
source = @config.root.join("javascripts", "truncate.js")
|
||||
|
||||
begin
|
||||
source.delete if source.exist?
|
||||
|
@ -283,9 +285,9 @@ describe 'Compiler' do
|
|||
file.write content
|
||||
end
|
||||
|
||||
Hanami::Assets::Compiler.compile(@config, 'truncate.js')
|
||||
Hanami::Assets::Compiler.compile(@config, "truncate.js")
|
||||
|
||||
compiled = @config.public_directory.join('assets', 'truncate.js')
|
||||
compiled = @config.public_directory.join("assets", "truncate.js")
|
||||
expect(compiled.read).to eq(content)
|
||||
|
||||
sleep 1
|
||||
|
@ -295,33 +297,33 @@ describe 'Compiler' do
|
|||
file.write content
|
||||
end
|
||||
|
||||
Hanami::Assets::Compiler.compile(@config, 'truncate.js')
|
||||
Hanami::Assets::Compiler.compile(@config, "truncate.js")
|
||||
|
||||
compiled = @config.public_directory.join('assets', 'truncate.js')
|
||||
compiled = @config.public_directory.join("assets", "truncate.js")
|
||||
expect(compiled.read).to eq(content)
|
||||
ensure
|
||||
source.delete if source.exist?
|
||||
end
|
||||
end
|
||||
|
||||
it 'raises an error in case of missing source' do
|
||||
sources = @config.sources.map(&:to_s).join(', ')
|
||||
it "raises an error in case of missing source" do
|
||||
sources = @config.sources.map(&:to_s).join(", ")
|
||||
expect do
|
||||
Hanami::Assets::Compiler.compile(@config, 'missing.js')
|
||||
Hanami::Assets::Compiler.compile(@config, "missing.js")
|
||||
end.to raise_error(Hanami::Assets::MissingAsset,
|
||||
"Missing asset: `missing.js' (sources: #{sources})")
|
||||
end
|
||||
|
||||
it 'raises an error in case of unknown compiler engine' do
|
||||
it "raises an error in case of unknown compiler engine" do
|
||||
expect do
|
||||
Hanami::Assets::Compiler.compile(@config, 'ouch.js')
|
||||
Hanami::Assets::Compiler.compile(@config, "ouch.js")
|
||||
end.to raise_error(Hanami::Assets::UnknownAssetEngine,
|
||||
"No asset engine registered for `ouch.js.unknown'")
|
||||
end
|
||||
|
||||
it 'ignores hidden files beginning with a dot' do
|
||||
it "ignores hidden files beginning with a dot" do
|
||||
expect do
|
||||
Hanami::Assets::Compiler.compile(@config, 'hidden.css')
|
||||
Hanami::Assets::Compiler.compile(@config, "hidden.css")
|
||||
end.to raise_error(Hanami::Assets::MissingAsset)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
RSpec.describe 'Fingerprint mode' do
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe "Fingerprint mode" do
|
||||
before do
|
||||
dest.rmtree if dest.exist?
|
||||
dest.mkpath
|
||||
|
@ -14,15 +16,15 @@ RSpec.describe 'Fingerprint mode' do
|
|||
end
|
||||
end
|
||||
|
||||
let(:dest) { TMP.join('bookshelf', 'public') }
|
||||
let(:dest) { TMP.join("bookshelf", "public") }
|
||||
|
||||
it 'uses fingerprinted relative urls' do
|
||||
it "uses fingerprinted relative urls" do
|
||||
rendered = Web::Views::Books::Show.render(format: :html)
|
||||
expect(rendered).to match %(<script src="/assets/jquery-05277a4edea56b7f82a4c1442159e183.js" type="text/javascript"></script>)
|
||||
expect(rendered).to match %(<script src="/assets/application-d1829dc353b734e3adc24855693b70f9.js" type="text/javascript"></script>)
|
||||
end
|
||||
|
||||
it 'raises error when referencing missing asset' do
|
||||
it "raises error when referencing missing asset" do
|
||||
expect { Web::Views::Users::Show.render(format: :html) }
|
||||
.to raise_error(Hanami::Assets::MissingManifestAssetError,
|
||||
"Can't find asset `/assets/missing.js' in manifest (#{Hanami::Assets.configuration.manifest_path})")
|
||||
|
|
|
@ -1,45 +1,47 @@
|
|||
require 'digest'
|
||||
require 'open3'
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe 'Precompile' do
|
||||
require "digest"
|
||||
require "open3"
|
||||
|
||||
describe "Precompile" do
|
||||
before do
|
||||
dest.rmtree if dest.exist?
|
||||
dest.mkpath
|
||||
end
|
||||
|
||||
let(:dest) { TMP }
|
||||
let(:target) { dest.join('assets') }
|
||||
let(:target) { dest.join("assets") }
|
||||
|
||||
let(:vendor_files) { %w[robots.txt].map { |file| dest.join(file) } }
|
||||
|
||||
describe 'standalone framework' do
|
||||
let(:dest) { TMP.join('standalone', 'public') }
|
||||
describe "standalone framework" do
|
||||
let(:dest) { TMP.join("standalone", "public") }
|
||||
|
||||
let(:assets) do
|
||||
['users.js']
|
||||
["users.js"]
|
||||
end
|
||||
|
||||
let(:environment) { "#{__dir__}/../../../support/fixtures/standalone/config/environment.rb" }
|
||||
|
||||
it 'precompiles assets' do
|
||||
it "precompiles assets" do
|
||||
expect_successful_command environment
|
||||
expect_successful_output(assets)
|
||||
end
|
||||
|
||||
describe 'when already precompiled ' do
|
||||
it 'cleans up the destination directory before to precompile' do
|
||||
describe "when already precompiled " do
|
||||
it "cleans up the destination directory before to precompile" do
|
||||
2.times do
|
||||
expect_successful_command environment
|
||||
end
|
||||
|
||||
duplicated_manifests = Dir[dest.join('assets-*.json').to_s]
|
||||
duplicated_manifests = Dir[dest.join("assets-*.json").to_s]
|
||||
expect(duplicated_manifests.count).to eq(0)
|
||||
expect(dest.join(target).exist?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when public directory or public/assets contains some files' do
|
||||
it 'keeps this files' do
|
||||
describe "when public directory or public/assets contains some files" do
|
||||
it "keeps this files" do
|
||||
expect_successful_command environment
|
||||
vendor_files.each { |file| FileUtils.touch file }
|
||||
expect_successful_command environment
|
||||
|
@ -59,48 +61,48 @@ describe 'Precompile' do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'duplicated frameworks' do
|
||||
let(:dest) { TMP.join('bookshelf', 'public') }
|
||||
describe "duplicated frameworks" do
|
||||
let(:dest) { TMP.join("bookshelf", "public") }
|
||||
|
||||
let(:assets) do
|
||||
['jquery.js',
|
||||
'bookshelf.jpg',
|
||||
'ember.js', # this is a duplicate
|
||||
'ember.min.js', # this is a duplicate
|
||||
'ember-source.js', # this is a duplicate
|
||||
'application.js',
|
||||
'admin/ember.js', # this is a duplicate
|
||||
'admin/ember.min.js', # this is a duplicate
|
||||
'admin/ember-source.js', # this is a duplicate
|
||||
'admin/zepto.js',
|
||||
'admin/application.js',
|
||||
'metrics/ember.js',
|
||||
'metrics/ember.min.js',
|
||||
'metrics/ember-source.js',
|
||||
'metrics/dashboard.js']
|
||||
["jquery.js",
|
||||
"bookshelf.jpg",
|
||||
"ember.js", # this is a duplicate
|
||||
"ember.min.js", # this is a duplicate
|
||||
"ember-source.js", # this is a duplicate
|
||||
"application.js",
|
||||
"admin/ember.js", # this is a duplicate
|
||||
"admin/ember.min.js", # this is a duplicate
|
||||
"admin/ember-source.js", # this is a duplicate
|
||||
"admin/zepto.js",
|
||||
"admin/application.js",
|
||||
"metrics/ember.js",
|
||||
"metrics/ember.min.js",
|
||||
"metrics/ember-source.js",
|
||||
"metrics/dashboard.js"]
|
||||
end
|
||||
|
||||
let(:environment) { "#{__dir__}/../../../support/fixtures/bookshelf/config/environment.rb" }
|
||||
|
||||
it 'precompiles assets' do
|
||||
it "precompiles assets" do
|
||||
expect_successful_command environment
|
||||
expect_successful_output(assets)
|
||||
end
|
||||
|
||||
describe 'when already precompiled ' do
|
||||
it 'cleans up the destination directory before to precompile' do
|
||||
describe "when already precompiled " do
|
||||
it "cleans up the destination directory before to precompile" do
|
||||
2.times do
|
||||
expect_successful_command environment
|
||||
end
|
||||
|
||||
duplicated_manifests = Dir[dest.join('assets-*.json').to_s]
|
||||
duplicated_manifests = Dir[dest.join("assets-*.json").to_s]
|
||||
expect(duplicated_manifests.count).to eq(0)
|
||||
expect(dest.join(target).exist?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when public directory or public/assets contains some files' do
|
||||
it 'keeps this files' do
|
||||
describe "when public directory or public/assets contains some files" do
|
||||
it "keeps this files" do
|
||||
expect_successful_command environment
|
||||
vendor_files.each { |file| FileUtils.touch file }
|
||||
expect_successful_command environment
|
||||
|
@ -121,14 +123,14 @@ describe 'Precompile' do
|
|||
end
|
||||
|
||||
describe "when 'config' is omitted" do
|
||||
it 'raises error and exit' do
|
||||
expect_failing_command '', 'You must specify a configuration file'
|
||||
it "raises error and exit" do
|
||||
expect_failing_command "", "You must specify a configuration file"
|
||||
end
|
||||
end
|
||||
|
||||
describe "when 'config' points to a non-existing file" do
|
||||
it 'raises error and exit' do
|
||||
expect_failing_command '--config=path/to/missing.rb', 'Cannot find configuration file: path/to/missing.rb'
|
||||
it "raises error and exit" do
|
||||
expect_failing_command "--config=path/to/missing.rb", "Cannot find configuration file: path/to/missing.rb"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -149,7 +151,7 @@ describe 'Precompile' do
|
|||
expect(result).to be_exist
|
||||
|
||||
checksum = Digest::MD5.file(result)
|
||||
filename = ::File.basename(asset, '.*')
|
||||
filename = ::File.basename(asset, ".*")
|
||||
ext = ::File.extname(asset)
|
||||
directory = Pathname.new(::File.dirname(asset))
|
||||
expect(target.join(directory, "#{filename}-#{checksum}#{ext}")).to be_exist
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
describe 'Rendering test' do
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe "Rendering test" do
|
||||
before do
|
||||
Hanami::Assets.configuration.reset!
|
||||
end
|
||||
|
@ -8,115 +10,115 @@ describe 'Rendering test' do
|
|||
Thread.current[:__hanami_assets] = nil
|
||||
end
|
||||
|
||||
describe 'with defaults' do
|
||||
describe "with defaults" do
|
||||
let(:result) { DefaultView.new.render }
|
||||
|
||||
it 'resolves javascript tag' do
|
||||
it "resolves javascript tag" do
|
||||
expect(result).to include %(<script src="/assets/feature-a.js" type="text/javascript"></script>)
|
||||
end
|
||||
|
||||
it 'resolves stylesheet tag' do
|
||||
it "resolves stylesheet tag" do
|
||||
expect(result).to include %(<link href="/assets/main.css" type="text/css" rel="stylesheet">)
|
||||
end
|
||||
|
||||
it 'stores assets in thread local' do
|
||||
it "stores assets in thread local" do
|
||||
result
|
||||
assets = Thread.current[:__hanami_assets]
|
||||
expect(assets).to be_kind_of(Hash)
|
||||
expect(assets.fetch('/assets/main.css')).to eq(as: :style, crossorigin: false)
|
||||
expect(assets.fetch('/assets/feature-a.js')).to eq(as: :script, crossorigin: false)
|
||||
expect(assets.fetch("/assets/main.css")).to eq(as: :style, crossorigin: false)
|
||||
expect(assets.fetch("/assets/feature-a.js")).to eq(as: :script, crossorigin: false)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with custom assets prefix' do
|
||||
describe "with custom assets prefix" do
|
||||
let(:result) { CustomAssetsPrefix.new.render }
|
||||
before do
|
||||
Hanami::Assets.configure do
|
||||
prefix '/assets/prefix'
|
||||
prefix "/assets/prefix"
|
||||
end
|
||||
end
|
||||
|
||||
it 'resolves javascript tag under configured path' do
|
||||
it "resolves javascript tag under configured path" do
|
||||
expect(result).to include %(<script src="/assets/prefix/feature-a.js" type="text/javascript"></script>)
|
||||
end
|
||||
|
||||
it 'resolves stylesheet tag under configured path' do
|
||||
it "resolves stylesheet tag under configured path" do
|
||||
expect(result).to include %(<link href="/assets/prefix/main.css" type="text/css" rel="stylesheet">)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with multiple assets' do
|
||||
describe "with multiple assets" do
|
||||
let(:result) { RenderMultipleAssets.new.render }
|
||||
|
||||
it 'resolves javascript tags' do
|
||||
it "resolves javascript tags" do
|
||||
expect(result).to include %(<script src="/assets/feature-a.js" type="text/javascript"></script>)
|
||||
expect(result).to include %(<script src="/assets/feature-b.js" type="text/javascript"></script>)
|
||||
end
|
||||
|
||||
it 'resolves stylesheets tag' do
|
||||
it "resolves stylesheets tag" do
|
||||
expect(result).to include %(<link href="/assets/grid.css" type="text/css" rel="stylesheet">)
|
||||
expect(result).to include %(<link href="/assets/main.css" type="text/css" rel="stylesheet">)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with absolute url' do
|
||||
describe "with absolute url" do
|
||||
before do
|
||||
Hanami::Assets.configuration.load!
|
||||
end
|
||||
|
||||
let(:result) { AbsoluteUrlsView.new.render }
|
||||
|
||||
it 'resolves javascript tag' do
|
||||
it "resolves javascript tag" do
|
||||
expect(result).to include %(<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js" type="text/javascript"></script>)
|
||||
end
|
||||
|
||||
it 'resolves stylesheets tag' do
|
||||
it "resolves stylesheets tag" do
|
||||
expect(result).to include %(<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" type="text/css" rel="stylesheet">)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with assets that need to be preprocessed' do
|
||||
describe 'javascripts' do
|
||||
describe "with assets that need to be preprocessed" do
|
||||
describe "javascripts" do
|
||||
let(:result) { CompilerView.new.render }
|
||||
|
||||
it 'renders script tag for pure javascript source file' do
|
||||
it "renders script tag for pure javascript source file" do
|
||||
expect(result).to include %(<script src="/assets/greet.js" type="text/javascript"></script>)
|
||||
end
|
||||
|
||||
it 'renders script tag for pure javascript source file from nested path' do
|
||||
it "renders script tag for pure javascript source file from nested path" do
|
||||
expect(result).to include %(<script src="/assets/bootstrap.js" type="text/javascript"></script>)
|
||||
end
|
||||
|
||||
it 'renders script tag for coffeescript source file from nested path' do
|
||||
it "renders script tag for coffeescript source file from nested path" do
|
||||
expect(result).to include %(<script src="/assets/hello.js" type="text/javascript"></script>)
|
||||
end
|
||||
|
||||
it 'renders script tag for es6 source file from nested path' do
|
||||
it "renders script tag for es6 source file from nested path" do
|
||||
expect(result).to include %(<script src="/assets/person.js" type="text/javascript"></script>)
|
||||
end
|
||||
|
||||
it 'renders script tag for babel source file from nested path' do
|
||||
it "renders script tag for babel source file from nested path" do
|
||||
expect(result).to include %(<script src="/assets/country.js" type="text/javascript"></script>)
|
||||
end
|
||||
|
||||
it 'renders script tag for jsx source file from nested path' do
|
||||
it "renders script tag for jsx source file from nested path" do
|
||||
expect(result).to include %(<script src="/assets/react-component.js" type="text/javascript"></script>)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'stylesheets' do
|
||||
describe "stylesheets" do
|
||||
let(:result) { CssCompilerView.new.render }
|
||||
|
||||
it 'renders link tag for sass source file' do
|
||||
it "renders link tag for sass source file" do
|
||||
expect(result).to include %(<link href="/assets/compile-sass.css" type="text/css" rel="stylesheet">)
|
||||
end
|
||||
|
||||
it 'renders link tag for scss source file' do
|
||||
it "renders link tag for scss source file" do
|
||||
expect(result).to include %(<link href="/assets/compile-scss.css" type="text/css" rel="stylesheet">)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'unknown engine' do
|
||||
describe "unknown engine" do
|
||||
it "doesn't raise error but still render it" do
|
||||
result = UnknownAssetEngineView.new.render
|
||||
expect(result).to include %(<script src="/assets/ouch.js" type="text/javascript"></script>)
|
||||
|
@ -124,7 +126,7 @@ describe 'Rendering test' do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'missing assets' do
|
||||
describe "missing assets" do
|
||||
it "doesn't raise error but still render it" do
|
||||
result = MissingAssetSourceView.new.render
|
||||
expect(result).to include %(<script src="/assets/missing.js" type="text/javascript"></script>)
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require __dir__ + "/../../../support/fixtures/bookshelf/config/environment"
|
||||
|
||||
describe 'Third part gems integration' do
|
||||
describe "Third part gems integration" do
|
||||
before do
|
||||
load __dir__ + "/../../../support/fixtures/hanami-emberjs/lib/hanami/emberjs.rb"
|
||||
end
|
||||
|
||||
it 'renders assets from a third part gem' do
|
||||
it "renders assets from a third part gem" do
|
||||
rendered = Metrics::Views::Dashboard::Index.render(format: :html)
|
||||
expect(rendered).to include %(<script src="/assets/metrics/ember.js" type="text/javascript"></script>)
|
||||
expect(rendered).to include %(<script src="/assets/metrics/dashboard.js" type="text/javascript"></script>)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require __dir__ + "/../../../support/fixtures/bookshelf/config/environment"
|
||||
|
||||
describe 'Hanami::View integration' do
|
||||
describe "Hanami::View integration" do
|
||||
before do
|
||||
frameworks = [Web::Assets, Admin::Assets]
|
||||
frameworks.each do |framework|
|
||||
|
@ -10,13 +12,13 @@ describe 'Hanami::View integration' do
|
|||
end
|
||||
end
|
||||
|
||||
it 'renders assets from the root path' do
|
||||
it "renders assets from the root path" do
|
||||
rendered = Web::Views::Books::Show.render(format: :html)
|
||||
expect(rendered).to include %(<script src="/assets/jquery.js" type="text/javascript"></script>)
|
||||
expect(rendered).to include %(<script src="/assets/application.js" type="text/javascript"></script>)
|
||||
end
|
||||
|
||||
it 'renders assets from a nested path' do
|
||||
it "renders assets from a nested path" do
|
||||
rendered = Admin::Views::Users::Index.render(format: :html)
|
||||
expect(rendered).to include %(<script src="/assets/admin/zepto.js" type="text/javascript"></script>)
|
||||
expect(rendered).to include %(<script src="/assets/admin/application.js" type="text/javascript"></script>)
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
if ENV['COVERALL']
|
||||
require 'coveralls'
|
||||
# frozen_string_literal: true
|
||||
|
||||
if ENV["COVERALL"]
|
||||
require "coveralls"
|
||||
Coveralls.wear!
|
||||
end
|
||||
|
||||
$LOAD_PATH.unshift 'lib'
|
||||
$LOAD_PATH.unshift 'spec'
|
||||
require 'hanami/assets'
|
||||
require 'support/test_file'
|
||||
require 'support/ci'
|
||||
require 'support/fixtures'
|
||||
require 'pathname'
|
||||
$LOAD_PATH.unshift "lib"
|
||||
$LOAD_PATH.unshift "spec"
|
||||
require "hanami/assets"
|
||||
require "support/test_file"
|
||||
require "support/ci"
|
||||
require "support/fixtures"
|
||||
require "pathname"
|
||||
|
||||
TMP = Pathname.new(__dir__).join('..', 'tmp')
|
||||
TMP = Pathname.new(__dir__).join("..", "tmp")
|
||||
TMP.mkpath
|
||||
|
||||
Hanami::Utils::LoadPaths.class_eval do
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module CI
|
||||
def self.enabled?
|
||||
ENV['TRAVIS']
|
||||
ENV["TRAVIS"]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
require 'erb'
|
||||
require 'sass'
|
||||
require 'coffee_script'
|
||||
require 'hanami/view'
|
||||
require 'tilt/erb'
|
||||
require 'tilt/babel'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "erb"
|
||||
require "sass"
|
||||
require "coffee_script"
|
||||
require "hanami/view"
|
||||
require "tilt/erb"
|
||||
require "tilt/babel"
|
||||
|
||||
module View
|
||||
def self.included(base)
|
||||
|
@ -15,7 +17,7 @@ module View
|
|||
|
||||
module ClassMethods
|
||||
def template
|
||||
__dir__ + '/fixtures/template.erb'
|
||||
__dir__ + "/fixtures/template.erb"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -34,7 +36,7 @@ class DefaultView
|
|||
include View
|
||||
|
||||
def self.template
|
||||
__dir__ + '/fixtures/template.erb'
|
||||
__dir__ + "/fixtures/template.erb"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -50,7 +52,7 @@ class RenderMultipleAssets
|
|||
include View
|
||||
|
||||
def self.template
|
||||
__dir__ + '/fixtures/multi-template.erb'
|
||||
__dir__ + "/fixtures/multi-template.erb"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -58,7 +60,7 @@ class AbsoluteUrlsView
|
|||
include View
|
||||
|
||||
def self.template
|
||||
__dir__ + '/fixtures/absolute-urls-template.erb'
|
||||
__dir__ + "/fixtures/absolute-urls-template.erb"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -66,7 +68,7 @@ class CompilerView
|
|||
include View
|
||||
|
||||
def self.template
|
||||
__dir__ + '/fixtures/compiler-template.erb'
|
||||
__dir__ + "/fixtures/compiler-template.erb"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -74,7 +76,7 @@ class MissingAssetSourceView
|
|||
include View
|
||||
|
||||
def self.template
|
||||
__dir__ + '/fixtures/missing-asset-source.erb'
|
||||
__dir__ + "/fixtures/missing-asset-source.erb"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -82,7 +84,7 @@ class UnknownAssetEngineView
|
|||
include View
|
||||
|
||||
def self.template
|
||||
__dir__ + '/fixtures/unknown-asset-engine.erb'
|
||||
__dir__ + "/fixtures/unknown-asset-engine.erb"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -90,7 +92,7 @@ class UnchangedCompilerView
|
|||
include View
|
||||
|
||||
def self.template
|
||||
__dir__ + '/fixtures/unchanged-asset.erb'
|
||||
__dir__ + "/fixtures/unchanged-asset.erb"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -98,7 +100,7 @@ class CssCompilerView
|
|||
include View
|
||||
|
||||
def self.template
|
||||
__dir__ + '/fixtures/compile-css.erb'
|
||||
__dir__ + "/fixtures/compile-css.erb"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -106,7 +108,7 @@ class HiddenAssetCompilerView
|
|||
include View
|
||||
|
||||
def self.template
|
||||
__dir__ + '/fixtures/hidden-asset.erb'
|
||||
__dir__ + "/fixtures/hidden-asset.erb"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "rubygems"
|
||||
require "bundler/setup"
|
||||
require "hanami/view"
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
source 'https://rubygems.org'
|
||||
# frozen_string_literal: true
|
||||
|
||||
source "https://rubygems.org"
|
||||
|
||||
# Specify your gem's dependencies in hanami-compass.gemspec
|
||||
gemspec
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
require 'bundler/gem_tasks'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "bundler/gem_tasks"
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'bundler/setup'
|
||||
require 'hanami/compass'
|
||||
require "bundler/setup"
|
||||
require "hanami/compass"
|
||||
|
||||
# You can add fixtures and/or initialization code here to make experimenting
|
||||
# with your gem easier. You can also use a different console, if you like.
|
||||
|
@ -10,5 +11,5 @@ require 'hanami/compass'
|
|||
# require "pry"
|
||||
# Pry.start
|
||||
|
||||
require 'irb'
|
||||
require "irb"
|
||||
IRB.start
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
require 'hanami/assets'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "hanami/assets"
|
||||
|
||||
module Hanami
|
||||
module Compass
|
||||
require 'hanami/compass/version'
|
||||
require "hanami/compass/version"
|
||||
end
|
||||
end
|
||||
|
||||
Hanami::Assets.sources << __dir__ + '/compass/src'
|
||||
Hanami::Assets.sources << __dir__ + "/compass/src"
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Hanami
|
||||
module Compass
|
||||
VERSION = '0.1.0'.freeze
|
||||
VERSION = "0.1.0"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
source 'https://rubygems.org'
|
||||
# frozen_string_literal: true
|
||||
|
||||
source "https://rubygems.org"
|
||||
|
||||
# Specify your gem's dependencies in hanami-emberjs.gemspec
|
||||
gemspec
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
require 'bundler/gem_tasks'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "bundler/gem_tasks"
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'bundler/setup'
|
||||
require 'hanami/emberjs'
|
||||
require "bundler/setup"
|
||||
require "hanami/emberjs"
|
||||
|
||||
# You can add fixtures and/or initialization code here to make experimenting
|
||||
# with your gem easier. You can also use a different console, if you like.
|
||||
|
@ -10,5 +11,5 @@ require 'hanami/emberjs'
|
|||
# require "pry"
|
||||
# Pry.start
|
||||
|
||||
require 'irb'
|
||||
require "irb"
|
||||
IRB.start
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
require 'hanami/assets'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "hanami/assets"
|
||||
|
||||
module Hanami
|
||||
module Emberjs
|
||||
require 'hanami/emberjs/version'
|
||||
require "hanami/emberjs/version"
|
||||
end
|
||||
end
|
||||
|
||||
Hanami::Assets.sources << __dir__ + '/emberjs/dist'
|
||||
Hanami::Assets.sources << __dir__ + '/emberjs/source'
|
||||
Hanami::Assets.sources << __dir__ + "/emberjs/dist"
|
||||
Hanami::Assets.sources << __dir__ + "/emberjs/source"
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Hanami
|
||||
module Emberjs
|
||||
VERSION = '0.1.0'.freeze
|
||||
VERSION = "0.1.0"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
source 'https://rubygems.org'
|
||||
# frozen_string_literal: true
|
||||
|
||||
source "https://rubygems.org"
|
||||
|
||||
# Specify your gem's dependencies in hanami-foo-compressor.gemspec
|
||||
gemspec
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
require 'bundler/gem_tasks'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "bundler/gem_tasks"
|
||||
task default: :spec
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'bundler/setup'
|
||||
require 'hanami/foo/compressor'
|
||||
require "bundler/setup"
|
||||
require "hanami/foo/compressor"
|
||||
|
||||
# You can add fixtures and/or initialization code here to make experimenting
|
||||
# with your gem easier. You can also use a different console, if you like.
|
||||
|
@ -10,5 +11,5 @@ require 'hanami/foo/compressor'
|
|||
# require "pry"
|
||||
# Pry.start
|
||||
|
||||
require 'irb'
|
||||
require "irb"
|
||||
IRB.start
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
require 'hanami/assets/compressors/javascript'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "hanami/assets/compressors/javascript"
|
||||
|
||||
module Hanami
|
||||
module Assets
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
require 'hanami/assets/compressors/stylesheet'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "hanami/assets/compressors/stylesheet"
|
||||
|
||||
module Hanami
|
||||
module Assets
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
require 'hanami/foo/compressor/version'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "hanami/foo/compressor/version"
|
||||
|
||||
module Hanami
|
||||
module Foo
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Hanami
|
||||
module Foo
|
||||
module Compressor
|
||||
VERSION = '0.1.0'.freeze
|
||||
VERSION = "0.1.0"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "rubygems"
|
||||
require "bundler/setup"
|
||||
require "hanami/view"
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
require 'securerandom'
|
||||
require_relative 'ci'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "securerandom"
|
||||
require_relative "ci"
|
||||
|
||||
class TestFile
|
||||
OPEN_MODE = File::WRONLY | File::TRUNC | File::CREAT
|
||||
|
|
|
@ -1,20 +1,22 @@
|
|||
require 'hanami/assets/bundler'
|
||||
require 'hanami/assets/compressors/javascript'
|
||||
require 'hanami/assets/compressors/stylesheet'
|
||||
require 'etc'
|
||||
require 'json'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "hanami/assets/bundler"
|
||||
require "hanami/assets/compressors/javascript"
|
||||
require "hanami/assets/compressors/stylesheet"
|
||||
require "etc"
|
||||
require "json"
|
||||
|
||||
describe Hanami::Assets::Bundler do
|
||||
before do
|
||||
dest.rmtree if dest.exist?
|
||||
dest.mkpath
|
||||
|
||||
FileUtils.copy_entry(source, dest.join('assets'))
|
||||
FileUtils.copy_entry(source, dest.join("assets"))
|
||||
expect(config.public_directory).to eq(dest) # better safe than sorry ;-)
|
||||
end
|
||||
|
||||
[nil, :builtin, :yui, :uglifier, :closure, :sass].each do |compressor|
|
||||
describe (compressor || 'NullCompressor').to_s do # rubocop:disable Lint/ParenthesesAsGroupedExpression
|
||||
describe (compressor || "NullCompressor").to_s do # rubocop:disable Lint/ParenthesesAsGroupedExpression
|
||||
let(:config) do
|
||||
Hanami::Assets::Configuration.new.tap do |c|
|
||||
c.public_directory dest
|
||||
|
@ -24,10 +26,10 @@ describe Hanami::Assets::Bundler do
|
|||
end
|
||||
end
|
||||
|
||||
let(:dest) { TMP.join('deploy', 'public') }
|
||||
let(:dest) { TMP.join("deploy", "public") }
|
||||
let(:source) { __dir__ + "/../../../support/fixtures/deploy/public/assets" }
|
||||
|
||||
it 'compresses javascripts' do
|
||||
it "compresses javascripts" do
|
||||
run!
|
||||
|
||||
assets(:js).each do |original, current|
|
||||
|
@ -35,7 +37,7 @@ describe Hanami::Assets::Bundler do
|
|||
end
|
||||
end
|
||||
|
||||
it 'compresses stylesheets' do
|
||||
it "compresses stylesheets" do
|
||||
run!
|
||||
|
||||
assets(:css).each do |original, current|
|
||||
|
@ -43,7 +45,7 @@ describe Hanami::Assets::Bundler do
|
|||
end
|
||||
end
|
||||
|
||||
it 'copies other assets' do
|
||||
it "copies other assets" do
|
||||
run!
|
||||
|
||||
assets(:png).each do |original, current|
|
||||
|
@ -52,10 +54,10 @@ describe Hanami::Assets::Bundler do
|
|||
end
|
||||
end
|
||||
|
||||
it 'generates manifest' do
|
||||
it "generates manifest" do
|
||||
run!
|
||||
|
||||
manifest = dest.join('assets.json')
|
||||
manifest = dest.join("assets.json")
|
||||
expect(manifest).to be_exist
|
||||
|
||||
expect_owner(manifest)
|
||||
|
@ -79,21 +81,21 @@ describe Hanami::Assets::Bundler do
|
|||
end
|
||||
end
|
||||
|
||||
it 'ensures intermediate directories to be created' do
|
||||
it "ensures intermediate directories to be created" do
|
||||
dest.rmtree if dest.exist?
|
||||
|
||||
run!
|
||||
|
||||
manifest = dest.join('assets.json')
|
||||
manifest = dest.join("assets.json")
|
||||
expect(manifest).to be_exist
|
||||
end
|
||||
|
||||
if compressor == :yui
|
||||
describe 'in case of error' do
|
||||
let(:dest) { TMP.join('broken', 'public') }
|
||||
let(:source) { __dir__ + '/../../../support/fixtures/broken/public/assets' }
|
||||
describe "in case of error" do
|
||||
let(:dest) { TMP.join("broken", "public") }
|
||||
let(:source) { __dir__ + "/../../../support/fixtures/broken/public/assets" }
|
||||
|
||||
it 'prints the name of the asset that caused the problem' do
|
||||
it "prints the name of the asset that caused the problem" do
|
||||
expect { run! }.to output(/Skipping compression of:/).to_stderr
|
||||
end
|
||||
end
|
||||
|
@ -164,7 +166,7 @@ describe Hanami::Assets::Bundler do
|
|||
|
||||
def expect_permissions(file)
|
||||
stat = ::File::Stat.new(file)
|
||||
expect(stat.mode.to_s(8)).to eq('100644')
|
||||
expect(stat.mode.to_s(8)).to eq("100644")
|
||||
end
|
||||
|
||||
def expect_same_asset(original, current)
|
||||
|
@ -177,8 +179,8 @@ describe Hanami::Assets::Bundler do
|
|||
|
||||
def compress(compressor, file)
|
||||
case File.extname(file)
|
||||
when '.js' then Hanami::Assets::Compressors::Javascript.for(compressor)
|
||||
when '.css' then Hanami::Assets::Compressors::Stylesheet.for(compressor)
|
||||
when ".js" then Hanami::Assets::Compressors::Javascript.for(compressor)
|
||||
when ".css" then Hanami::Assets::Compressors::Stylesheet.for(compressor)
|
||||
# when ".js" then YUI::JavaScriptCompressor.new(munge: true)
|
||||
# when ".css" then YUI::CssCompressor.new
|
||||
end.compress(::File.read(file))
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
require 'hanami/assets/cache'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "hanami/assets/cache"
|
||||
|
||||
RSpec.describe Hanami::Assets::Cache do
|
||||
let(:cache) { Hanami::Assets::Cache.new }
|
||||
|
||||
describe '#modified?' do
|
||||
describe "#modified?" do
|
||||
it "returns false when the stored file wasn't updated" do
|
||||
file = TestFile.new
|
||||
cache.store(file)
|
||||
|
@ -11,7 +13,7 @@ RSpec.describe Hanami::Assets::Cache do
|
|||
expect(cache.modified?(file)).not_to eq(true)
|
||||
end
|
||||
|
||||
it 'returns true when the file was updated after the last check' do
|
||||
it "returns true when the file was updated after the last check" do
|
||||
file = TestFile.new
|
||||
cache.store(file)
|
||||
|
||||
|
@ -20,13 +22,13 @@ RSpec.describe Hanami::Assets::Cache do
|
|||
end
|
||||
end
|
||||
|
||||
it 'returns true when the file was never stored' do
|
||||
it "returns true when the file was never stored" do
|
||||
file = TestFile.new
|
||||
|
||||
expect(cache.modified?(file)).to eq(true)
|
||||
end
|
||||
|
||||
describe 'with dependencies' do
|
||||
describe "with dependencies" do
|
||||
it "returns true when both file and deps weren't updated, but checking at the same timestamp" do
|
||||
file = TestFile.new
|
||||
deps = [TestFile.new]
|
||||
|
@ -35,7 +37,7 @@ RSpec.describe Hanami::Assets::Cache do
|
|||
expect(cache.modified?(file)).to eq(true)
|
||||
end
|
||||
|
||||
it 'returns true when at least one dependency was updated' do
|
||||
it "returns true when at least one dependency was updated" do
|
||||
file = TestFile.new
|
||||
deps = [dep = TestFile.new]
|
||||
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
require 'hanami/assets/compressors/builtin_stylesheet'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "hanami/assets/compressors/builtin_stylesheet"
|
||||
|
||||
describe Hanami::Assets::Compressors::BuiltinStylesheet do
|
||||
let(:compressor) { Hanami::Assets::Compressors::BuiltinStylesheet.new }
|
||||
|
||||
describe '#compress' do
|
||||
it 'compresses given file' do
|
||||
describe "#compress" do
|
||||
it "compresses given file" do
|
||||
asset = __dir__ + "/../../../../support/fixtures/reset.css"
|
||||
expected = File.read(__dir__ + '/../../../../support/fixtures/compressed-reset.css')
|
||||
expected = File.read(__dir__ + "/../../../../support/fixtures/compressed-reset.css")
|
||||
actual = compressor.compress(asset)
|
||||
|
||||
expect(actual).to eq(expected)
|
||||
|
|
|
@ -1,63 +1,65 @@
|
|||
require 'hanami/assets/compressors/javascript'
|
||||
require 'hanami/foo/compressor'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "hanami/assets/compressors/javascript"
|
||||
require "hanami/foo/compressor"
|
||||
|
||||
describe Hanami::Assets::Compressors::Javascript do
|
||||
describe '.for' do
|
||||
describe ".for" do
|
||||
let(:compressor) { Hanami::Assets::Compressors::Javascript.for(engine_name) }
|
||||
|
||||
describe 'when given argument is nil' do
|
||||
describe "when given argument is nil" do
|
||||
let(:engine_name) { nil }
|
||||
|
||||
it 'returns NullCompressor' do
|
||||
it "returns NullCompressor" do
|
||||
expect(compressor).to be_kind_of(Hanami::Assets::Compressors::NullCompressor)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when given argument is :yui' do
|
||||
describe "when given argument is :yui" do
|
||||
let(:engine_name) { :yui }
|
||||
|
||||
it 'returns YuiJavascript' do
|
||||
it "returns YuiJavascript" do
|
||||
expect(compressor).to be_kind_of(Hanami::Assets::Compressors::YuiJavascript)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when given argument is :uglifier' do
|
||||
describe "when given argument is :uglifier" do
|
||||
let(:engine_name) { :uglifier }
|
||||
|
||||
it 'returns UglifierJavascript' do
|
||||
it "returns UglifierJavascript" do
|
||||
expect(compressor).to be_kind_of(Hanami::Assets::Compressors::UglifierJavascript)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when given argument is :closure' do
|
||||
describe "when given argument is :closure" do
|
||||
let(:engine_name) { :closure }
|
||||
|
||||
it 'returns ClosureJavascript' do
|
||||
it "returns ClosureJavascript" do
|
||||
expect(compressor).to be_kind_of(Hanami::Assets::Compressors::ClosureJavascript)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when given argument is unknown symbol' do
|
||||
describe "when given argument is unknown symbol" do
|
||||
let(:engine_name) { :wat }
|
||||
|
||||
it 'raises error' do
|
||||
it "raises error" do
|
||||
expect { compressor }.to raise_error(Hanami::Assets::Compressors::UnknownCompressorError,
|
||||
'Unknown Javascript compressor: :wat')
|
||||
"Unknown Javascript compressor: :wat")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when third party gem' do
|
||||
describe "when third party gem" do
|
||||
let(:engine_name) { :foo }
|
||||
|
||||
it 'returns FooJavascript' do
|
||||
it "returns FooJavascript" do
|
||||
expect(compressor).to be_kind_of(Hanami::Assets::Compressors::FooJavascript)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when anything else' do
|
||||
describe "when anything else" do
|
||||
let(:engine_name) { CustomJavascriptCompressor.new }
|
||||
|
||||
it 'is returned as it is' do
|
||||
it "is returned as it is" do
|
||||
expect(compressor).to eq(engine_name)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,55 +1,57 @@
|
|||
require 'hanami/assets/compressors/stylesheet'
|
||||
require 'hanami/foo/compressor'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "hanami/assets/compressors/stylesheet"
|
||||
require "hanami/foo/compressor"
|
||||
|
||||
describe Hanami::Assets::Compressors::Stylesheet do
|
||||
describe '.for' do
|
||||
describe ".for" do
|
||||
let(:compressor) { Hanami::Assets::Compressors::Stylesheet.for(engine_name) }
|
||||
|
||||
describe 'when given argument is nil' do
|
||||
describe "when given argument is nil" do
|
||||
let(:engine_name) { nil }
|
||||
|
||||
it 'returns NullCompressor' do
|
||||
it "returns NullCompressor" do
|
||||
expect(compressor).to be_kind_of(Hanami::Assets::Compressors::NullCompressor)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when given argument is :yui' do
|
||||
describe "when given argument is :yui" do
|
||||
let(:engine_name) { :yui }
|
||||
|
||||
it 'returns YuiStylesheet' do
|
||||
it "returns YuiStylesheet" do
|
||||
expect(compressor).to be_kind_of(Hanami::Assets::Compressors::YuiStylesheet)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when given argument is :sass' do
|
||||
describe "when given argument is :sass" do
|
||||
let(:engine_name) { :sass }
|
||||
|
||||
it 'returns SassStylesheet' do
|
||||
it "returns SassStylesheet" do
|
||||
expect(compressor).to be_kind_of(Hanami::Assets::Compressors::SassStylesheet)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when given argument is unknown symbol' do
|
||||
describe "when given argument is unknown symbol" do
|
||||
let(:engine_name) { :wat }
|
||||
|
||||
it 'raises error' do
|
||||
it "raises error" do
|
||||
expect { compressor }.to raise_error(Hanami::Assets::Compressors::UnknownCompressorError,
|
||||
'Unknown Stylesheet compressor: :wat')
|
||||
"Unknown Stylesheet compressor: :wat")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when third party gem' do
|
||||
describe "when third party gem" do
|
||||
let(:engine_name) { :foo }
|
||||
|
||||
it 'returns FooStylesheet' do
|
||||
it "returns FooStylesheet" do
|
||||
expect(compressor).to be_kind_of(Hanami::Assets::Compressors::FooStylesheet)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when anything else' do
|
||||
describe "when anything else" do
|
||||
let(:engine_name) { CustomStylesheetCompressor.new }
|
||||
|
||||
it 'is returned as it is' do
|
||||
it "is returned as it is" do
|
||||
expect(compressor).to eq(engine_name)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
require 'pp'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "pp"
|
||||
|
||||
describe Hanami::Assets::Config::NullManifest do
|
||||
let(:configuration) { Hanami::Assets::Configuration.new }
|
||||
let(:manifest) { Hanami::Assets::Config::NullManifest.new(configuration) }
|
||||
|
||||
it 'is pretty printable' do
|
||||
it "is pretty printable" do
|
||||
expect { pp manifest }.to output(%r{Hanami::Assets::Config::NullManifest}).to_stdout
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
require 'hanami/assets/compressors/javascript'
|
||||
require 'hanami/assets/compressors/stylesheet'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "hanami/assets/compressors/javascript"
|
||||
require "hanami/assets/compressors/stylesheet"
|
||||
|
||||
describe Hanami::Assets::Configuration do
|
||||
before do
|
||||
|
@ -10,156 +12,156 @@ describe Hanami::Assets::Configuration do
|
|||
@configuration.reset!
|
||||
end
|
||||
|
||||
describe '#javascript_compressor' do
|
||||
describe 'default' do
|
||||
it 'is nil by default' do
|
||||
describe "#javascript_compressor" do
|
||||
describe "default" do
|
||||
it "is nil by default" do
|
||||
expect(@configuration.javascript_compressor).to be_nil
|
||||
end
|
||||
|
||||
it 'returns NullCompressor for internal usage' do
|
||||
it "returns NullCompressor for internal usage" do
|
||||
expect(@configuration.js_compressor).to be_kind_of(Hanami::Assets::Compressors::NullCompressor)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when :yui' do
|
||||
describe "when :yui" do
|
||||
before do
|
||||
@configuration.javascript_compressor :yui
|
||||
end
|
||||
|
||||
it 'returns value before to load configuration' do
|
||||
it "returns value before to load configuration" do
|
||||
expect(@configuration.javascript_compressor).to eq(:yui)
|
||||
end
|
||||
|
||||
it 'is instance of Hanami::Assets::Compressors::YuiJavascriptCompressor' do
|
||||
it "is instance of Hanami::Assets::Compressors::YuiJavascriptCompressor" do
|
||||
expect(@configuration.js_compressor).to be_kind_of(Hanami::Assets::Compressors::YuiJavascript)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when object' do
|
||||
describe "when object" do
|
||||
before do
|
||||
@configuration.javascript_compressor compressor
|
||||
end
|
||||
|
||||
let(:compressor) { CustomJavascriptCompressor.new }
|
||||
|
||||
it 'returns value before to load configuration' do
|
||||
it "returns value before to load configuration" do
|
||||
expect(@configuration.javascript_compressor).to eq(compressor)
|
||||
end
|
||||
|
||||
it 'returns value after loading' do
|
||||
it "returns value after loading" do
|
||||
expect(@configuration.js_compressor).to eq(compressor)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#stylesheet_compressor' do
|
||||
describe 'default' do
|
||||
it 'is nil by default' do
|
||||
describe "#stylesheet_compressor" do
|
||||
describe "default" do
|
||||
it "is nil by default" do
|
||||
expect(@configuration.stylesheet_compressor).to be_nil
|
||||
end
|
||||
|
||||
it 'returns NullCompressor when loaded' do
|
||||
it "returns NullCompressor when loaded" do
|
||||
expect(@configuration.css_compressor).to be_kind_of(Hanami::Assets::Compressors::NullCompressor)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when :yui' do
|
||||
describe "when :yui" do
|
||||
before do
|
||||
@configuration.stylesheet_compressor :yui
|
||||
end
|
||||
|
||||
it 'returns value before to load configuration' do
|
||||
it "returns value before to load configuration" do
|
||||
expect(@configuration.stylesheet_compressor).to eq(:yui)
|
||||
end
|
||||
|
||||
it 'is instance of Hanami::Assets::Compressors::YuiStylesheetCompressor' do
|
||||
it "is instance of Hanami::Assets::Compressors::YuiStylesheetCompressor" do
|
||||
expect(@configuration.css_compressor).to be_kind_of(Hanami::Assets::Compressors::YuiStylesheet)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when object' do
|
||||
describe "when object" do
|
||||
before do
|
||||
@configuration.stylesheet_compressor compressor
|
||||
end
|
||||
|
||||
let(:compressor) { CustomStylesheetCompressor.new }
|
||||
|
||||
it 'returns value before to load configuration' do
|
||||
it "returns value before to load configuration" do
|
||||
expect(@configuration.css_compressor).to eq(compressor)
|
||||
end
|
||||
|
||||
it 'returns value after loading' do
|
||||
it "returns value after loading" do
|
||||
expect(@configuration.css_compressor).to eq(compressor)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#subresource_integrity' do
|
||||
it 'is false by default' do
|
||||
describe "#subresource_integrity" do
|
||||
it "is false by default" do
|
||||
expect(@configuration.subresource_integrity).to eq(false)
|
||||
end
|
||||
|
||||
it 'allows to set to true, with default of SHA256' do
|
||||
it "allows to set to true, with default of SHA256" do
|
||||
@configuration.subresource_integrity true
|
||||
expect(@configuration.subresource_integrity).to eq(true)
|
||||
end
|
||||
|
||||
it 'allows to set a symbol' do
|
||||
it "allows to set a symbol" do
|
||||
@configuration.subresource_integrity :sha384
|
||||
expect(@configuration.subresource_integrity).to eq(:sha384)
|
||||
end
|
||||
|
||||
it 'allows to set an Array of symbols, without brackets' do
|
||||
it "allows to set an Array of symbols, without brackets" do
|
||||
@configuration.subresource_integrity :sha256, :sha512
|
||||
expect(@configuration.subresource_integrity).to eq(%i[sha256 sha512])
|
||||
end
|
||||
|
||||
it 'allows to set an Array of symbols, with brackets' do
|
||||
it "allows to set an Array of symbols, with brackets" do
|
||||
@configuration.subresource_integrity %i[sha256 sha512]
|
||||
expect(@configuration.subresource_integrity).to eq(%i[sha256 sha512])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#subresource_integrity_algorithms' do
|
||||
it 'includes only sha256 by default' do
|
||||
describe "#subresource_integrity_algorithms" do
|
||||
it "includes only sha256 by default" do
|
||||
@configuration.subresource_integrity true
|
||||
expect(@configuration.subresource_integrity_algorithms).to eq([:sha256])
|
||||
end
|
||||
|
||||
it 'converts symbol into array of symboles' do
|
||||
it "converts symbol into array of symboles" do
|
||||
@configuration.subresource_integrity :sha384
|
||||
expect(@configuration.subresource_integrity_algorithms).to eq([:sha384])
|
||||
end
|
||||
|
||||
it 'allows to an Array of symbols' do
|
||||
it "allows to an Array of symbols" do
|
||||
@configuration.subresource_integrity %i[sha256 sha512]
|
||||
expect(@configuration.subresource_integrity_algorithms).to eq(%i[sha256 sha512])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#cdn' do
|
||||
it 'is false by default' do
|
||||
describe "#cdn" do
|
||||
it "is false by default" do
|
||||
expect(@configuration.cdn).to eq(false)
|
||||
end
|
||||
|
||||
it 'allows to set a value' do
|
||||
it "allows to set a value" do
|
||||
@configuration.cdn true
|
||||
expect(@configuration.cdn).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#sources' do
|
||||
it 'is empty by default' do
|
||||
describe "#sources" do
|
||||
it "is empty by default" do
|
||||
expect(@configuration.sources).to be_empty
|
||||
end
|
||||
|
||||
it 'allows to add paths' do
|
||||
it "allows to add paths" do
|
||||
@configuration.sources << __dir__
|
||||
|
||||
expect(@configuration.sources).to eq([__dir__])
|
||||
end
|
||||
|
||||
it 'removes duplicates and nil sources' do
|
||||
it "removes duplicates and nil sources" do
|
||||
@configuration.sources << __dir__
|
||||
@configuration.sources << __dir__
|
||||
@configuration.sources << nil
|
||||
|
@ -168,296 +170,296 @@ describe Hanami::Assets::Configuration do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#scheme' do
|
||||
describe "#scheme" do
|
||||
it 'returns "http" as default value' do
|
||||
expect(@configuration.scheme).to eq('http')
|
||||
expect(@configuration.scheme).to eq("http")
|
||||
end
|
||||
|
||||
it 'allows to set a value' do
|
||||
@configuration.scheme 'https'
|
||||
expect(@configuration.scheme).to eq('https')
|
||||
it "allows to set a value" do
|
||||
@configuration.scheme "https"
|
||||
expect(@configuration.scheme).to eq("https")
|
||||
end
|
||||
end
|
||||
|
||||
describe '#host' do
|
||||
describe "#host" do
|
||||
it 'returns "localhost" as default value' do
|
||||
expect(@configuration.host).to eq('localhost')
|
||||
expect(@configuration.host).to eq("localhost")
|
||||
end
|
||||
|
||||
it 'allows to set a value' do
|
||||
@configuration.host 'hanamirb.org'
|
||||
expect(@configuration.host).to eq('hanamirb.org')
|
||||
it "allows to set a value" do
|
||||
@configuration.host "hanamirb.org"
|
||||
expect(@configuration.host).to eq("hanamirb.org")
|
||||
end
|
||||
end
|
||||
|
||||
describe '#port' do
|
||||
describe "#port" do
|
||||
it 'returns "2300" as default value' do
|
||||
expect(@configuration.port).to eq('2300')
|
||||
expect(@configuration.port).to eq("2300")
|
||||
end
|
||||
|
||||
it 'allows to set a value (string)' do
|
||||
@configuration.port '443'
|
||||
expect(@configuration.port).to eq('443')
|
||||
it "allows to set a value (string)" do
|
||||
@configuration.port "443"
|
||||
expect(@configuration.port).to eq("443")
|
||||
end
|
||||
|
||||
it 'allows to set a value (integer)' do
|
||||
it "allows to set a value (integer)" do
|
||||
@configuration.port 443
|
||||
expect(@configuration.port).to eq('443')
|
||||
expect(@configuration.port).to eq("443")
|
||||
end
|
||||
end
|
||||
|
||||
describe '#prefix' do
|
||||
describe "#prefix" do
|
||||
it 'returns "/assets" value default' do
|
||||
expect(@configuration.prefix).to be_kind_of(Hanami::Utils::PathPrefix)
|
||||
expect(@configuration.prefix).to eq('/assets')
|
||||
expect(@configuration.prefix).to eq("/assets")
|
||||
end
|
||||
|
||||
it 'allows to set a value' do
|
||||
@configuration.prefix 'application-prefix'
|
||||
expect(@configuration.prefix).to eq('application-prefix')
|
||||
it "allows to set a value" do
|
||||
@configuration.prefix "application-prefix"
|
||||
expect(@configuration.prefix).to eq("application-prefix")
|
||||
end
|
||||
end
|
||||
|
||||
describe '#public_directory' do
|
||||
describe "#public_directory" do
|
||||
it 'defaults to "public/" on current directory' do
|
||||
expected = Pathname.new(Dir.pwd + '/public')
|
||||
expected = Pathname.new(Dir.pwd + "/public")
|
||||
expect(@configuration.public_directory).to eq(expected)
|
||||
end
|
||||
|
||||
it 'allows to set a custom location' do
|
||||
dest = __dir__ + '/../tmp'
|
||||
it "allows to set a custom location" do
|
||||
dest = __dir__ + "/../tmp"
|
||||
@configuration.public_directory(dest)
|
||||
expect(@configuration.public_directory).to eq(Pathname.new(File.expand_path(dest)))
|
||||
end
|
||||
end
|
||||
|
||||
describe '#manifest' do
|
||||
describe "#manifest" do
|
||||
it 'defaults to "assets.json"' do
|
||||
expect(@configuration.manifest).to eq('assets.json')
|
||||
expect(@configuration.manifest).to eq("assets.json")
|
||||
end
|
||||
|
||||
it 'allows to set a relative path' do
|
||||
@configuration.manifest 'manifest.json'
|
||||
expect(@configuration.manifest).to eq('manifest.json')
|
||||
it "allows to set a relative path" do
|
||||
@configuration.manifest "manifest.json"
|
||||
expect(@configuration.manifest).to eq("manifest.json")
|
||||
end
|
||||
end
|
||||
|
||||
describe '#manifest_path' do
|
||||
it 'joins #manifest with #public_directory' do
|
||||
describe "#manifest_path" do
|
||||
it "joins #manifest with #public_directory" do
|
||||
expected = @configuration.public_directory.join(@configuration.manifest)
|
||||
expect(@configuration.manifest_path).to eq(expected)
|
||||
end
|
||||
|
||||
it 'returns absolute path, if #manifest is absolute path' do
|
||||
@configuration.manifest expected = __dir__ + '/manifest.json'
|
||||
it "returns absolute path, if #manifest is absolute path" do
|
||||
@configuration.manifest expected = __dir__ + "/manifest.json"
|
||||
expect(@configuration.manifest_path).to eq(Pathname.new(expected))
|
||||
end
|
||||
end
|
||||
|
||||
describe '#asset_path' do
|
||||
describe "#asset_path" do
|
||||
after do
|
||||
@configuration.reset!
|
||||
end
|
||||
|
||||
it 'returns relative url for given source' do
|
||||
actual = @configuration.asset_path('application.js')
|
||||
expect(actual).to eq('/assets/application.js')
|
||||
it "returns relative url for given source" do
|
||||
actual = @configuration.asset_path("application.js")
|
||||
expect(actual).to eq("/assets/application.js")
|
||||
end
|
||||
|
||||
it 'returns String instance' do
|
||||
actual = @configuration.asset_path('application.js')
|
||||
it "returns String instance" do
|
||||
actual = @configuration.asset_path("application.js")
|
||||
expect(actual).to be_kind_of(::String)
|
||||
end
|
||||
|
||||
describe 'fingerprint mode' do
|
||||
describe "fingerprint mode" do
|
||||
before do
|
||||
@configuration.fingerprint true
|
||||
end
|
||||
|
||||
describe 'with manifest' do
|
||||
describe "with manifest" do
|
||||
before do
|
||||
manifest = Hanami::Assets::Config::Manifest.new({
|
||||
'/assets/application.js' => {
|
||||
'target' => '/assets/application-abc123.js'
|
||||
"/assets/application.js" => {
|
||||
"target" => "/assets/application-abc123.js"
|
||||
}
|
||||
}, [])
|
||||
@configuration.instance_variable_set(:@public_manifest, manifest)
|
||||
end
|
||||
|
||||
it 'returns asset with fingerprint' do
|
||||
actual = @configuration.asset_path('application.js')
|
||||
expect(actual).to eq('/assets/application-abc123.js')
|
||||
it "returns asset with fingerprint" do
|
||||
actual = @configuration.asset_path("application.js")
|
||||
expect(actual).to eq("/assets/application-abc123.js")
|
||||
end
|
||||
|
||||
describe 'cdn mode' do
|
||||
describe "cdn mode" do
|
||||
before do
|
||||
@configuration.scheme 'https'
|
||||
@configuration.host 'bookshelf.cdn-example.org'
|
||||
@configuration.port '443'
|
||||
@configuration.scheme "https"
|
||||
@configuration.host "bookshelf.cdn-example.org"
|
||||
@configuration.port "443"
|
||||
@configuration.cdn true
|
||||
|
||||
@configuration.load!
|
||||
end
|
||||
|
||||
it 'returns absolute url' do
|
||||
actual = @configuration.asset_path('application.js')
|
||||
expect(actual).to eq('https://bookshelf.cdn-example.org/assets/application-abc123.js')
|
||||
it "returns absolute url" do
|
||||
actual = @configuration.asset_path("application.js")
|
||||
expect(actual).to eq("https://bookshelf.cdn-example.org/assets/application-abc123.js")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with missing manifest' do
|
||||
it 'raises exception with correct message' do
|
||||
describe "with missing manifest" do
|
||||
it "raises exception with correct message" do
|
||||
expect do
|
||||
@configuration.asset_path('application.js')
|
||||
@configuration.asset_path("application.js")
|
||||
end.to raise_error(Hanami::Assets::MissingManifestFileError,
|
||||
"Can't read manifest: #{@configuration.manifest_path}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'cdn mode' do
|
||||
describe "cdn mode" do
|
||||
before do
|
||||
@configuration.scheme 'https'
|
||||
@configuration.host 'bookshelf.cdn-example.org'
|
||||
@configuration.port '443'
|
||||
@configuration.scheme "https"
|
||||
@configuration.host "bookshelf.cdn-example.org"
|
||||
@configuration.port "443"
|
||||
@configuration.cdn true
|
||||
|
||||
@configuration.load!
|
||||
end
|
||||
|
||||
it 'returns absolute url' do
|
||||
actual = @configuration.asset_path('application.js')
|
||||
expect(actual).to eq('https://bookshelf.cdn-example.org/assets/application.js')
|
||||
it "returns absolute url" do
|
||||
actual = @configuration.asset_path("application.js")
|
||||
expect(actual).to eq("https://bookshelf.cdn-example.org/assets/application.js")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#asset_url' do
|
||||
describe "#asset_url" do
|
||||
after do
|
||||
@configuration.reset!
|
||||
end
|
||||
|
||||
describe 'development mode' do
|
||||
describe "development mode" do
|
||||
before do
|
||||
@configuration.load!
|
||||
end
|
||||
|
||||
it 'returns absolute url for given source' do
|
||||
actual = @configuration.asset_url('application.js')
|
||||
expect(actual).to eq('http://localhost:2300/assets/application.js')
|
||||
it "returns absolute url for given source" do
|
||||
actual = @configuration.asset_url("application.js")
|
||||
expect(actual).to eq("http://localhost:2300/assets/application.js")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'production mode' do
|
||||
describe "production mode" do
|
||||
before do
|
||||
@configuration.scheme 'https'
|
||||
@configuration.host 'hanamirb.org'
|
||||
@configuration.scheme "https"
|
||||
@configuration.host "hanamirb.org"
|
||||
@configuration.port 443
|
||||
@configuration.load!
|
||||
end
|
||||
|
||||
it 'returns absolute url for given source' do
|
||||
actual = @configuration.asset_url('application.js')
|
||||
expect(actual).to eq('https://hanamirb.org/assets/application.js')
|
||||
it "returns absolute url for given source" do
|
||||
actual = @configuration.asset_url("application.js")
|
||||
expect(actual).to eq("https://hanamirb.org/assets/application.js")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with http scheme' do
|
||||
describe "with http scheme" do
|
||||
before do
|
||||
@configuration.scheme 'http'
|
||||
@configuration.scheme "http"
|
||||
end
|
||||
|
||||
describe 'and standard port' do
|
||||
describe "and standard port" do
|
||||
before do
|
||||
@configuration.port 80
|
||||
@configuration.load!
|
||||
end
|
||||
|
||||
it 'returns absolute url without port' do
|
||||
actual = @configuration.asset_url('application.js')
|
||||
expect(actual).to eq('http://localhost/assets/application.js')
|
||||
it "returns absolute url without port" do
|
||||
actual = @configuration.asset_url("application.js")
|
||||
expect(actual).to eq("http://localhost/assets/application.js")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'and custom port' do
|
||||
describe "and custom port" do
|
||||
before do
|
||||
@configuration.port 8080
|
||||
@configuration.load!
|
||||
end
|
||||
|
||||
it 'returns absolute url with port' do
|
||||
actual = @configuration.asset_url('application.js')
|
||||
expect(actual).to eq('http://localhost:8080/assets/application.js')
|
||||
it "returns absolute url with port" do
|
||||
actual = @configuration.asset_url("application.js")
|
||||
expect(actual).to eq("http://localhost:8080/assets/application.js")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with https scheme' do
|
||||
describe "with https scheme" do
|
||||
before do
|
||||
@configuration.scheme 'https'
|
||||
@configuration.scheme "https"
|
||||
end
|
||||
|
||||
describe 'and standard port' do
|
||||
describe "and standard port" do
|
||||
before do
|
||||
@configuration.port 443
|
||||
@configuration.load!
|
||||
end
|
||||
|
||||
it 'returns absolute url without port' do
|
||||
actual = @configuration.asset_url('application.js')
|
||||
expect(actual).to eq('https://localhost/assets/application.js')
|
||||
it "returns absolute url without port" do
|
||||
actual = @configuration.asset_url("application.js")
|
||||
expect(actual).to eq("https://localhost/assets/application.js")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'and custom port' do
|
||||
describe "and custom port" do
|
||||
before do
|
||||
@configuration.port 8081
|
||||
@configuration.load!
|
||||
end
|
||||
|
||||
it 'returns absolute url with port' do
|
||||
actual = @configuration.asset_url('application.js')
|
||||
expect(actual).to eq('https://localhost:8081/assets/application.js')
|
||||
it "returns absolute url with port" do
|
||||
actual = @configuration.asset_url("application.js")
|
||||
expect(actual).to eq("https://localhost:8081/assets/application.js")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with custom host' do
|
||||
describe "with custom host" do
|
||||
before do
|
||||
@configuration.host 'example.com'
|
||||
@configuration.host "example.com"
|
||||
@configuration.load!
|
||||
end
|
||||
|
||||
it 'returns absolute url for given source' do
|
||||
actual = @configuration.asset_url('application.js')
|
||||
expect(actual).to eq('http://example.com:2300/assets/application.js')
|
||||
it "returns absolute url for given source" do
|
||||
actual = @configuration.asset_url("application.js")
|
||||
expect(actual).to eq("http://example.com:2300/assets/application.js")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'fingerprint mode' do
|
||||
describe "fingerprint mode" do
|
||||
before do
|
||||
@configuration.fingerprint true
|
||||
end
|
||||
|
||||
describe 'with manifest' do
|
||||
describe "with manifest" do
|
||||
before do
|
||||
manifest = Hanami::Assets::Config::Manifest.new({ '/assets/application.js' => { 'target' => '/assets/application-abc123.js' } }, [])
|
||||
manifest = Hanami::Assets::Config::Manifest.new({ "/assets/application.js" => { "target" => "/assets/application-abc123.js" } }, [])
|
||||
|
||||
@configuration.load!
|
||||
@configuration.instance_variable_set(:@public_manifest, manifest)
|
||||
end
|
||||
|
||||
it 'returns asset with fingerprint' do
|
||||
actual = @configuration.asset_url('application.js')
|
||||
expect(actual).to eq('http://localhost:2300/assets/application-abc123.js')
|
||||
it "returns asset with fingerprint" do
|
||||
actual = @configuration.asset_url("application.js")
|
||||
expect(actual).to eq("http://localhost:2300/assets/application-abc123.js")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with missing manifest' do
|
||||
it 'raises exception with correct message' do
|
||||
describe "with missing manifest" do
|
||||
it "raises exception with correct message" do
|
||||
expect do
|
||||
@configuration.asset_url('application.js')
|
||||
@configuration.asset_url("application.js")
|
||||
end.to raise_error(Hanami::Assets::MissingManifestFileError,
|
||||
"Can't read manifest: #{@configuration.manifest_path}")
|
||||
end
|
||||
|
@ -527,18 +529,18 @@ describe Hanami::Assets::Configuration do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'subresource_integrity_value' do
|
||||
describe 'subresource_integrity mode' do
|
||||
describe "subresource_integrity_value" do
|
||||
describe "subresource_integrity mode" do
|
||||
before do
|
||||
@configuration.subresource_integrity true
|
||||
end
|
||||
|
||||
describe 'with manifest' do
|
||||
describe "with manifest" do
|
||||
before do
|
||||
manifest = Hanami::Assets::Config::Manifest.new({
|
||||
'/assets/application.js' => {
|
||||
'target' => '/assets/application-abc123.js',
|
||||
'sri' => ['sha0-456def']
|
||||
"/assets/application.js" => {
|
||||
"target" => "/assets/application-abc123.js",
|
||||
"sri" => ["sha0-456def"]
|
||||
}
|
||||
}, [])
|
||||
|
||||
|
@ -546,16 +548,16 @@ describe Hanami::Assets::Configuration do
|
|||
@configuration.instance_variable_set(:@public_manifest, manifest)
|
||||
end
|
||||
|
||||
it 'returns subresource_integrity value' do
|
||||
actual = @configuration.subresource_integrity_value('application.js')
|
||||
expect(actual).to eq('sha0-456def')
|
||||
it "returns subresource_integrity value" do
|
||||
actual = @configuration.subresource_integrity_value("application.js")
|
||||
expect(actual).to eq("sha0-456def")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with missing manifest' do
|
||||
it 'raises an exception' do
|
||||
describe "with missing manifest" do
|
||||
it "raises an exception" do
|
||||
expect do
|
||||
@configuration.subresource_integrity_value('application.js')
|
||||
@configuration.subresource_integrity_value("application.js")
|
||||
end.to raise_error(Hanami::Assets::MissingManifestFileError,
|
||||
"Can't read manifest: #{@configuration.manifest_path}")
|
||||
end
|
||||
|
@ -563,137 +565,137 @@ describe Hanami::Assets::Configuration do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#reset!' do
|
||||
describe "#reset!" do
|
||||
before do
|
||||
@configuration.scheme 'https'
|
||||
@configuration.host 'example.com'
|
||||
@configuration.port '443'
|
||||
@configuration.prefix 'prfx'
|
||||
@configuration.scheme "https"
|
||||
@configuration.host "example.com"
|
||||
@configuration.port "443"
|
||||
@configuration.prefix "prfx"
|
||||
@configuration.javascript_compressor :yui
|
||||
@configuration.stylesheet_compressor :yui
|
||||
@configuration.manifest 'assets.json'
|
||||
@configuration.public_directory(Dir.pwd + '/tmp')
|
||||
@configuration.manifest "assets.json"
|
||||
@configuration.public_directory(Dir.pwd + "/tmp")
|
||||
@configuration.instance_variable_set(:@public_manifest, {})
|
||||
|
||||
@configuration.reset!
|
||||
end
|
||||
|
||||
it 'sets default value for public directory' do
|
||||
expect(@configuration.public_directory).to eq(Pathname.new(Dir.pwd + '/public'))
|
||||
it "sets default value for public directory" do
|
||||
expect(@configuration.public_directory).to eq(Pathname.new(Dir.pwd + "/public"))
|
||||
end
|
||||
|
||||
it 'sets default value for scheme' do
|
||||
expect(@configuration.scheme).to eq('http')
|
||||
it "sets default value for scheme" do
|
||||
expect(@configuration.scheme).to eq("http")
|
||||
end
|
||||
|
||||
it 'sets default value for host' do
|
||||
expect(@configuration.host).to eq('localhost')
|
||||
it "sets default value for host" do
|
||||
expect(@configuration.host).to eq("localhost")
|
||||
end
|
||||
|
||||
it 'sets default value for port' do
|
||||
expect(@configuration.port).to eq('2300')
|
||||
it "sets default value for port" do
|
||||
expect(@configuration.port).to eq("2300")
|
||||
end
|
||||
|
||||
it 'sets default value for prefix' do
|
||||
it "sets default value for prefix" do
|
||||
expect(@configuration.prefix).to be_kind_of(Hanami::Utils::PathPrefix)
|
||||
expect(@configuration.prefix).to eq('/assets')
|
||||
expect(@configuration.prefix).to eq("/assets")
|
||||
end
|
||||
|
||||
it 'sets default value for javascript_compressor' do
|
||||
it "sets default value for javascript_compressor" do
|
||||
expect(@configuration.javascript_compressor).to be_nil
|
||||
end
|
||||
|
||||
it 'sets default value for stylesheet_compressor' do
|
||||
it "sets default value for stylesheet_compressor" do
|
||||
expect(@configuration.stylesheet_compressor).to be_nil
|
||||
end
|
||||
|
||||
it 'sets default value for manifest' do
|
||||
expect(@configuration.manifest).to eq('assets.json')
|
||||
it "sets default value for manifest" do
|
||||
expect(@configuration.manifest).to eq("assets.json")
|
||||
end
|
||||
|
||||
it 'sets default value for manifest' do
|
||||
it "sets default value for manifest" do
|
||||
expect(@configuration.public_manifest.class).to eq(Hanami::Assets::Config::NullManifest)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#duplicate' do
|
||||
describe "#duplicate" do
|
||||
before do
|
||||
@configuration.reset!
|
||||
@configuration.cdn true
|
||||
@configuration.subresource_integrity true
|
||||
@configuration.compile true
|
||||
@configuration.scheme 'ftp'
|
||||
@configuration.host 'hanamirb.org'
|
||||
@configuration.port '8080'
|
||||
@configuration.prefix '/foo'
|
||||
@configuration.manifest 'm.json'
|
||||
@configuration.scheme "ftp"
|
||||
@configuration.host "hanamirb.org"
|
||||
@configuration.port "8080"
|
||||
@configuration.prefix "/foo"
|
||||
@configuration.manifest "m.json"
|
||||
@configuration.javascript_compressor :yui
|
||||
@configuration.stylesheet_compressor :yui
|
||||
@configuration.root __dir__
|
||||
@configuration.public_directory __dir__
|
||||
@configuration.sources << __dir__ + '/fixtures/javascripts'
|
||||
@configuration.sources << __dir__ + "/fixtures/javascripts"
|
||||
|
||||
@config = @configuration.duplicate
|
||||
end
|
||||
|
||||
it 'returns a copy of the configuration' do
|
||||
it "returns a copy of the configuration" do
|
||||
expect(@config.cdn).to eq(true)
|
||||
expect(@config.subresource_integrity).to eq(true)
|
||||
expect(@config.compile).to eq(true)
|
||||
expect(@config.scheme).to eq('ftp')
|
||||
expect(@config.host).to eq('hanamirb.org')
|
||||
expect(@config.port).to eq('8080')
|
||||
expect(@config.prefix).to eq('/foo')
|
||||
expect(@config.manifest).to eq('m.json')
|
||||
expect(@config.scheme).to eq("ftp")
|
||||
expect(@config.host).to eq("hanamirb.org")
|
||||
expect(@config.port).to eq("8080")
|
||||
expect(@config.prefix).to eq("/foo")
|
||||
expect(@config.manifest).to eq("m.json")
|
||||
expect(@config.javascript_compressor).to eq(:yui)
|
||||
expect(@config.stylesheet_compressor).to eq(:yui)
|
||||
expect(@config.root).to eq(Pathname.new(__dir__))
|
||||
expect(@config.public_directory).to eq(Pathname.new(__dir__))
|
||||
expect(@config.sources).to eq([__dir__ + '/fixtures/javascripts'])
|
||||
expect(@config.sources).to eq([__dir__ + "/fixtures/javascripts"])
|
||||
end
|
||||
|
||||
it "doesn't affect the original configuration" do
|
||||
@config.cdn false
|
||||
@config.subresource_integrity false
|
||||
@config.compile false
|
||||
@config.scheme 'mailto'
|
||||
@config.host 'example.org'
|
||||
@config.port '9091'
|
||||
@config.prefix '/bar'
|
||||
@config.manifest 'a.json'
|
||||
@config.scheme "mailto"
|
||||
@config.host "example.org"
|
||||
@config.port "9091"
|
||||
@config.prefix "/bar"
|
||||
@config.manifest "a.json"
|
||||
@config.javascript_compressor :uglify
|
||||
@config.stylesheet_compressor :uglify
|
||||
@config.root __dir__ + "/../../../support/fixtures"
|
||||
@config.public_directory __dir__ + "/fixtures"
|
||||
@config.sources << __dir__ + '/fixtures/stylesheets'
|
||||
@config.sources << __dir__ + "/fixtures/stylesheets"
|
||||
|
||||
expect(@config.cdn).to eq(false)
|
||||
expect(@config.subresource_integrity).to eq(false)
|
||||
expect(@config.compile).to eq(false)
|
||||
expect(@config.scheme).to eq('mailto')
|
||||
expect(@config.host).to eq('example.org')
|
||||
expect(@config.port).to eq('9091')
|
||||
expect(@config.prefix).to eq('/bar')
|
||||
expect(@config.manifest).to eq('a.json')
|
||||
expect(@config.scheme).to eq("mailto")
|
||||
expect(@config.host).to eq("example.org")
|
||||
expect(@config.port).to eq("9091")
|
||||
expect(@config.prefix).to eq("/bar")
|
||||
expect(@config.manifest).to eq("a.json")
|
||||
expect(@config.javascript_compressor).to eq(:uglify)
|
||||
expect(@config.stylesheet_compressor).to eq(:uglify)
|
||||
expect(@config.root).to eq(Pathname.new(File.expand_path(__dir__ + "/../../../support/fixtures")))
|
||||
expect(@config.public_directory).to eq(Pathname.new(__dir__ + '/fixtures'))
|
||||
expect(@config.sources).to eq([__dir__ + '/fixtures/javascripts', __dir__ + '/fixtures/stylesheets'])
|
||||
expect(@config.public_directory).to eq(Pathname.new(__dir__ + "/fixtures"))
|
||||
expect(@config.sources).to eq([__dir__ + "/fixtures/javascripts", __dir__ + "/fixtures/stylesheets"])
|
||||
|
||||
expect(@configuration.cdn).to eq(true)
|
||||
expect(@configuration.subresource_integrity).to eq(true)
|
||||
expect(@configuration.compile).to eq(true)
|
||||
expect(@configuration.scheme).to eq('ftp')
|
||||
expect(@configuration.host).to eq('hanamirb.org')
|
||||
expect(@configuration.port).to eq('8080')
|
||||
expect(@configuration.prefix).to eq('/foo')
|
||||
expect(@configuration.manifest).to eq('m.json')
|
||||
expect(@configuration.scheme).to eq("ftp")
|
||||
expect(@configuration.host).to eq("hanamirb.org")
|
||||
expect(@configuration.port).to eq("8080")
|
||||
expect(@configuration.prefix).to eq("/foo")
|
||||
expect(@configuration.manifest).to eq("m.json")
|
||||
expect(@configuration.javascript_compressor).to eq(:yui)
|
||||
expect(@configuration.stylesheet_compressor).to eq(:yui)
|
||||
expect(@configuration.root).to eq(Pathname.new(__dir__))
|
||||
expect(@configuration.public_directory).to eq(Pathname.new(__dir__))
|
||||
expect(@configuration.sources).to eq([__dir__ + '/fixtures/javascripts'])
|
||||
expect(@configuration.sources).to eq([__dir__ + "/fixtures/javascripts"])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
describe Hanami::Assets::Helpers do
|
||||
let(:view) { ImageHelperView.new({}, {}) }
|
||||
let(:cdn_url) { 'https://bookshelf.cdn-example.com' }
|
||||
let(:cdn_url) { "https://bookshelf.cdn-example.com" }
|
||||
|
||||
before do
|
||||
view.class.assets_configuration.load!
|
||||
|
@ -11,67 +13,67 @@ describe Hanami::Assets::Helpers do
|
|||
view.class.assets_configuration.reset!
|
||||
end
|
||||
|
||||
describe '#javascript' do
|
||||
it 'returns an instance of SafeString' do
|
||||
actual = DefaultView.new.javascript('feature-a')
|
||||
describe "#javascript" do
|
||||
it "returns an instance of SafeString" do
|
||||
actual = DefaultView.new.javascript("feature-a")
|
||||
expect(actual).to be_instance_of(::Hanami::Utils::Escape::SafeString)
|
||||
end
|
||||
|
||||
it 'renders <script> tag' do
|
||||
actual = DefaultView.new.javascript('feature-a')
|
||||
it "renders <script> tag" do
|
||||
actual = DefaultView.new.javascript("feature-a")
|
||||
expect(actual).to eq(%(<script src="/assets/feature-a.js" type="text/javascript"></script>))
|
||||
end
|
||||
|
||||
it 'renders <script> tag without appending ext after query string' do
|
||||
actual = DefaultView.new.javascript('feature-x?callback=init')
|
||||
it "renders <script> tag without appending ext after query string" do
|
||||
actual = DefaultView.new.javascript("feature-x?callback=init")
|
||||
expect(actual).to eq(%(<script src="/assets/feature-x?callback=init" type="text/javascript"></script>))
|
||||
end
|
||||
|
||||
it 'renders <script> tag with a defer attribute' do
|
||||
actual = DefaultView.new.javascript('feature-a', defer: true)
|
||||
it "renders <script> tag with a defer attribute" do
|
||||
actual = DefaultView.new.javascript("feature-a", defer: true)
|
||||
expect(actual).to eq(%(<script defer="defer" src="/assets/feature-a.js" type="text/javascript"></script>))
|
||||
end
|
||||
|
||||
it 'renders <script> tag with an integrity attribute' do
|
||||
actual = DefaultView.new.javascript('feature-a', integrity: 'sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC')
|
||||
it "renders <script> tag with an integrity attribute" do
|
||||
actual = DefaultView.new.javascript("feature-a", integrity: "sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC")
|
||||
expect(actual).to eq(%(<script integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC" src="/assets/feature-a.js" type="text/javascript" crossorigin="anonymous"></script>))
|
||||
end
|
||||
|
||||
it 'renders <script> tag with a crossorigin attribute' do
|
||||
actual = DefaultView.new.javascript('feature-a', integrity: 'sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC', crossorigin: 'use-credentials')
|
||||
it "renders <script> tag with a crossorigin attribute" do
|
||||
actual = DefaultView.new.javascript("feature-a", integrity: "sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC", crossorigin: "use-credentials")
|
||||
expect(actual).to eq(%(<script integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC" crossorigin="use-credentials" src="/assets/feature-a.js" type="text/javascript"></script>))
|
||||
end
|
||||
|
||||
describe 'async option' do
|
||||
it 'renders <script> tag with an async=true if async option is true' do
|
||||
actual = DefaultView.new.javascript('feature-a', async: true)
|
||||
describe "async option" do
|
||||
it "renders <script> tag with an async=true if async option is true" do
|
||||
actual = DefaultView.new.javascript("feature-a", async: true)
|
||||
expect(actual).to eq(%(<script async="async" src="/assets/feature-a.js" type="text/javascript"></script>))
|
||||
end
|
||||
|
||||
it 'renders <script> tag without an async=true if async option is false' do
|
||||
actual = DefaultView.new.javascript('feature-a', async: false)
|
||||
it "renders <script> tag without an async=true if async option is false" do
|
||||
actual = DefaultView.new.javascript("feature-a", async: false)
|
||||
expect(actual).to eq(%(<script src="/assets/feature-a.js" type="text/javascript"></script>))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'subresource_integrity mode' do
|
||||
describe "subresource_integrity mode" do
|
||||
before do
|
||||
activate_subresource_integrity_mode!
|
||||
end
|
||||
|
||||
it 'includes subresource_integrity and crossorigin attributes' do
|
||||
actual = DefaultView.new.javascript('feature-a')
|
||||
it "includes subresource_integrity and crossorigin attributes" do
|
||||
actual = DefaultView.new.javascript("feature-a")
|
||||
expect(actual).to eq(%(<script src="/assets/feature-a.js" type="text/javascript" integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC" crossorigin="anonymous"></script>))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'cdn mode' do
|
||||
describe "cdn mode" do
|
||||
before do
|
||||
activate_cdn_mode!
|
||||
end
|
||||
|
||||
it 'returns absolute url for src attribute' do
|
||||
actual = DefaultView.new.javascript('feature-a')
|
||||
it "returns absolute url for src attribute" do
|
||||
actual = DefaultView.new.javascript("feature-a")
|
||||
expect(actual).to eq(%(<script src="#{cdn_url}/assets/feature-a.js" type="text/javascript"></script>))
|
||||
end
|
||||
end
|
||||
|
@ -116,50 +118,50 @@ describe Hanami::Assets::Helpers do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#stylesheet' do
|
||||
it 'returns an instance of SafeString' do
|
||||
actual = DefaultView.new.stylesheet('main')
|
||||
describe "#stylesheet" do
|
||||
it "returns an instance of SafeString" do
|
||||
actual = DefaultView.new.stylesheet("main")
|
||||
expect(actual).to be_instance_of(::Hanami::Utils::Escape::SafeString)
|
||||
end
|
||||
|
||||
it 'renders <link> tag' do
|
||||
actual = DefaultView.new.stylesheet('main')
|
||||
it "renders <link> tag" do
|
||||
actual = DefaultView.new.stylesheet("main")
|
||||
expect(actual).to eq(%(<link href="/assets/main.css" type="text/css" rel="stylesheet">))
|
||||
end
|
||||
|
||||
it 'renders <link> tag without appending ext after query string' do
|
||||
actual = DefaultView.new.stylesheet('fonts?font=Helvetica')
|
||||
it "renders <link> tag without appending ext after query string" do
|
||||
actual = DefaultView.new.stylesheet("fonts?font=Helvetica")
|
||||
expect(actual).to eq(%(<link href="/assets/fonts?font=Helvetica" type="text/css" rel="stylesheet">))
|
||||
end
|
||||
|
||||
it 'renders <link> tag with an integrity attribute' do
|
||||
actual = DefaultView.new.stylesheet('main', integrity: 'sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC')
|
||||
it "renders <link> tag with an integrity attribute" do
|
||||
actual = DefaultView.new.stylesheet("main", integrity: "sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC")
|
||||
expect(actual).to eq(%(<link integrity=\"sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC\" href=\"/assets/main.css\" type=\"text/css\" rel=\"stylesheet\" crossorigin=\"anonymous\">))
|
||||
end
|
||||
|
||||
it 'renders <link> tag with a crossorigin attribute' do
|
||||
actual = DefaultView.new.stylesheet('main', integrity: 'sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC', crossorigin: 'use-credentials')
|
||||
it "renders <link> tag with a crossorigin attribute" do
|
||||
actual = DefaultView.new.stylesheet("main", integrity: "sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC", crossorigin: "use-credentials")
|
||||
expect(actual).to eq(%(<link integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC" crossorigin="use-credentials" href="/assets/main.css" type="text/css" rel="stylesheet">))
|
||||
end
|
||||
|
||||
describe 'subresource_integrity mode' do
|
||||
describe "subresource_integrity mode" do
|
||||
before do
|
||||
activate_subresource_integrity_mode!
|
||||
end
|
||||
|
||||
it 'includes subresource_integrity and crossorigin attributes' do
|
||||
actual = DefaultView.new.stylesheet('main')
|
||||
it "includes subresource_integrity and crossorigin attributes" do
|
||||
actual = DefaultView.new.stylesheet("main")
|
||||
expect(actual).to eq(%(<link href="/assets/main.css" type="text/css" rel="stylesheet" integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC" crossorigin="anonymous">))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'cdn mode' do
|
||||
describe "cdn mode" do
|
||||
before do
|
||||
activate_cdn_mode!
|
||||
end
|
||||
|
||||
it 'returns absolute url for href attribute' do
|
||||
actual = DefaultView.new.stylesheet('main')
|
||||
it "returns absolute url for href attribute" do
|
||||
actual = DefaultView.new.stylesheet("main")
|
||||
expect(actual).to eq(%(<link href="#{cdn_url}/assets/main.css" type="text/css" rel="stylesheet">))
|
||||
end
|
||||
end
|
||||
|
@ -197,34 +199,34 @@ describe Hanami::Assets::Helpers do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'image' do
|
||||
it 'returns an instance of HtmlBuilder' do
|
||||
actual = view.image('application.jpg')
|
||||
describe "image" do
|
||||
it "returns an instance of HtmlBuilder" do
|
||||
actual = view.image("application.jpg")
|
||||
expect(actual).to be_instance_of(::Hanami::Helpers::HtmlHelper::HtmlBuilder)
|
||||
end
|
||||
|
||||
it 'renders an <img> tag' do
|
||||
actual = view.image('application.jpg').to_s
|
||||
it "renders an <img> tag" do
|
||||
actual = view.image("application.jpg").to_s
|
||||
expect(actual).to eq(%(<img src="/assets/application.jpg" alt="Application">))
|
||||
end
|
||||
|
||||
it 'custom alt' do
|
||||
actual = view.image('application.jpg', alt: 'My Alt').to_s
|
||||
it "custom alt" do
|
||||
actual = view.image("application.jpg", alt: "My Alt").to_s
|
||||
expect(actual).to eq(%(<img alt="My Alt" src="/assets/application.jpg">))
|
||||
end
|
||||
|
||||
it 'custom data attribute' do
|
||||
actual = view.image('application.jpg', 'data-user-id' => 5).to_s
|
||||
it "custom data attribute" do
|
||||
actual = view.image("application.jpg", "data-user-id" => 5).to_s
|
||||
expect(actual).to eq(%(<img data-user-id="5" src="/assets/application.jpg" alt="Application">))
|
||||
end
|
||||
|
||||
describe 'cdn mode' do
|
||||
describe "cdn mode" do
|
||||
before do
|
||||
activate_cdn_mode!
|
||||
end
|
||||
|
||||
it 'returns absolute url for src attribute' do
|
||||
actual = view.image('application.jpg').to_s
|
||||
it "returns absolute url for src attribute" do
|
||||
actual = view.image("application.jpg").to_s
|
||||
expect(actual).to eq(%(<img src="#{cdn_url}/assets/application.jpg" alt="Application">))
|
||||
end
|
||||
end
|
||||
|
@ -255,28 +257,28 @@ describe Hanami::Assets::Helpers do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#favicon' do
|
||||
it 'returns an instance of HtmlBuilder' do
|
||||
describe "#favicon" do
|
||||
it "returns an instance of HtmlBuilder" do
|
||||
actual = view.favicon
|
||||
expect(actual).to be_instance_of(::Hanami::Helpers::HtmlHelper::HtmlBuilder)
|
||||
end
|
||||
|
||||
it 'renders <link> tag' do
|
||||
it "renders <link> tag" do
|
||||
actual = view.favicon.to_s
|
||||
expect(actual).to eq(%(<link href="/assets/favicon.ico" rel="shortcut icon" type="image/x-icon">))
|
||||
end
|
||||
|
||||
it 'renders with HTML attributes' do
|
||||
actual = view.favicon('favicon.png', rel: 'icon', type: 'image/png').to_s
|
||||
it "renders with HTML attributes" do
|
||||
actual = view.favicon("favicon.png", rel: "icon", type: "image/png").to_s
|
||||
expect(actual).to eq(%(<link rel="icon" type="image/png" href="/assets/favicon.png">))
|
||||
end
|
||||
|
||||
describe 'cdn mode' do
|
||||
describe "cdn mode" do
|
||||
before do
|
||||
activate_cdn_mode!
|
||||
end
|
||||
|
||||
it 'returns absolute url for href attribute' do
|
||||
it "returns absolute url for href attribute" do
|
||||
actual = view.favicon.to_s
|
||||
expect(actual).to eq(%(<link href="#{cdn_url}/assets/favicon.ico" rel="shortcut icon" type="image/x-icon">))
|
||||
end
|
||||
|
@ -308,69 +310,69 @@ describe Hanami::Assets::Helpers do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#video' do
|
||||
it 'returns an instance of HtmlBuilder' do
|
||||
actual = view.video('movie.mp4')
|
||||
describe "#video" do
|
||||
it "returns an instance of HtmlBuilder" do
|
||||
actual = view.video("movie.mp4")
|
||||
expect(actual).to be_instance_of(::Hanami::Helpers::HtmlHelper::HtmlBuilder)
|
||||
end
|
||||
|
||||
it 'renders <video> tag' do
|
||||
actual = view.video('movie.mp4').to_s
|
||||
it "renders <video> tag" do
|
||||
actual = view.video("movie.mp4").to_s
|
||||
expect(actual).to eq(%(<video src="/assets/movie.mp4"></video>))
|
||||
end
|
||||
|
||||
it 'renders with html attributes' do
|
||||
actual = view.video('movie.mp4', autoplay: true, controls: true).to_s
|
||||
it "renders with html attributes" do
|
||||
actual = view.video("movie.mp4", autoplay: true, controls: true).to_s
|
||||
expect(actual).to eq(%(<video autoplay="autoplay" controls="controls" src="/assets/movie.mp4"></video>))
|
||||
end
|
||||
|
||||
it 'renders with fallback content' do
|
||||
actual = view.video('movie.mp4') do
|
||||
'Your browser does not support the video tag'
|
||||
it "renders with fallback content" do
|
||||
actual = view.video("movie.mp4") do
|
||||
"Your browser does not support the video tag"
|
||||
end.to_s
|
||||
|
||||
expect(actual).to eq(%(<video src="/assets/movie.mp4">\nYour browser does not support the video tag\n</video>))
|
||||
end
|
||||
|
||||
it 'renders with tracks' do
|
||||
actual = view.video('movie.mp4') do
|
||||
track kind: 'captions', src: view.asset_path('movie.en.vtt'), srclang: 'en', label: 'English'
|
||||
it "renders with tracks" do
|
||||
actual = view.video("movie.mp4") do
|
||||
track kind: "captions", src: view.asset_path("movie.en.vtt"), srclang: "en", label: "English"
|
||||
end.to_s
|
||||
|
||||
expect(actual).to eq(%(<video src="/assets/movie.mp4">\n<track kind="captions" src="/assets/movie.en.vtt" srclang="en" label="English">\n</video>))
|
||||
end
|
||||
|
||||
it 'renders with sources' do
|
||||
it "renders with sources" do
|
||||
actual = view.video do
|
||||
text 'Your browser does not support the video tag'
|
||||
source src: view.asset_path('movie.mp4'), type: 'video/mp4'
|
||||
source src: view.asset_path('movie.ogg'), type: 'video/ogg'
|
||||
text "Your browser does not support the video tag"
|
||||
source src: view.asset_path("movie.mp4"), type: "video/mp4"
|
||||
source src: view.asset_path("movie.ogg"), type: "video/ogg"
|
||||
end.to_s
|
||||
|
||||
expect(actual).to eq(%(<video>\nYour browser does not support the video tag\n<source src="/assets/movie.mp4" type="video/mp4">\n<source src="/assets/movie.ogg" type="video/ogg">\n</video>))
|
||||
end
|
||||
|
||||
it 'raises an exception when no arguments' do
|
||||
it "raises an exception when no arguments" do
|
||||
expect do
|
||||
view.video
|
||||
end.to raise_error(ArgumentError,
|
||||
'You should provide a source via `src` option or with a `source` HTML tag')
|
||||
"You should provide a source via `src` option or with a `source` HTML tag")
|
||||
end
|
||||
|
||||
it 'raises an exception when no src and no block' do
|
||||
it "raises an exception when no src and no block" do
|
||||
expect do
|
||||
view.video(content: true)
|
||||
end.to raise_error(ArgumentError,
|
||||
'You should provide a source via `src` option or with a `source` HTML tag')
|
||||
"You should provide a source via `src` option or with a `source` HTML tag")
|
||||
end
|
||||
|
||||
describe 'cdn mode' do
|
||||
describe "cdn mode" do
|
||||
before do
|
||||
activate_cdn_mode!
|
||||
end
|
||||
|
||||
it 'returns absolute url for src attribute' do
|
||||
actual = view.video('movie.mp4').to_s
|
||||
it "returns absolute url for src attribute" do
|
||||
actual = view.video("movie.mp4").to_s
|
||||
expect(actual).to eq(%(<video src="#{cdn_url}/assets/movie.mp4"></video>))
|
||||
end
|
||||
end
|
||||
|
@ -425,69 +427,69 @@ describe Hanami::Assets::Helpers do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#audio' do
|
||||
it 'returns an instance of HtmlBuilder' do
|
||||
actual = view.audio('song.ogg')
|
||||
describe "#audio" do
|
||||
it "returns an instance of HtmlBuilder" do
|
||||
actual = view.audio("song.ogg")
|
||||
expect(actual).to be_instance_of(::Hanami::Helpers::HtmlHelper::HtmlBuilder)
|
||||
end
|
||||
|
||||
it 'renders <audio> tag' do
|
||||
actual = view.audio('song.ogg').to_s
|
||||
it "renders <audio> tag" do
|
||||
actual = view.audio("song.ogg").to_s
|
||||
expect(actual).to eq(%(<audio src="/assets/song.ogg"></audio>))
|
||||
end
|
||||
|
||||
it 'renders with html attributes' do
|
||||
actual = view.audio('song.ogg', autoplay: true, controls: true).to_s
|
||||
it "renders with html attributes" do
|
||||
actual = view.audio("song.ogg", autoplay: true, controls: true).to_s
|
||||
expect(actual).to eq(%(<audio autoplay="autoplay" controls="controls" src="/assets/song.ogg"></audio>))
|
||||
end
|
||||
|
||||
it 'renders with fallback content' do
|
||||
actual = view.audio('song.ogg') do
|
||||
'Your browser does not support the audio tag'
|
||||
it "renders with fallback content" do
|
||||
actual = view.audio("song.ogg") do
|
||||
"Your browser does not support the audio tag"
|
||||
end.to_s
|
||||
|
||||
expect(actual).to eq(%(<audio src="/assets/song.ogg">\nYour browser does not support the audio tag\n</audio>))
|
||||
end
|
||||
|
||||
it 'renders with tracks' do
|
||||
actual = view.audio('song.ogg') do
|
||||
track kind: 'captions', src: view.asset_path('song.pt-BR.vtt'), srclang: 'pt-BR', label: 'Portuguese'
|
||||
it "renders with tracks" do
|
||||
actual = view.audio("song.ogg") do
|
||||
track kind: "captions", src: view.asset_path("song.pt-BR.vtt"), srclang: "pt-BR", label: "Portuguese"
|
||||
end.to_s
|
||||
|
||||
expect(actual).to eq(%(<audio src="/assets/song.ogg">\n<track kind="captions" src="/assets/song.pt-BR.vtt" srclang="pt-BR" label="Portuguese">\n</audio>))
|
||||
end
|
||||
|
||||
it 'renders with sources' do
|
||||
it "renders with sources" do
|
||||
actual = view.audio do
|
||||
text 'Your browser does not support the audio tag'
|
||||
source src: view.asset_path('song.ogg'), type: 'audio/ogg'
|
||||
source src: view.asset_path('song.wav'), type: 'audio/wav'
|
||||
text "Your browser does not support the audio tag"
|
||||
source src: view.asset_path("song.ogg"), type: "audio/ogg"
|
||||
source src: view.asset_path("song.wav"), type: "audio/wav"
|
||||
end.to_s
|
||||
|
||||
expect(actual).to eq(%(<audio>\nYour browser does not support the audio tag\n<source src="/assets/song.ogg" type="audio/ogg">\n<source src="/assets/song.wav" type="audio/wav">\n</audio>))
|
||||
end
|
||||
|
||||
it 'raises an exception when no arguments' do
|
||||
it "raises an exception when no arguments" do
|
||||
expect do
|
||||
view.audio
|
||||
end.to raise_error(ArgumentError,
|
||||
'You should provide a source via `src` option or with a `source` HTML tag')
|
||||
"You should provide a source via `src` option or with a `source` HTML tag")
|
||||
end
|
||||
|
||||
it 'raises an exception when no src and no block' do
|
||||
it "raises an exception when no src and no block" do
|
||||
expect do
|
||||
view.audio(controls: true)
|
||||
end.to raise_error(ArgumentError,
|
||||
'You should provide a source via `src` option or with a `source` HTML tag')
|
||||
"You should provide a source via `src` option or with a `source` HTML tag")
|
||||
end
|
||||
|
||||
describe 'cdn mode' do
|
||||
describe "cdn mode" do
|
||||
before do
|
||||
activate_cdn_mode!
|
||||
end
|
||||
|
||||
it 'returns absolute url for src attribute' do
|
||||
actual = view.audio('song.ogg').to_s
|
||||
it "returns absolute url for src attribute" do
|
||||
actual = view.audio("song.ogg").to_s
|
||||
expect(actual).to eq(%(<audio src="#{cdn_url}/assets/song.ogg"></audio>))
|
||||
end
|
||||
end
|
||||
|
@ -542,25 +544,25 @@ describe Hanami::Assets::Helpers do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#asset_path' do
|
||||
it 'returns relative URL for given asset name' do
|
||||
result = view.asset_path('application.js')
|
||||
expect(result).to eq('/assets/application.js')
|
||||
describe "#asset_path" do
|
||||
it "returns relative URL for given asset name" do
|
||||
result = view.asset_path("application.js")
|
||||
expect(result).to eq("/assets/application.js")
|
||||
end
|
||||
|
||||
it 'returns absolute URL if the argument is an absolute URL' do
|
||||
result = view.asset_path('http://assets.hanamirb.org/assets/application.css')
|
||||
expect(result).to eq('http://assets.hanamirb.org/assets/application.css')
|
||||
it "returns absolute URL if the argument is an absolute URL" do
|
||||
result = view.asset_path("http://assets.hanamirb.org/assets/application.css")
|
||||
expect(result).to eq("http://assets.hanamirb.org/assets/application.css")
|
||||
end
|
||||
|
||||
describe 'cdn mode' do
|
||||
describe "cdn mode" do
|
||||
before do
|
||||
activate_cdn_mode!
|
||||
end
|
||||
|
||||
it 'returns absolute url' do
|
||||
result = view.asset_path('application.js')
|
||||
expect(result).to eq('https://bookshelf.cdn-example.com/assets/application.js')
|
||||
it "returns absolute url" do
|
||||
result = view.asset_path("application.js")
|
||||
expect(result).to eq("https://bookshelf.cdn-example.com/assets/application.js")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -577,7 +579,7 @@ describe Hanami::Assets::Helpers do
|
|||
assets = Thread.current[:__hanami_assets]
|
||||
|
||||
expect(assets).to be_kind_of(Hash)
|
||||
expect(assets.fetch('/assets/dashboard.js')).to eq(as: nil, crossorigin: false)
|
||||
expect(assets.fetch("/assets/dashboard.js")).to eq(as: nil, crossorigin: false)
|
||||
end
|
||||
|
||||
it "allows to specify asset type" do
|
||||
|
@ -585,7 +587,7 @@ describe Hanami::Assets::Helpers do
|
|||
assets = Thread.current[:__hanami_assets]
|
||||
|
||||
expect(assets).to be_kind_of(Hash)
|
||||
expect(assets.fetch('/assets/video.mp4')).to eq(as: :video, crossorigin: false)
|
||||
expect(assets.fetch("/assets/video.mp4")).to eq(as: :video, crossorigin: false)
|
||||
end
|
||||
|
||||
it "allows to link crossorigin asset" do
|
||||
|
@ -598,29 +600,29 @@ describe Hanami::Assets::Helpers do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#asset_url' do
|
||||
describe "#asset_url" do
|
||||
before do
|
||||
view.class.assets_configuration.load!
|
||||
end
|
||||
|
||||
it 'returns absolute URL for given asset name' do
|
||||
result = view.asset_url('application.js')
|
||||
expect(result).to eq('http://localhost:2300/assets/application.js')
|
||||
it "returns absolute URL for given asset name" do
|
||||
result = view.asset_url("application.js")
|
||||
expect(result).to eq("http://localhost:2300/assets/application.js")
|
||||
end
|
||||
|
||||
it 'returns absolute URL if the argument is an absolute URL' do
|
||||
result = view.asset_url('http://assets.hanamirb.org/assets/application.css')
|
||||
expect(result).to eq('http://assets.hanamirb.org/assets/application.css')
|
||||
it "returns absolute URL if the argument is an absolute URL" do
|
||||
result = view.asset_url("http://assets.hanamirb.org/assets/application.css")
|
||||
expect(result).to eq("http://assets.hanamirb.org/assets/application.css")
|
||||
end
|
||||
|
||||
describe 'cdn mode' do
|
||||
describe "cdn mode" do
|
||||
before do
|
||||
activate_cdn_mode!
|
||||
end
|
||||
|
||||
it 'still returns absolute url' do
|
||||
result = view.asset_url('application.js')
|
||||
expect(result).to eq('https://bookshelf.cdn-example.com/assets/application.js')
|
||||
it "still returns absolute url" do
|
||||
result = view.asset_url("application.js")
|
||||
expect(result).to eq("https://bookshelf.cdn-example.com/assets/application.js")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -665,14 +667,14 @@ describe Hanami::Assets::Helpers do
|
|||
view.class.assets_configuration.load!
|
||||
|
||||
manifest = Hanami::Assets::Config::Manifest.new({
|
||||
'/assets/feature-a.js' => {
|
||||
'sri' => [
|
||||
'sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC'
|
||||
"/assets/feature-a.js" => {
|
||||
"sri" => [
|
||||
"sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC"
|
||||
]
|
||||
},
|
||||
'/assets/main.css' => {
|
||||
'sri' => [
|
||||
'sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC'
|
||||
"/assets/main.css" => {
|
||||
"sri" => [
|
||||
"sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC"
|
||||
]
|
||||
}
|
||||
}, [])
|
||||
|
@ -680,9 +682,9 @@ describe Hanami::Assets::Helpers do
|
|||
end
|
||||
|
||||
def activate_cdn_mode! # rubocop:disable Metrics/AbcSize
|
||||
view.class.assets_configuration.scheme 'https'
|
||||
view.class.assets_configuration.host 'bookshelf.cdn-example.com'
|
||||
view.class.assets_configuration.port '443'
|
||||
view.class.assets_configuration.scheme "https"
|
||||
view.class.assets_configuration.host "bookshelf.cdn-example.com"
|
||||
view.class.assets_configuration.port "443"
|
||||
view.class.assets_configuration.cdn true
|
||||
|
||||
view.class.assets_configuration.load!
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
describe "Hanami::Assets::VERSION" do
|
||||
it "exposes version" do
|
||||
expect(Hanami::Assets::VERSION).to eq("1.1.0")
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
describe Hanami::Assets do
|
||||
describe '.sources' do
|
||||
describe ".sources" do
|
||||
before do
|
||||
Hanami::Assets.sources.clear
|
||||
end
|
||||
|
@ -12,19 +14,19 @@ describe Hanami::Assets do
|
|||
expect(Hanami::Assets.sources).to be_empty
|
||||
end
|
||||
|
||||
it 'allows to add a source' do
|
||||
it "allows to add a source" do
|
||||
Hanami::Assets.sources << __dir__
|
||||
|
||||
expect(Hanami::Assets.sources).to eq([__dir__])
|
||||
end
|
||||
|
||||
it 'adds a source to the configuration' do
|
||||
it "adds a source to the configuration" do
|
||||
Hanami::Assets.sources << __dir__
|
||||
expect(Hanami::Assets.configuration.sources).to include(__dir__)
|
||||
end
|
||||
|
||||
it 'keeps duplicated frameworks in sync' do
|
||||
source = __dir__ + '/fixtures/bookshelf/vendor/assets' + '/fixtures/bookshelf/vendor/assets'
|
||||
it "keeps duplicated frameworks in sync" do
|
||||
source = __dir__ + "/fixtures/bookshelf/vendor/assets" + "/fixtures/bookshelf/vendor/assets"
|
||||
Hanami::Assets.sources << source
|
||||
|
||||
Hanami::Assets.duplicates.map(&:configuration).each do |config|
|
||||
|
|
Loading…
Reference in New Issue