mirror of
https://github.com/middleman/middleman.git
synced 2022-11-09 12:20:27 -05:00
Centralize active_support integration (#2256)
* Centralize active_support integration * For some reason, as_json is magic * Fix ActiveSupport paths * Env update
This commit is contained in:
parent
c99b616cf8
commit
feb7a3d852
24 changed files with 32 additions and 49 deletions
|
@ -1,6 +1,8 @@
|
|||
ENV['TEST'] = 'true'
|
||||
|
||||
require 'backports/latest'
|
||||
require 'active_support/all'
|
||||
|
||||
require 'sassc'
|
||||
|
||||
require 'simplecov'
|
||||
|
|
|
@ -591,9 +591,9 @@ Feature: Incremental builds
|
|||
When a file named "source/roles/data.json.erb" with:
|
||||
"""
|
||||
{
|
||||
"roles": <%= data.roles.select(&:salary).to_json %>
|
||||
"roles": <%= data.roles.select(&:salary).to_json %>,
|
||||
"roles2": <%= data.roles.first.as_json %>
|
||||
}
|
||||
"""
|
||||
Then build the app tracking dependencies
|
||||
Then there are "1" files which are created
|
||||
# with depth "1"
|
||||
Then build the app tracking dependencies with depth "1"
|
||||
Then there are "1" files which are created
|
|
@ -1,6 +1,8 @@
|
|||
ENV['TEST'] = 'true'
|
||||
|
||||
require 'backports/latest'
|
||||
require 'active_support/all'
|
||||
|
||||
require 'sassc'
|
||||
|
||||
require 'simplecov'
|
||||
|
|
|
@ -3,6 +3,7 @@ libdir = __dir__
|
|||
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
||||
|
||||
require 'backports/latest'
|
||||
require 'active_support/all'
|
||||
|
||||
# Top-level Middleman namespace
|
||||
module Middleman
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
require 'active_support/core_ext/integer/inflections'
|
||||
require 'hamster'
|
||||
require 'middleman-core/contracts'
|
||||
require 'middleman-core/callback_manager'
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
require 'active_support/core_ext/object/deep_dup'
|
||||
require 'middleman-core/util'
|
||||
|
||||
module Middleman
|
||||
|
|
|
@ -8,6 +8,10 @@ module Middleman
|
|||
class ArrayProxy < BaseProxy
|
||||
WRAPPED_LIST_METHODS = Set.new %i[each each_with_index select sort shuffle reverse rotate sample]
|
||||
|
||||
def respond_to_missing?(name, *)
|
||||
self.class.const_get(:WRAPPED_LIST_METHODS).include?(name) || super
|
||||
end
|
||||
|
||||
def method_missing(name, *args, &block)
|
||||
if self.class.const_get(:WRAPPED_LIST_METHODS).include?(name)
|
||||
log_access(:__full_access__)
|
||||
|
@ -53,16 +57,6 @@ module Middleman
|
|||
end
|
||||
end
|
||||
|
||||
def to_s
|
||||
log_access(:__full_access__)
|
||||
@data.to_s
|
||||
end
|
||||
|
||||
def to_json(*args)
|
||||
log_access(:__full_access__)
|
||||
@data.to_a.to_json(*args)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def wrapped_array
|
||||
|
|
|
@ -20,6 +20,10 @@ module Middleman
|
|||
@accessed_keys = ::Hamster::Set.new
|
||||
end
|
||||
|
||||
def respond_to_missing?(name, *)
|
||||
@data.respond_to?(name) || super
|
||||
end
|
||||
|
||||
def method_missing(name, *args, &block)
|
||||
if @data.respond_to?(name)
|
||||
log_access(:__full_access__)
|
||||
|
@ -40,6 +44,11 @@ module Middleman
|
|||
@parent = new_parent
|
||||
end
|
||||
|
||||
def as_json(*args)
|
||||
log_access(:__full_access__)
|
||||
@data.as_json(*args)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def log_access(key)
|
||||
|
|
|
@ -14,6 +14,10 @@ module Middleman
|
|||
end
|
||||
alias get []
|
||||
|
||||
def respond_to_missing?(name, *)
|
||||
@data.key?(name) || super
|
||||
end
|
||||
|
||||
def method_missing(name, *_args)
|
||||
return self[name] if @data.key?(name)
|
||||
|
||||
|
@ -21,16 +25,6 @@ module Middleman
|
|||
rescue NoMethodError
|
||||
nil
|
||||
end
|
||||
|
||||
def to_s
|
||||
log_access(:__full_access__)
|
||||
@data.to_s
|
||||
end
|
||||
|
||||
def to_json(*args)
|
||||
log_access(:__full_access__)
|
||||
@data.to_h.to_json(*args)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,8 +23,6 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
|||
def initialize(app, options_hash = ::Middleman::EMPTY_HASH, &block)
|
||||
super
|
||||
|
||||
require 'active_support/core_ext/object/to_query'
|
||||
|
||||
::Middleman::TemplateContext.send :include, ::Padrino::Helpers::OutputHelpers
|
||||
::Middleman::TemplateContext.send :include, ::Padrino::Helpers::TagHelpers
|
||||
::Middleman::TemplateContext.send :include, ::Padrino::Helpers::AssetTagHelpers
|
||||
|
@ -47,7 +45,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
|||
|
||||
options = parse_data_options(name, options)
|
||||
attributes = tag_attributes(options)
|
||||
output = ActiveSupport::SafeBuffer.new
|
||||
output = ::ActiveSupport::SafeBuffer.new
|
||||
output.safe_concat "<#{name}#{attributes}>"
|
||||
|
||||
if content.respond_to?(:each) && !content.is_a?(String)
|
||||
|
|
|
@ -4,8 +4,6 @@ require 'pathname'
|
|||
# DbC
|
||||
require 'middleman-core/contracts'
|
||||
|
||||
require 'active_support/core_ext/hash/keys'
|
||||
|
||||
require 'middleman-core/util/data'
|
||||
|
||||
# Extensions namespace
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
require 'forwardable'
|
||||
require 'memoist'
|
||||
require 'active_support/core_ext/class/attribute'
|
||||
require 'middleman-core/configuration'
|
||||
require 'middleman-core/contracts'
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
require 'active_support/core_ext/object/try'
|
||||
require 'memoist'
|
||||
require 'middleman-core/contracts'
|
||||
require 'rack/mime'
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
require 'active_support/core_ext/object/try'
|
||||
require 'middleman-core/contracts'
|
||||
require 'memoist'
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
require 'tilt'
|
||||
require 'hamster'
|
||||
require 'active_support/core_ext/string/output_safety'
|
||||
require 'active_support/core_ext/module/delegation'
|
||||
require 'middleman-core/contracts'
|
||||
require 'middleman-core/dependencies/vertices/vertex'
|
||||
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
# Use the Ruby/Rails logger
|
||||
require 'active_support/notifications'
|
||||
require 'active_support/logger'
|
||||
module Middleman
|
||||
# The Middleman Logger
|
||||
class Logger < ActiveSupport::Logger
|
||||
class Logger < ::ActiveSupport::Logger
|
||||
def self.singleton(*args)
|
||||
if !@_logger || !args.empty?
|
||||
args = [0, false, args.first] if args.length == 1 && (args.first.is_a?(::String) || args.first.respond_to?(:write))
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
require 'ipaddr'
|
||||
require 'active_support/core_ext/object/blank'
|
||||
require 'middleman-core/preview_server/checks'
|
||||
require 'middleman-core/preview_server/server_hostname'
|
||||
require 'middleman-core/preview_server/server_ip_address'
|
||||
|
|
|
@ -13,7 +13,7 @@ module Middleman
|
|||
def precompiled_preamble(locals)
|
||||
original = super
|
||||
"__in_erb_template = true\n" << original
|
||||
# .rpartition("\n").first << "#{@outvar} = _buf = ActiveSupport::SafeBuffer.new\n"
|
||||
# .rpartition("\n").first << "#{@outvar} = _buf = ::ActiveSupport::SafeBuffer.new\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
require 'redcarpet'
|
||||
require 'active_support/core_ext/module/attribute_accessors'
|
||||
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
# Used for merging results of metadata callbacks
|
||||
require 'active_support/core_ext/hash/deep_merge'
|
||||
require 'monitor'
|
||||
require 'hamster'
|
||||
require 'middleman-core/extensions'
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
require 'tilt'
|
||||
require 'hamster'
|
||||
require 'active_support/core_ext/string/output_safety'
|
||||
require 'middleman-core/contracts'
|
||||
require 'middleman-core/template_context'
|
||||
require 'middleman-core/file_renderer'
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
# For instrumenting
|
||||
require 'active_support/notifications'
|
||||
|
||||
require 'middleman-core/application'
|
||||
require 'middleman-core/sources'
|
||||
require 'middleman-core/sitemap/resource'
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
# For URI templating
|
||||
require 'addressable/uri'
|
||||
require 'addressable/template'
|
||||
require 'active_support/inflector'
|
||||
require 'active_support/inflector/transliterate'
|
||||
|
||||
module Middleman
|
||||
module Util
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
require 'backports/latest'
|
||||
require 'active_support/all'
|
||||
|
||||
require 'simplecov'
|
||||
SimpleCov.root(File.expand_path(File.dirname(__FILE__) + '/..'))
|
||||
SimpleCov.start
|
||||
|
|
Loading…
Reference in a new issue