Rubocop'd
This commit is contained in:
commit
f513ab77b3
2
Gemfile
2
Gemfile
|
@ -12,7 +12,6 @@ gem 'rspec', '~> 2.12'
|
||||||
gem 'simplecov'
|
gem 'simplecov'
|
||||||
|
|
||||||
# Optional middleman dependencies, included for tests
|
# Optional middleman dependencies, included for tests
|
||||||
gem 'haml', '~> 4.0.0', require: false # Make sure to use Haml 4 for tests
|
|
||||||
gem 'sinatra', require: false
|
gem 'sinatra', require: false
|
||||||
gem 'slim', require: false
|
gem 'slim', require: false
|
||||||
gem 'liquid', require: false
|
gem 'liquid', require: false
|
||||||
|
@ -30,7 +29,6 @@ platforms :jruby do
|
||||||
end
|
end
|
||||||
|
|
||||||
# Code Quality
|
# Code Quality
|
||||||
gem 'cane', platforms: [:mri_19, :mri_20], require: false
|
|
||||||
gem 'coveralls', require: false
|
gem 'coveralls', require: false
|
||||||
gem 'rubocop', require: false, group: :development
|
gem 'rubocop', require: false, group: :development
|
||||||
|
|
||||||
|
|
60
Rakefile
60
Rakefile
|
@ -1,5 +1,4 @@
|
||||||
require 'rubygems' unless defined?(Gem)
|
require 'rubygems' unless defined?(Gem)
|
||||||
# require 'fileutils' unless defined?(FileUtils)
|
|
||||||
require 'rake'
|
require 'rake'
|
||||||
|
|
||||||
require File.expand_path('../middleman-core/lib/middleman-core/version.rb', __FILE__)
|
require File.expand_path('../middleman-core/lib/middleman-core/version.rb', __FILE__)
|
||||||
|
@ -14,51 +13,14 @@ def sh_rake(command)
|
||||||
sh "#{Gem.ruby} -S rake #{command}", verbose: true
|
sh "#{Gem.ruby} -S rake #{command}", verbose: true
|
||||||
end
|
end
|
||||||
|
|
||||||
def say(text, color=:magenta)
|
|
||||||
n = { bold: 1, red: 31, green: 32, yellow: 33, blue: 34, magenta: 35 }.fetch(color, 0)
|
|
||||||
puts "\e[%dm%s\e[0m" % [n, text]
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "Run 'install' for all projects"
|
|
||||||
task :install do
|
|
||||||
GEM_PATHS.each do |dir|
|
|
||||||
Dir.chdir(dir) { sh_rake(:install) }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc 'Clean pkg and other stuff'
|
|
||||||
task :clean do
|
|
||||||
GEM_PATHS.each do |g|
|
|
||||||
%w(tmp pkg coverage).each { |dir| sh 'rm -rf %s' % File.join(g, dir) }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc 'Clean pkg and other stuff'
|
|
||||||
task :uninstall do
|
|
||||||
sh 'gem search --no-version middleman | grep middleman | xargs gem uninstall -a'
|
|
||||||
end
|
|
||||||
|
|
||||||
desc 'Displays the current version'
|
desc 'Displays the current version'
|
||||||
task :version do
|
task :version do
|
||||||
say "Current version: #{Middleman::VERSION}"
|
puts "Current version: #{Middleman::VERSION}"
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Bumps the version number based on given version'
|
|
||||||
task :bump, [:version] do |t, args|
|
|
||||||
raise 'Please specify version=x.x.x !' unless args.version
|
|
||||||
version_path = File.dirname(__FILE__) + '/middleman-core/lib/middleman-core/version.rb'
|
|
||||||
version_text = File.read(version_path).sub(/VERSION = '[\d\.\w]+'/, "VERSION = '#{args.version}'")
|
|
||||||
say "Updating Middleman to version #{args.version}"
|
|
||||||
File.open(version_path, 'w') { |f| f.write version_text }
|
|
||||||
sh 'git commit -a -m "Bumped version to %s"' % args.version
|
|
||||||
end
|
|
||||||
|
|
||||||
desc 'Executes a fresh install removing all middleman version and then reinstall all gems'
|
|
||||||
task fresh: [:uninstall, :install, :clean]
|
|
||||||
|
|
||||||
desc 'Pushes repository to GitHub'
|
desc 'Pushes repository to GitHub'
|
||||||
task :push do
|
task :push do
|
||||||
say 'Pushing to github...'
|
puts 'Pushing to github...'
|
||||||
sh "git tag v#{Middleman::VERSION}"
|
sh "git tag v#{Middleman::VERSION}"
|
||||||
sh 'git push origin master'
|
sh 'git push origin master'
|
||||||
sh "git push origin v#{Middleman::VERSION}"
|
sh "git push origin v#{Middleman::VERSION}"
|
||||||
|
@ -66,11 +28,10 @@ end
|
||||||
|
|
||||||
desc 'Release all middleman gems'
|
desc 'Release all middleman gems'
|
||||||
task publish: :push do
|
task publish: :push do
|
||||||
say 'Pushing to rubygems...'
|
puts 'Pushing to rubygems...'
|
||||||
GEM_PATHS.each do |dir|
|
GEM_PATHS.each do |dir|
|
||||||
Dir.chdir(dir) { sh_rake('release') }
|
Dir.chdir(dir) { sh_rake('release') }
|
||||||
end
|
end
|
||||||
Rake::Task['clean'].invoke
|
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Generate documentation for all middleman gems'
|
desc 'Generate documentation for all middleman gems'
|
||||||
|
@ -85,6 +46,7 @@ task :test do
|
||||||
GEM_PATHS.each do |g|
|
GEM_PATHS.each do |g|
|
||||||
Dir.chdir("#{File.join(ROOT, g)}") { sh "#{Gem.ruby} -S rake test" }
|
Dir.chdir("#{File.join(ROOT, g)}") { sh "#{Gem.ruby} -S rake test" }
|
||||||
end
|
end
|
||||||
|
Rake::Task['rubocop'].invoke
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Run specs for all middleman gems'
|
desc 'Run specs for all middleman gems'
|
||||||
|
@ -94,25 +56,11 @@ task :spec do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
|
||||||
require 'cane/rake_task'
|
|
||||||
desc 'Run cane to check quality metrics'
|
|
||||||
Cane::RakeTask.new(:quality) do |cane|
|
|
||||||
cane.no_style = true
|
|
||||||
cane.no_doc = true
|
|
||||||
cane.abc_glob = 'middleman*/lib/middleman*/**/*.rb'
|
|
||||||
end
|
|
||||||
rescue LoadError
|
|
||||||
end
|
|
||||||
|
|
||||||
begin
|
|
||||||
require 'rubocop/rake_task'
|
require 'rubocop/rake_task'
|
||||||
desc 'Run RuboCop to check code consistency'
|
desc 'Run RuboCop to check code consistency'
|
||||||
Rubocop::RakeTask.new(:rubocop) do |task|
|
Rubocop::RakeTask.new(:rubocop) do |task|
|
||||||
task.fail_on_error = false
|
task.fail_on_error = false
|
||||||
end
|
end
|
||||||
rescue LoadError
|
|
||||||
end
|
|
||||||
|
|
||||||
desc 'Run tests for all middleman gems'
|
desc 'Run tests for all middleman gems'
|
||||||
task default: :test
|
task default: :test
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# rubocop:disable FileName
|
||||||
|
|
||||||
# Setup our load paths
|
# Setup our load paths
|
||||||
libdir = File.expand_path(File.dirname(__FILE__))
|
libdir = File.expand_path(File.dirname(__FILE__))
|
||||||
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
||||||
|
@ -34,6 +36,7 @@ module Middleman
|
||||||
# @param [Symbol, String, nil] meth
|
# @param [Symbol, String, nil] meth
|
||||||
# @param [Boolean] subcommand
|
# @param [Boolean] subcommand
|
||||||
# @return [void]
|
# @return [void]
|
||||||
|
# rubocop:disable UnusedMethodArgument
|
||||||
def help(meth=nil, subcommand=false)
|
def help(meth=nil, subcommand=false)
|
||||||
if meth && !self.respond_to?(meth)
|
if meth && !self.respond_to?(meth)
|
||||||
klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
|
klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
|
||||||
|
@ -56,10 +59,7 @@ module Middleman
|
||||||
# @param [Symbol] meth
|
# @param [Symbol] meth
|
||||||
def method_missing(meth, *args)
|
def method_missing(meth, *args)
|
||||||
meth = meth.to_s
|
meth = meth.to_s
|
||||||
|
meth = self.class.map[meth] if self.class.map.key?(meth)
|
||||||
if self.class.map.key?(meth)
|
|
||||||
meth = self.class.map[meth]
|
|
||||||
end
|
|
||||||
|
|
||||||
klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
|
klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
if klass.nil?
|
if klass.nil?
|
||||||
raise Thor::Error.new "There's no '#{meth}' command for Middleman. Try 'middleman help' for a list of commands."
|
raise Thor::Error, "There's no '#{meth}' command for Middleman. Try 'middleman help' for a list of commands."
|
||||||
else
|
else
|
||||||
args.unshift(task) if task
|
args.unshift(task) if task
|
||||||
klass.start(args, shell: shell)
|
klass.start(args, shell: shell)
|
||||||
|
|
|
@ -273,7 +273,6 @@ module Middleman::Cli
|
||||||
base.say_status :error, file_name, :red
|
base.say_status :error, file_name, :red
|
||||||
if base.debugging
|
if base.debugging
|
||||||
raise e
|
raise e
|
||||||
exit(1)
|
|
||||||
elsif base.options['verbose']
|
elsif base.options['verbose']
|
||||||
base.shell.say response, :red
|
base.shell.say response, :red
|
||||||
end
|
end
|
||||||
|
|
|
@ -30,9 +30,7 @@ module Middleman::Cli
|
||||||
}
|
}
|
||||||
|
|
||||||
@app = ::Middleman::Application.server.inst do
|
@app = ::Middleman::Application.server.inst do
|
||||||
if opts[:environment]
|
config[:environment] = opts[:environment].to_sym if opts[:environment]
|
||||||
config[:environment] = opts[:environment].to_sym
|
|
||||||
end
|
|
||||||
|
|
||||||
::Middleman::Logger.singleton(opts[:debug] ? 0 : 1, opts[:instrumenting] || false)
|
::Middleman::Logger.singleton(opts[:debug] ? 0 : 1, opts[:instrumenting] || false)
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,7 +41,7 @@ module Middleman::Cli
|
||||||
def init(name='.')
|
def init(name='.')
|
||||||
key = options[:template].to_sym
|
key = options[:template].to_sym
|
||||||
unless ::Middleman::Templates.registered.key?(key)
|
unless ::Middleman::Templates.registered.key?(key)
|
||||||
raise Thor::Error.new "Unknown project template '#{key}'"
|
raise Thor::Error, "Unknown project template '#{key}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
thor_group = ::Middleman::Templates.registered[key]
|
thor_group = ::Middleman::Templates.registered[key]
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# rubocop:disable FileName
|
||||||
|
|
||||||
# Setup our load paths
|
# Setup our load paths
|
||||||
libdir = File.expand_path(File.dirname(__FILE__))
|
libdir = File.expand_path(File.dirname(__FILE__))
|
||||||
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
||||||
|
|
|
@ -43,16 +43,17 @@ module Middleman
|
||||||
# Get the value of a setting by key. Returns nil if there is no such setting.
|
# Get the value of a setting by key. Returns nil if there is no such setting.
|
||||||
# @return [Object]
|
# @return [Object]
|
||||||
def [](key)
|
def [](key)
|
||||||
setting = @settings[key]
|
setting_obj = setting(key)
|
||||||
setting ? setting.value : nil
|
setting_obj ? setting_obj.value : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Set the value of a setting by key. Creates the setting if it doesn't exist.
|
# Set the value of a setting by key. Creates the setting if it doesn't exist.
|
||||||
# @param [Symbol] key
|
# @param [Symbol] key
|
||||||
# @param [Object] val
|
# @param [Object] val
|
||||||
|
# rubocop:disable UselessSetterCall
|
||||||
def []=(key, val)
|
def []=(key, val)
|
||||||
setting = @settings[key] || define_setting(key)
|
setting_obj = setting(key) || define_setting(key)
|
||||||
setting.value = val
|
setting_obj.value = val
|
||||||
end
|
end
|
||||||
|
|
||||||
# Allow configuration settings to be read and written via methods
|
# Allow configuration settings to be read and written via methods
|
||||||
|
@ -159,6 +160,7 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
# Whether or not there has been a value set beyond the default
|
# Whether or not there has been a value set beyond the default
|
||||||
|
# rubocop:disable TrivialAccessors
|
||||||
def value_set?
|
def value_set?
|
||||||
@value_set
|
@value_set
|
||||||
end
|
end
|
||||||
|
|
|
@ -142,9 +142,6 @@ module Middleman
|
||||||
def data_for_path(path)
|
def data_for_path(path)
|
||||||
response = nil
|
response = nil
|
||||||
|
|
||||||
@@local_sources ||= {}
|
|
||||||
@@callback_sources ||= {}
|
|
||||||
|
|
||||||
if store.key?(path.to_s)
|
if store.key?(path.to_s)
|
||||||
response = store[path.to_s]
|
response = store[path.to_s]
|
||||||
elsif callbacks.key?(path.to_s)
|
elsif callbacks.key?(path.to_s)
|
||||||
|
@ -163,10 +160,7 @@ module Middleman
|
||||||
return @local_data[path.to_s]
|
return @local_data[path.to_s]
|
||||||
else
|
else
|
||||||
result = data_for_path(path)
|
result = data_for_path(path)
|
||||||
|
return ::Middleman::Util.recursively_enhance(result) if result
|
||||||
if result
|
|
||||||
return ::Middleman::Util.recursively_enhance(result)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
super
|
super
|
||||||
|
@ -186,21 +180,23 @@ module Middleman
|
||||||
__send__(key) if key?(key)
|
__send__(key) if key?(key)
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_key?(key)
|
def key?(key)
|
||||||
@local_data.key?(key.to_s) || !!(data_for_path(key))
|
@local_data.key?(key.to_s) || data_for_path(key)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
alias_method :has_key?, :key?
|
||||||
|
|
||||||
# Convert all the data into a static hash
|
# Convert all the data into a static hash
|
||||||
#
|
#
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
def to_h
|
def to_h
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
store.each do |k, v|
|
store.each do |k, _|
|
||||||
data[k] = data_for_path(k)
|
data[k] = data_for_path(k)
|
||||||
end
|
end
|
||||||
|
|
||||||
callbacks.each do |k, v|
|
callbacks.each do |k, _|
|
||||||
data[k] = data_for_path(k)
|
data[k] = data_for_path(k)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ require 'padrino-helpers'
|
||||||
|
|
||||||
class Padrino::Helpers::OutputHelpers::ErbHandler
|
class Padrino::Helpers::OutputHelpers::ErbHandler
|
||||||
# Force Erb capture not to use safebuffer
|
# Force Erb capture not to use safebuffer
|
||||||
|
# rubocop:disable UnderscorePrefixedVariableName
|
||||||
def capture_from_template(*args, &block)
|
def capture_from_template(*args, &block)
|
||||||
self.output_buffer, _buf_was = '', output_buffer
|
self.output_buffer, _buf_was = '', output_buffer
|
||||||
raw = block.call(*args)
|
raw = block.call(*args)
|
||||||
|
@ -38,6 +39,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
||||||
helpers do
|
helpers do
|
||||||
|
|
||||||
# Make all block content html_safe
|
# Make all block content html_safe
|
||||||
|
# rubocop:disable Semicolon
|
||||||
def content_tag(name, content=nil, options=nil, &block)
|
def content_tag(name, content=nil, options=nil, &block)
|
||||||
# safe_content_tag(name, content, options, &block)
|
# safe_content_tag(name, content, options, &block)
|
||||||
if block_given?
|
if block_given?
|
||||||
|
@ -70,6 +72,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
||||||
ActiveSupport::SafeBuffer.new.safe_concat(result)
|
ActiveSupport::SafeBuffer.new.safe_concat(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# rubocop:disable MultilineBlockChain, UnusedBlockArgument
|
||||||
def auto_find_proper_handler(&block)
|
def auto_find_proper_handler(&block)
|
||||||
if block_given?
|
if block_given?
|
||||||
engine = File.extname(block.source_location[0])[1..-1].to_sym
|
engine = File.extname(block.source_location[0])[1..-1].to_sym
|
||||||
|
@ -116,8 +119,10 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
||||||
def auto_tag(asset_ext, asset_dir=nil)
|
def auto_tag(asset_ext, asset_dir=nil)
|
||||||
if asset_dir.nil?
|
if asset_dir.nil?
|
||||||
asset_dir = case asset_ext
|
asset_dir = case asset_ext
|
||||||
when :js then config[:js_dir]
|
when :js
|
||||||
when :css then config[:css_dir]
|
config[:js_dir]
|
||||||
|
when :css
|
||||||
|
config[:css_dir]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -164,13 +169,20 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def asset_path(kind, source, options={})
|
def asset_path(kind, source, options={})
|
||||||
return source if source.to_s.include?('//') || source.to_s.start_with?('data:')
|
return source if source.to_s.include?('//') || source.to_s.start_with?('data:')
|
||||||
|
|
||||||
asset_folder = case kind
|
asset_folder = case kind
|
||||||
when :css then config[:css_dir]
|
when :css
|
||||||
when :js then config[:js_dir]
|
config[:css_dir]
|
||||||
when :images then config[:images_dir]
|
when :js
|
||||||
when :fonts then config[:fonts_dir]
|
config[:js_dir]
|
||||||
else kind.to_s
|
when :images
|
||||||
|
config[:images_dir]
|
||||||
|
when :fonts
|
||||||
|
config[:fonts_dir]
|
||||||
|
else
|
||||||
|
kind.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
source = source.to_s.tr(' ', '')
|
source = source.to_s.tr(' ', '')
|
||||||
ignore_extension = (kind == :images || kind == :fonts) # don't append extension
|
ignore_extension = (kind == :images || kind == :fonts) # don't append extension
|
||||||
source << ".#{kind}" unless ignore_extension || source.end_with?(".#{kind}")
|
source << ".#{kind}" unless ignore_extension || source.end_with?(".#{kind}")
|
||||||
|
@ -185,9 +197,10 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
||||||
# @param [String] prefix The type prefix (such as "images")
|
# @param [String] prefix The type prefix (such as "images")
|
||||||
# @param [Hash] options Data to pass through.
|
# @param [Hash] options Data to pass through.
|
||||||
# @return [String] The fully qualified asset url
|
# @return [String] The fully qualified asset url
|
||||||
|
# rubocop:disable UnusedMethodArgument
|
||||||
def asset_url(path, prefix='', options={})
|
def asset_url(path, prefix='', options={})
|
||||||
# Don't touch assets which already have a full path
|
# Don't touch assets which already have a full path
|
||||||
if path.include?('//') or path.start_with?('data:')
|
if path.include?('//') || path.start_with?('data:')
|
||||||
path
|
path
|
||||||
else # rewrite paths to use their destination path
|
else # rewrite paths to use their destination path
|
||||||
if resource = sitemap.find_resource_by_destination_path(url_for(path))
|
if resource = sitemap.find_resource_by_destination_path(url_for(path))
|
||||||
|
@ -229,12 +242,12 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
||||||
options_index = block_given? ? 1 : 2
|
options_index = block_given? ? 1 : 2
|
||||||
|
|
||||||
if block_given? && args.size > 2
|
if block_given? && args.size > 2
|
||||||
raise ArgumentError.new('Too many arguments to link_to(url, options={}, &block)')
|
raise ArgumentError, 'Too many arguments to link_to(url, options={}, &block)'
|
||||||
end
|
end
|
||||||
|
|
||||||
if url = args[url_arg_index]
|
if url = args[url_arg_index]
|
||||||
options = args[options_index] || {}
|
options = args[options_index] || {}
|
||||||
raise ArgumentError.new('Options must be a hash') unless options.is_a?(Hash)
|
raise ArgumentError, 'Options must be a hash' unless options.is_a?(Hash)
|
||||||
|
|
||||||
# Transform the url through our magic url_for method
|
# Transform the url through our magic url_for method
|
||||||
args[url_arg_index] = url_for(url, options)
|
args[url_arg_index] = url_for(url, options)
|
||||||
|
|
|
@ -73,6 +73,7 @@ module Middleman
|
||||||
#
|
#
|
||||||
# @param [Symbol, Module] ext Which extension to activate
|
# @param [Symbol, Module] ext Which extension to activate
|
||||||
# @return [void]
|
# @return [void]
|
||||||
|
# rubocop:disable BlockNesting
|
||||||
def activate(ext, options={}, &block)
|
def activate(ext, options={}, &block)
|
||||||
extension = ::Middleman::Extensions.load(ext)
|
extension = ::Middleman::Extensions.load(ext)
|
||||||
logger.debug "== Activating: #{ext}"
|
logger.debug "== Activating: #{ext}"
|
||||||
|
|
|
@ -119,6 +119,7 @@ module Middleman::CoreExtensions
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Parse YAML frontmatter out of a string
|
# Parse YAML frontmatter out of a string
|
||||||
# @param [String] content
|
# @param [String] content
|
||||||
# @return [Array<Hash, String>]
|
# @return [Array<Hash, String>]
|
||||||
|
|
|
@ -58,7 +58,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
||||||
delegate :logger, to: :app
|
delegate :logger, to: :app
|
||||||
|
|
||||||
def langs
|
def langs
|
||||||
@_langs ||= get_known_languages
|
@_langs ||= known_languages
|
||||||
end
|
end
|
||||||
|
|
||||||
# Update the main sitemap resource list
|
# Update the main sitemap resource list
|
||||||
|
@ -72,8 +72,8 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
||||||
# If it uses file extension localization
|
# If it uses file extension localization
|
||||||
if parse_locale_extension(resource.path)
|
if parse_locale_extension(resource.path)
|
||||||
result = parse_locale_extension(resource.path)
|
result = parse_locale_extension(resource.path)
|
||||||
lang, path, page_id = result
|
ext_lang, path, page_id = result
|
||||||
new_resources << build_resource(path, resource.path, page_id, lang)
|
new_resources << build_resource(path, resource.path, page_id, ext_lang)
|
||||||
# If it's a "localizable template"
|
# If it's a "localizable template"
|
||||||
elsif File.fnmatch?(File.join(options[:templates_dir], '**'), resource.path)
|
elsif File.fnmatch?(File.join(options[:templates_dir], '**'), resource.path)
|
||||||
page_id = File.basename(resource.path, File.extname(resource.path))
|
page_id = File.basename(resource.path, File.extname(resource.path))
|
||||||
|
@ -99,7 +99,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
||||||
|
|
||||||
def convert_glob_to_regex(glob)
|
def convert_glob_to_regex(glob)
|
||||||
# File.fnmatch doesn't support brackets: {rb,yml,yaml}
|
# File.fnmatch doesn't support brackets: {rb,yml,yaml}
|
||||||
regex = @locales_glob.sub(/\./, '\.').sub(File.join('**', '*'), '.*').sub(/\//, '\/').sub('{rb,yml,yaml}', '(rb|ya?ml)')
|
regex = glob.sub(/\./, '\.').sub(File.join('**', '*'), '.*').sub(/\//, '\/').sub('{rb,yml,yaml}', '(rb|ya?ml)')
|
||||||
%r{^#{regex}}
|
%r{^#{regex}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
||||||
end
|
end
|
||||||
|
|
||||||
def metadata_for_path(url)
|
def metadata_for_path(url)
|
||||||
if d = get_localization_data(url)
|
if d = localization_data(url)
|
||||||
lang, page_id = d
|
lang, page_id = d
|
||||||
else
|
else
|
||||||
# Default to the @mount_at_root lang
|
# Default to the @mount_at_root lang
|
||||||
|
@ -132,19 +132,21 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_known_languages
|
def known_languages
|
||||||
if options[:langs]
|
if options[:langs]
|
||||||
Array(options[:langs]).map(&:to_sym)
|
Array(options[:langs]).map(&:to_sym)
|
||||||
else
|
else
|
||||||
known_langs = app.files.known_paths.select do |p|
|
known_langs = app.files.known_paths.select do |p|
|
||||||
p.to_s.match(@locales_regex) && (p.to_s.split(File::SEPARATOR).length === 2)
|
p.to_s.match(@locales_regex) && (p.to_s.split(File::SEPARATOR).length == 2)
|
||||||
end.map { |p|
|
end
|
||||||
|
|
||||||
|
known_langs.map { |p|
|
||||||
File.basename(p.to_s).sub(/\.ya?ml$/, '').sub(/\.rb$/, '')
|
File.basename(p.to_s).sub(/\.ya?ml$/, '').sub(/\.rb$/, '')
|
||||||
}.sort.map(&:to_sym)
|
}.sort.map(&:to_sym)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_localization_data(path)
|
def localization_data(path)
|
||||||
@_localization_data ||= {}
|
@_localization_data ||= {}
|
||||||
@_localization_data[path]
|
@_localization_data[path]
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
require 'middleman-core/template_context'
|
require 'middleman-core/template_context'
|
||||||
|
|
||||||
# Rendering extension
|
# Rendering extension
|
||||||
|
# rubocop:disable UnderscorePrefixedVariableName
|
||||||
module Middleman
|
module Middleman
|
||||||
module CoreExtensions
|
module CoreExtensions
|
||||||
module Rendering
|
module Rendering
|
||||||
|
@ -75,7 +76,7 @@ module Middleman
|
||||||
|
|
||||||
# Clean up missing Tilt exts
|
# Clean up missing Tilt exts
|
||||||
app.after_configuration do
|
app.after_configuration do
|
||||||
Tilt.mappings.each do |key, klasses|
|
Tilt.mappings.each do |key, _|
|
||||||
begin
|
begin
|
||||||
Tilt[".#{key}"]
|
Tilt[".#{key}"]
|
||||||
rescue LoadError, NameError
|
rescue LoadError, NameError
|
||||||
|
|
|
@ -70,15 +70,15 @@ module Middleman
|
||||||
app.use Rack::Lint
|
app.use Rack::Lint
|
||||||
app.use Rack::Head
|
app.use Rack::Head
|
||||||
|
|
||||||
Array(@middleware).each do |klass, options, block|
|
Array(@middleware).each do |klass, options, middleware_block|
|
||||||
app.use(klass, *options, &block)
|
app.use(klass, *options, &middleware_block)
|
||||||
end
|
end
|
||||||
|
|
||||||
inner_app = inst(&block)
|
inner_app = inst(&block)
|
||||||
app.map('/') { run inner_app }
|
app.map('/') { run inner_app }
|
||||||
|
|
||||||
Array(@mappings).each do |path, block|
|
Array(@mappings).each do |path, map_block|
|
||||||
app.map(path, &block)
|
app.map(path, &map_block)
|
||||||
end
|
end
|
||||||
|
|
||||||
app
|
app
|
||||||
|
@ -126,6 +126,7 @@ module Middleman
|
||||||
# configuration can be included later without impacting
|
# configuration can be included later without impacting
|
||||||
# other classes and instances.
|
# other classes and instances.
|
||||||
#
|
#
|
||||||
|
# rubocop:disable ClassVars
|
||||||
# @return [Class]
|
# @return [Class]
|
||||||
def server(&block)
|
def server(&block)
|
||||||
@@servercounter ||= 0
|
@@servercounter ||= 0
|
||||||
|
@ -189,7 +190,7 @@ module Middleman
|
||||||
# @param env
|
# @param env
|
||||||
# @param [Rack::Request] req
|
# @param [Rack::Request] req
|
||||||
# @param [Rack::Response] res
|
# @param [Rack::Response] res
|
||||||
def process_request(env, req, res)
|
def process_request(env, _, res)
|
||||||
start_time = Time.now
|
start_time = Time.now
|
||||||
|
|
||||||
request_path = URI.decode(env['PATH_INFO'].dup)
|
request_path = URI.decode(env['PATH_INFO'].dup)
|
||||||
|
|
|
@ -13,9 +13,7 @@ module Middleman
|
||||||
# When in dev
|
# When in dev
|
||||||
app.configure :development do
|
app.configure :development do
|
||||||
# Include middlemare
|
# Include middlemare
|
||||||
if config[:show_exceptions]
|
use ::Rack::ShowExceptions if config[:show_exceptions]
|
||||||
use ::Rack::ShowExceptions
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -87,7 +87,7 @@ module Middleman
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def setup_options(options_hash, &block)
|
def setup_options(options_hash)
|
||||||
@options = self.class.config.dup
|
@options = self.class.config.dup
|
||||||
@options.finalize!
|
@options.finalize!
|
||||||
|
|
||||||
|
@ -122,10 +122,9 @@ module Middleman
|
||||||
def bind_after_configuration
|
def bind_after_configuration
|
||||||
ext = self
|
ext = self
|
||||||
@klass.after_configuration do
|
@klass.after_configuration do
|
||||||
if ext.respond_to?(:after_configuration)
|
ext.after_configuration if ext.respond_to?(:after_configuration)
|
||||||
ext.after_configuration
|
|
||||||
end
|
|
||||||
|
|
||||||
|
# rubocop:disable IfUnlessModifier
|
||||||
if ext.respond_to?(:manipulate_resource_list)
|
if ext.respond_to?(:manipulate_resource_list)
|
||||||
ext.app.sitemap.register_resource_list_manipulator(ext.class.ext_name, ext)
|
ext.app.sitemap.register_resource_list_manipulator(ext.class.ext_name, ext)
|
||||||
end
|
end
|
||||||
|
@ -136,7 +135,7 @@ module Middleman
|
||||||
ext = self
|
ext = self
|
||||||
if ext.respond_to?(:before_build)
|
if ext.respond_to?(:before_build)
|
||||||
@klass.before_build do |builder|
|
@klass.before_build do |builder|
|
||||||
if ext.method(:before_build).arity === 1
|
if ext.method(:before_build).arity == 1
|
||||||
ext.before_build(builder)
|
ext.before_build(builder)
|
||||||
else
|
else
|
||||||
ext.before_build
|
ext.before_build
|
||||||
|
@ -149,7 +148,7 @@ module Middleman
|
||||||
ext = self
|
ext = self
|
||||||
if ext.respond_to?(:after_build)
|
if ext.respond_to?(:after_build)
|
||||||
@klass.after_build do |builder|
|
@klass.after_build do |builder|
|
||||||
if ext.method(:after_build).arity === 1
|
if ext.method(:after_build).arity == 1
|
||||||
ext.after_build(builder)
|
ext.after_build(builder)
|
||||||
else
|
else
|
||||||
ext.after_build
|
ext.after_build
|
||||||
|
|
|
@ -30,9 +30,7 @@ module Middleman
|
||||||
# extension is activated.
|
# extension is activated.
|
||||||
def register(name, namespace=nil, &block)
|
def register(name, namespace=nil, &block)
|
||||||
# If we've already got an extension registered under this name, bail out
|
# If we've already got an extension registered under this name, bail out
|
||||||
if registered.key?(name.to_sym)
|
raise "There is already an extension registered with the name '#{name}'" if registered.key?(name.to_sym)
|
||||||
raise "There is already an extension registered with the name '#{name}'"
|
|
||||||
end
|
|
||||||
|
|
||||||
registered[name.to_sym] = if block_given?
|
registered[name.to_sym] = if block_given?
|
||||||
block
|
block
|
||||||
|
|
|
@ -39,7 +39,9 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
||||||
else
|
else
|
||||||
-1
|
-1
|
||||||
end
|
end
|
||||||
end.each do |resource|
|
end
|
||||||
|
|
||||||
|
sorted_resources.each do |resource|
|
||||||
next unless options.exts.include?(resource.ext)
|
next unless options.exts.include?(resource.ext)
|
||||||
next if ignored_resource?(resource)
|
next if ignored_resource?(resource)
|
||||||
next if resource.ignored?
|
next if resource.ignored?
|
||||||
|
|
|
@ -14,7 +14,7 @@ class Middleman::Extensions::AssetHost < ::Middleman::Extension
|
||||||
if asset_host.is_a?(Proc)
|
if asset_host.is_a?(Proc)
|
||||||
config.asset_host(&asset_host)
|
config.asset_host(&asset_host)
|
||||||
else
|
else
|
||||||
config.asset_host do |asset|
|
config.asset_host do |_|
|
||||||
asset_host
|
asset_host
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,7 +39,7 @@ class Middleman::Extensions::Gzip < ::Middleman::Extension
|
||||||
|
|
||||||
# Farm out gzip tasks to threads and put the results in in_queue
|
# Farm out gzip tasks to threads and put the results in in_queue
|
||||||
out_queue = Queue.new
|
out_queue = Queue.new
|
||||||
threads = num_threads.times.map do
|
num_threads.times.each do
|
||||||
Thread.new do
|
Thread.new do
|
||||||
while path = in_queue.pop
|
while path = in_queue.pop
|
||||||
out_queue << gzip_file(path.to_s)
|
out_queue << gzip_file(path.to_s)
|
||||||
|
|
|
@ -17,7 +17,7 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
|
||||||
class SassCompressor
|
class SassCompressor
|
||||||
def self.compress(style, options={})
|
def self.compress(style, options={})
|
||||||
root_node = ::Sass::SCSS::CssParser.new(style, 'middleman-css-input', 1).parse
|
root_node = ::Sass::SCSS::CssParser.new(style, 'middleman-css-input', 1).parse
|
||||||
root_node.options = { style: :compressed }
|
root_node.options = options.merge(style: :compressed)
|
||||||
root_node.render.strip
|
root_node.render.strip
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -47,7 +47,7 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
|
||||||
|
|
||||||
if inline_html_content?(env['PATH_INFO'])
|
if inline_html_content?(env['PATH_INFO'])
|
||||||
minified = ::Middleman::Util.extract_response_text(response)
|
minified = ::Middleman::Util.extract_response_text(response)
|
||||||
minified.gsub!(INLINE_CSS_REGEX) do |match|
|
minified.gsub!(INLINE_CSS_REGEX) do
|
||||||
$1 << @compressor.compress($2) << $3
|
$1 << @compressor.compress($2) << $3
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -64,6 +64,7 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def inline_html_content?(path)
|
def inline_html_content?(path)
|
||||||
(path.end_with?('.html') || path.end_with?('.php')) && @inline
|
(path.end_with?('.html') || path.end_with?('.php')) && @inline
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,6 +20,7 @@ module Middleman
|
||||||
# @param [Hash] opts
|
# @param [Hash] opts
|
||||||
# @param [Class] context
|
# @param [Class] context
|
||||||
# @return [String]
|
# @return [String]
|
||||||
|
# rubocop:disable UnderscorePrefixedVariableName
|
||||||
def render(locs={}, opts={}, context, &block)
|
def render(locs={}, opts={}, context, &block)
|
||||||
path = @path.dup
|
path = @path.dup
|
||||||
|
|
||||||
|
@ -37,7 +38,7 @@ module Middleman
|
||||||
body = if opts[:template_body]
|
body = if opts[:template_body]
|
||||||
opts.delete(:template_body)
|
opts.delete(:template_body)
|
||||||
else
|
else
|
||||||
get_template_data_for_file
|
template_data_for_file
|
||||||
end
|
end
|
||||||
|
|
||||||
# Merge per-extension options from config
|
# Merge per-extension options from config
|
||||||
|
@ -81,7 +82,7 @@ module Middleman
|
||||||
# Get the template data from a path
|
# Get the template data from a path
|
||||||
# @param [String] path
|
# @param [String] path
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def get_template_data_for_file
|
def template_data_for_file
|
||||||
if @app.extensions[:front_matter]
|
if @app.extensions[:front_matter]
|
||||||
@app.extensions[:front_matter].template_data_for_file(@path)
|
@app.extensions[:front_matter].template_data_for_file(@path)
|
||||||
else
|
else
|
||||||
|
|
|
@ -40,12 +40,12 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
# The index page
|
# The index page
|
||||||
def index(env)
|
def index(_)
|
||||||
template('index.html.erb')
|
template('index.html.erb')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Inspect the sitemap
|
# Inspect the sitemap
|
||||||
def sitemap(env)
|
def sitemap(_)
|
||||||
resources = @middleman.inst.sitemap.resources(true)
|
resources = @middleman.inst.sitemap.resources(true)
|
||||||
|
|
||||||
sitemap_tree = SitemapTree.new
|
sitemap_tree = SitemapTree.new
|
||||||
|
@ -58,7 +58,7 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
# Inspect configuration
|
# Inspect configuration
|
||||||
def config(env)
|
def config(_)
|
||||||
global_config = @middleman.inst.config.all_settings.map { |c| ConfigSetting.new(c) }
|
global_config = @middleman.inst.config.all_settings.map { |c| ConfigSetting.new(c) }
|
||||||
extension_config = {}
|
extension_config = {}
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,7 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
def render
|
def render
|
||||||
content = ''
|
sorted_children_keys = @children.keys.sort do |a, b|
|
||||||
@children.keys.sort do |a, b|
|
|
||||||
a_subtree = @children[a]
|
a_subtree = @children[a]
|
||||||
b_subtree = @children[b]
|
b_subtree = @children[b]
|
||||||
if a_subtree.is_a? SitemapResource
|
if a_subtree.is_a? SitemapResource
|
||||||
|
@ -32,7 +31,9 @@ module Middleman
|
||||||
else
|
else
|
||||||
a.downcase <=> b.downcase
|
a.downcase <=> b.downcase
|
||||||
end
|
end
|
||||||
end.each do |path_part|
|
end
|
||||||
|
|
||||||
|
sorted_children_keys.reduce('') do |content, path_part|
|
||||||
subtree = @children[path_part]
|
subtree = @children[path_part]
|
||||||
content << "<details class='#{subtree.css_classes.join(' ')}'>"
|
content << "<details class='#{subtree.css_classes.join(' ')}'>"
|
||||||
content << '<summary>'
|
content << '<summary>'
|
||||||
|
@ -41,7 +42,6 @@ module Middleman
|
||||||
content << subtree.render
|
content << subtree.render
|
||||||
content << '</details>'
|
content << '</details>'
|
||||||
end
|
end
|
||||||
content
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def css_classes
|
def css_classes
|
||||||
|
|
|
@ -2,6 +2,7 @@ require 'webrick'
|
||||||
require 'middleman-core/meta_pages'
|
require 'middleman-core/meta_pages'
|
||||||
require 'middleman-core/logger'
|
require 'middleman-core/logger'
|
||||||
|
|
||||||
|
# rubocop:disable GlobalVars
|
||||||
module Middleman
|
module Middleman
|
||||||
module PreviewServer
|
module PreviewServer
|
||||||
DEFAULT_PORT = 4567
|
DEFAULT_PORT = 4567
|
||||||
|
@ -14,7 +15,7 @@ module Middleman
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def start(opts={})
|
def start(opts={})
|
||||||
@options = opts
|
@options = opts
|
||||||
@host = @options[:host] || Socket.ip_address_list.find(&:ipv4_private?).ip_address
|
@host = @options[:host] || '0.0.0.0'
|
||||||
@port = @options[:port] || DEFAULT_PORT
|
@port = @options[:port] || DEFAULT_PORT
|
||||||
|
|
||||||
mount_instance(new_app)
|
mount_instance(new_app)
|
||||||
|
@ -89,6 +90,7 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def new_app
|
def new_app
|
||||||
opts = @options.dup
|
opts = @options.dup
|
||||||
server = ::Middleman::Application.server
|
server = ::Middleman::Application.server
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
module Middleman
|
module Middleman
|
||||||
module Profiling
|
module Profiling
|
||||||
# The profiler instance. There can only be one!
|
# The profiler instance. There can only be one!
|
||||||
|
# rubocop:disable TrivialAccessors
|
||||||
def self.profiler=(prof)
|
def self.profiler=(prof)
|
||||||
@profiler = prof
|
@profiler = prof
|
||||||
end
|
end
|
||||||
|
@ -23,7 +24,7 @@ module Middleman
|
||||||
def start
|
def start
|
||||||
end
|
end
|
||||||
|
|
||||||
def report(report_name)
|
def report(_)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ module Middleman
|
||||||
# Setup extension
|
# Setup extension
|
||||||
class << self
|
class << self
|
||||||
# Once registered
|
# Once registered
|
||||||
def registered(app)
|
def registered(_)
|
||||||
::Tilt.prefer(::Middleman::Renderers::HamlTemplate, 'haml')
|
::Tilt.prefer(::Middleman::Renderers::HamlTemplate, 'haml')
|
||||||
|
|
||||||
# Add haml helpers to context
|
# Add haml helpers to context
|
||||||
|
|
|
@ -4,7 +4,7 @@ module Middleman
|
||||||
module Renderers
|
module Renderers
|
||||||
# Our own Kramdown Tilt template that simply uses our custom renderer.
|
# Our own Kramdown Tilt template that simply uses our custom renderer.
|
||||||
class KramdownTemplate < ::Tilt::KramdownTemplate
|
class KramdownTemplate < ::Tilt::KramdownTemplate
|
||||||
def evaluate(scope, locals, &block)
|
def evaluate(scope, *)
|
||||||
@output ||= begin
|
@output ||= begin
|
||||||
MiddlemanKramdownHTML.scope = ::Middleman::Renderers::Haml.last_haml_scope || scope
|
MiddlemanKramdownHTML.scope = ::Middleman::Renderers::Haml.last_haml_scope || scope
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ module Middleman
|
||||||
class MiddlemanKramdownHTML < ::Kramdown::Converter::Html
|
class MiddlemanKramdownHTML < ::Kramdown::Converter::Html
|
||||||
cattr_accessor :scope
|
cattr_accessor :scope
|
||||||
|
|
||||||
def convert_img(el, indent)
|
def convert_img(el, _)
|
||||||
attrs = el.attr.dup
|
attrs = el.attr.dup
|
||||||
|
|
||||||
link = attrs.delete('src')
|
link = attrs.delete('src')
|
||||||
|
|
|
@ -14,7 +14,7 @@ module Middleman
|
||||||
::Liquid::Template.file_system = ::Liquid::LocalFileSystem.new(source_dir)
|
::Liquid::Template.file_system = ::Liquid::LocalFileSystem.new(source_dir)
|
||||||
|
|
||||||
# Convert data object into a hash for liquid
|
# Convert data object into a hash for liquid
|
||||||
sitemap.provides_metadata %r{\.liquid$} do |path|
|
sitemap.provides_metadata %r{\.liquid$} do
|
||||||
{ locals: { data: data.to_h } }
|
{ locals: { data: data.to_h } }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,7 +38,7 @@ module Middleman
|
||||||
renderer.new(render_options)
|
renderer.new(render_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def evaluate(scope, locals, &block)
|
def evaluate(scope, _)
|
||||||
@output ||= begin
|
@output ||= begin
|
||||||
MiddlemanRedcarpetHTML.scope = ::Middleman::Renderers::Haml.last_haml_scope || scope
|
MiddlemanRedcarpetHTML.scope = ::Middleman::Renderers::Haml.last_haml_scope || scope
|
||||||
|
|
||||||
|
|
|
@ -31,9 +31,7 @@ module Middleman
|
||||||
def initialize(*args, &block)
|
def initialize(*args, &block)
|
||||||
super
|
super
|
||||||
|
|
||||||
if @options.key?(:context)
|
@context = @options[:context] if @options.key?(:context)
|
||||||
@context = @options[:context]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Define the expected syntax for the template
|
# Define the expected syntax for the template
|
||||||
|
@ -46,9 +44,8 @@ module Middleman
|
||||||
|
|
||||||
# Add exception messaging
|
# Add exception messaging
|
||||||
# @param [Class] context
|
# @param [Class] context
|
||||||
# @param [Hash] locals
|
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def evaluate(context, locals, &block)
|
def evaluate(context, _)
|
||||||
@context ||= context
|
@context ||= context
|
||||||
@engine = ::Sass::Engine.new(data, sass_options)
|
@engine = ::Sass::Engine.new(data, sass_options)
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,8 @@ module Middleman
|
||||||
# Files starting with an underscore, but not a double-underscore
|
# Files starting with an underscore, but not a double-underscore
|
||||||
partials: proc { |file| file =~ %r{/_[^_]} },
|
partials: proc { |file| file =~ %r{/_[^_]} },
|
||||||
|
|
||||||
layout: proc { |file, app|
|
layout: proc { |file, sitemap_app|
|
||||||
file.start_with?(File.join(app.config[:source], 'layout.')) || file.start_with?(File.join(app.config[:source], 'layouts/'))
|
file.start_with?(File.join(sitemap_app.config[:source], 'layout.')) || file.start_with?(File.join(sitemap_app.config[:source], 'layouts/'))
|
||||||
}
|
}
|
||||||
}, 'Callbacks that can exclude paths from the sitemap'
|
}, 'Callbacks that can exclude paths from the sitemap'
|
||||||
|
|
||||||
|
|
|
@ -35,13 +35,13 @@ module Middleman
|
||||||
# Update or add an on-disk file path
|
# Update or add an on-disk file path
|
||||||
# @param [String] file
|
# @param [String] file
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
def touch_file(file, rebuild=true)
|
def touch_file(file)
|
||||||
return false if File.directory?(file)
|
return false if File.directory?(file)
|
||||||
|
|
||||||
path = @sitemap.file_to_path(file)
|
path = @sitemap.file_to_path(file)
|
||||||
return false unless path
|
return false unless path
|
||||||
|
|
||||||
ignored = @app.config[:ignored_sitemap_matchers].any? do |name, callback|
|
ignored = @app.config[:ignored_sitemap_matchers].any? do |_, callback|
|
||||||
if callback.arity == 1
|
if callback.arity == 1
|
||||||
callback.call(file)
|
callback.call(file)
|
||||||
else
|
else
|
||||||
|
@ -67,7 +67,7 @@ module Middleman
|
||||||
# Remove a file from the store
|
# Remove a file from the store
|
||||||
# @param [String] file
|
# @param [String] file
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def remove_file(file, rebuild=true)
|
def remove_file(file)
|
||||||
if @file_paths_on_disk.delete?(file)
|
if @file_paths_on_disk.delete?(file)
|
||||||
@sitemap.rebuild_resource_list!(:removed_file)
|
@sitemap.rebuild_resource_list!(:removed_file)
|
||||||
unless waiting_for_ready || @app.build?
|
unless waiting_for_ready || @app.build?
|
||||||
|
|
|
@ -88,8 +88,9 @@ module Middleman
|
||||||
module ProxyResourceInstanceMethods
|
module ProxyResourceInstanceMethods
|
||||||
# Whether this page is a proxy
|
# Whether this page is a proxy
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
|
# rubocop:disable TrivialAccessors
|
||||||
def proxy?
|
def proxy?
|
||||||
!!@proxied_to
|
@proxied_to
|
||||||
end
|
end
|
||||||
|
|
||||||
# Set this page to proxy to a target path
|
# Set this page to proxy to a target path
|
||||||
|
@ -122,6 +123,7 @@ module Middleman
|
||||||
proxy_resource
|
proxy_resource
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# rubocop:disable AccessorMethodName
|
||||||
def get_source_file
|
def get_source_file
|
||||||
if proxy?
|
if proxy?
|
||||||
proxied_to_resource.source_file
|
proxied_to_resource.source_file
|
||||||
|
|
|
@ -17,9 +17,7 @@ module Middleman
|
||||||
# @param [String] path
|
# @param [String] path
|
||||||
# @param [Hash] opts The :to value gives a target path
|
# @param [Hash] opts The :to value gives a target path
|
||||||
def create_redirect(path, opts={}, &block)
|
def create_redirect(path, opts={}, &block)
|
||||||
if block_given?
|
opts[:template] = block if block_given?
|
||||||
opts[:template] = block
|
|
||||||
end
|
|
||||||
|
|
||||||
@redirects[path] = opts
|
@redirects[path] = opts
|
||||||
|
|
||||||
|
@ -54,7 +52,7 @@ module Middleman
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def render(*args, &block)
|
def render(*)
|
||||||
url = ::Middleman::Util.url_for(store.app, @request_path,
|
url = ::Middleman::Util.url_for(store.app, @request_path,
|
||||||
relative: false,
|
relative: false,
|
||||||
find_resource: true
|
find_resource: true
|
||||||
|
|
|
@ -59,7 +59,7 @@ module Middleman
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def render(*args, &block)
|
def render(*)
|
||||||
return output.call if output
|
return output.call if output
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ module Middleman
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
full_path = File.join(app.source_dir, eponymous_directory_path)
|
full_path = File.join(app.source_dir, eponymous_directory_path)
|
||||||
!!(File.exist?(full_path) && File.directory?(full_path))
|
File.exist?(full_path) && File.directory?(full_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
# The path for this resource if it were a directory, and not a file
|
# The path for this resource if it were a directory, and not a file
|
||||||
|
|
|
@ -93,9 +93,7 @@ module Middleman
|
||||||
# Render this resource
|
# Render this resource
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def render(opts={}, locs={})
|
def render(opts={}, locs={})
|
||||||
unless template?
|
return ::Middleman::FileRenderer.new(@app, source_file).template_data_for_file unless template?
|
||||||
return ::Middleman::FileRenderer.new(@app, source_file).get_template_data_for_file
|
|
||||||
end
|
|
||||||
|
|
||||||
relative_source = Pathname(source_file).relative_path_from(Pathname(app.root))
|
relative_source = Pathname(source_file).relative_path_from(Pathname(app.root))
|
||||||
|
|
||||||
|
|
|
@ -63,12 +63,13 @@ module Middleman
|
||||||
# @param [Symbol] name Name of the manipulator for debugging
|
# @param [Symbol] name Name of the manipulator for debugging
|
||||||
# @param [Class, Module] inst Abstract namespace which can update the resource list
|
# @param [Class, Module] inst Abstract namespace which can update the resource list
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def register_resource_list_manipulator(name, inst, unused=true)
|
def register_resource_list_manipulator(name, inst, *)
|
||||||
@resource_list_manipulators << [name, inst]
|
@resource_list_manipulators << [name, inst]
|
||||||
rebuild_resource_list!(:registered_new)
|
rebuild_resource_list!(:registered_new)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Rebuild the list of resources from scratch, using registed manipulators
|
# Rebuild the list of resources from scratch, using registed manipulators
|
||||||
|
# rubocop:disable UnusedMethodArgument
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def rebuild_resource_list!(reason=nil)
|
def rebuild_resource_list!(reason=nil)
|
||||||
@lock.synchronize do
|
@lock.synchronize do
|
||||||
|
@ -254,9 +255,7 @@ module Middleman
|
||||||
if @app.respond_to? :langs
|
if @app.respond_to? :langs
|
||||||
path_bits = path.split('.')
|
path_bits = path.split('.')
|
||||||
lang = path_bits.last
|
lang = path_bits.last
|
||||||
if @app.langs.include?(lang.to_sym)
|
return path_bits[0..-2].join('.') if @app.langs.include?(lang.to_sym)
|
||||||
return path_bits[0..-2].join('.')
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
path
|
path
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
require 'middleman-core/file_renderer'
|
require 'middleman-core/file_renderer'
|
||||||
require 'middleman-core/template_renderer'
|
require 'middleman-core/template_renderer'
|
||||||
|
|
||||||
|
# rubocop:disable UnderscorePrefixedVariableName
|
||||||
module Middleman
|
module Middleman
|
||||||
class TemplateContext
|
class TemplateContext
|
||||||
attr_reader :app
|
attr_reader :app
|
||||||
|
@ -19,6 +20,7 @@ module Middleman
|
||||||
_buf_was
|
_buf_was
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# rubocop:disable TrivialAccessors
|
||||||
def restore_buffer(_buf_was)
|
def restore_buffer(_buf_was)
|
||||||
@_out_buf = _buf_was
|
@_out_buf = _buf_was
|
||||||
end
|
end
|
||||||
|
@ -62,7 +64,7 @@ module Middleman
|
||||||
# @param [String, Symbol] data
|
# @param [String, Symbol] data
|
||||||
# @param [Hash] options
|
# @param [Hash] options
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def render(engine, data, options={}, &block)
|
def render(_, data, options={}, &block)
|
||||||
data = data.to_s
|
data = data.to_s
|
||||||
|
|
||||||
locals = options[:locals]
|
locals = options[:locals]
|
||||||
|
|
|
@ -37,9 +37,7 @@ module Middleman
|
||||||
# Sandboxed class for template eval
|
# Sandboxed class for template eval
|
||||||
context = @app.template_context_class.new(@app, locs, opts)
|
context = @app.template_context_class.new(@app, locs, opts)
|
||||||
|
|
||||||
if context.respond_to?(:init_haml_helpers)
|
context.init_haml_helpers if context.respond_to?(:init_haml_helpers)
|
||||||
context.init_haml_helpers
|
|
||||||
end
|
|
||||||
|
|
||||||
# Keep rendering template until we've used up all extensions. This
|
# Keep rendering template until we've used up all extensions. This
|
||||||
# handles cases like `style.css.sass.erb`
|
# handles cases like `style.css.sass.erb`
|
||||||
|
@ -125,9 +123,6 @@ module Middleman
|
||||||
# @param [Symbol] preferred_engine
|
# @param [Symbol] preferred_engine
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def self.locate_layout(app, name, preferred_engine=nil)
|
def self.locate_layout(app, name, preferred_engine=nil)
|
||||||
# Whether we've found the layout
|
|
||||||
layout_path = false
|
|
||||||
|
|
||||||
resolve_opts = {}
|
resolve_opts = {}
|
||||||
resolve_opts[:preferred_engine] = preferred_engine unless preferred_engine.nil?
|
resolve_opts[:preferred_engine] = preferred_engine unless preferred_engine.nil?
|
||||||
|
|
||||||
|
@ -167,10 +162,9 @@ module Middleman
|
||||||
# If we're specifically looking for a preferred engine
|
# If we're specifically looking for a preferred engine
|
||||||
if options.key?(:preferred_engine)
|
if options.key?(:preferred_engine)
|
||||||
extension_class = ::Tilt[options[:preferred_engine]]
|
extension_class = ::Tilt[options[:preferred_engine]]
|
||||||
matched_exts = []
|
|
||||||
|
|
||||||
# Get a list of extensions for a preferred engine
|
# Get a list of extensions for a preferred engine
|
||||||
matched_exts = ::Tilt.mappings.select do |ext, engines|
|
matched_exts = ::Tilt.mappings.select do |_, engines|
|
||||||
engines.include? extension_class
|
engines.include? extension_class
|
||||||
end.keys
|
end.keys
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ module Middleman
|
||||||
def extract_response_text(response)
|
def extract_response_text(response)
|
||||||
# The rack spec states all response bodies must respond to each
|
# The rack spec states all response bodies must respond to each
|
||||||
result = ''
|
result = ''
|
||||||
response.each do |part, s|
|
response.each do |part, _|
|
||||||
result << part
|
result << part
|
||||||
end
|
end
|
||||||
result
|
result
|
||||||
|
@ -343,8 +343,8 @@ module Middleman
|
||||||
# options.force? # => !!options['force']
|
# options.force? # => !!options['force']
|
||||||
# options.shebang # => "/usr/lib/local/ruby"
|
# options.shebang # => "/usr/lib/local/ruby"
|
||||||
# options.test_framework?(:rspec) # => options[:test_framework] == :rspec
|
# options.test_framework?(:rspec) # => options[:test_framework] == :rspec
|
||||||
#
|
# rubocop:disable DoubleNegation
|
||||||
def method_missing(method, *args, &block)
|
def method_missing(method, *args)
|
||||||
method = method.to_s
|
method = method.to_s
|
||||||
if method =~ /^(\w+)\?$/
|
if method =~ /^(\w+)\?$/
|
||||||
if args.empty?
|
if args.empty?
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# rubocop:disable FileName
|
||||||
|
|
||||||
# Setup our load paths
|
# Setup our load paths
|
||||||
libdir = File.expand_path(File.dirname(__FILE__))
|
libdir = File.expand_path(File.dirname(__FILE__))
|
||||||
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
||||||
|
|
Loading…
Reference in a new issue