source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | slim-template/slim | https://github.com/slim-template/slim | test/core/test_code_evaluation.rb | Ruby | mit | 5,359 | main | 4,670 | require 'helper'
class TestSlimCodeEvaluation < TestSlim
def test_render_with_call_to_set_attributes
source = %q{
p id="#{id_helper}" class="hello world" = hello_world
}
assert_html '<p class="hello world" id="notice">Hello World from @env</p>', source
end
def test_render_with_call_to_set_custom_attrib... |
github | slim-template/slim | https://github.com/slim-template/slim | test/core/test_erb_converter.rb | Ruby | mit | 5,359 | main | 1,580 | require 'helper'
require 'slim/erb_converter'
class TestSlimERBConverter < TestSlim
def test_converter
source = %q{
doctype 5
html
head
title Hello World!
/! Meta tags
with long explanatory
multiline comment
meta name="description" content="template language"
/! Stylesheets
... |
github | slim-template/slim | https://github.com/slim-template/slim | test/core/test_parser_errors.rb | Ruby | mit | 5,359 | main | 3,574 | require 'helper'
class TestParserErrors < TestSlim
def test_correct_filename
source = %q{
doctype 5
div Invalid
}
assert_syntax_error "Unexpected indentation\n test.slim, Line 3, Column 2\n div Invalid\n ^\n", source, file: 'test.slim'
end
def test_unexpected_indentation
source = %q{
docty... |
github | slim-template/slim | https://github.com/slim-template/slim | test/core/test_slim_template.rb | Ruby | mit | 5,359 | main | 2,163 | require 'helper'
class ::MockError < NameError
end
class TestSlimTemplate < TestSlim
def test_default_mime_type
assert_equal 'text/html', Slim::Template.default_mime_type
end
def test_registered_extension
assert_equal Slim::Template, Tilt['test.slim']
end
def test_preparing_and_evaluating
temp... |
github | slim-template/slim | https://github.com/slim-template/slim | test/core/test_embedded_engines.rb | Ruby | mit | 5,359 | main | 6,919 | require 'helper'
require 'erb'
class TestSlimEmbeddedEngines < TestSlim
def test_render_with_markdown
source = %q{
markdown:
#Header
Hello from #{"Markdown!"}
#{1+2}
[#{1}](#{"#2"})
* one
* two
}
if ::Tilt['md'].name =~ /Redcarpet/
# redcarpet
assert_html "<h1>Header</h1>\n\n<p>He... |
github | slim-template/slim | https://github.com/slim-template/slim | test/core/test_text_interpolation.rb | Ruby | mit | 5,359 | main | 1,665 | require 'helper'
class TestSlimTextInterpolation < TestSlim
def test_interpolation_in_attribute
source = %q{
p id="a#{id_helper}b" = hello_world
}
assert_html '<p id="anoticeb">Hello World from @env</p>', source
end
def test_nested_interpolation_in_attribute
source = %q{
p id="#{"abc#{1+1}" + "("}"... |
github | slim-template/slim | https://github.com/slim-template/slim | test/core/test_code_blocks.rb | Ruby | mit | 5,359 | main | 3,967 | require 'helper'
class TestSlimCodeBlocks < TestSlim
def test_render_with_output_code_block
source = %q{
p
= hello_world "Hello Ruby!" do
| Hello from within a block!
}
assert_html '<p>Hello Ruby! Hello from within a block! Hello Ruby!</p>', source
end
def test_render_with_output_code_block_witho... |
github | slim-template/slim | https://github.com/slim-template/slim | test/core/test_code_output.rb | Ruby | mit | 5,359 | main | 3,005 | require 'helper'
class TestSlimCodeOutput < TestSlim
def test_render_with_call
source = %q{
p
= hello_world
}
assert_html '<p>Hello World from @env</p>', source
end
def test_render_with_trailing_whitespace
source = %q{
p
=> hello_world
}
assert_html '<p>Hello World from @env </p>', source
... |
github | slim-template/slim | https://github.com/slim-template/slim | test/core/test_html_attributes.rb | Ruby | mit | 5,359 | main | 6,728 | require 'helper'
class TestSlimHTMLAttributes < TestSlim
def test_ternary_operation_in_attribute
source = %q{
p id="#{(false ? 'notshown' : 'shown')}" = output_number
}
assert_html '<p id="shown">1337</p>', source
end
def test_ternary_operation_in_attribute_2
source = %q{
p id=(false ? 'notshown' :... |
github | slim-template/slim | https://github.com/slim-template/slim | test/core/helper.rb | Ruby | mit | 5,359 | main | 3,755 | begin
require 'simplecov'
SimpleCov.start
rescue LoadError
end
require 'minitest/autorun'
require 'slim'
require 'slim/grammar'
Slim::Engine.after Slim::Parser, Temple::Filters::Validator, grammar: Slim::Grammar
Slim::Engine.before :Pretty, Temple::Filters::Validator
class TestSlim < Minitest::Test
def setup
... |
github | slim-template/slim | https://github.com/slim-template/slim | test/core/test_html_escaping.rb | Ruby | mit | 5,359 | main | 1,326 | require 'helper'
class TestSlimHtmlEscaping < TestSlim
def test_html_will_not_be_escaped
source = %q{
p <Hello> World, meet "Slim".
}
assert_html '<p><Hello> World, meet "Slim".</p>', source
end
def test_html_with_newline_will_not_be_escaped
source = %q{
p
|
<Hello> World,
meet "Slim".
}... |
github | slim-template/slim | https://github.com/slim-template/slim | test/core/test_code_structure.rb | Ruby | mit | 5,359 | main | 3,377 | require 'helper'
class TestSlimCodeStructure < TestSlim
def test_render_with_conditional
source = %q{
div
- if show_first?
p The first paragraph
- else
p The second paragraph
}
assert_html '<div><p>The second paragraph</p></div>', source
end
def test_render_with_begin
source = %q{
-... |
github | slim-template/slim | https://github.com/slim-template/slim | test/core/test_encoding.rb | Ruby | mit | 5,359 | main | 687 | require 'helper'
class TestSlimEncoding < TestSlim
def test_windows_crlf
source = "a href='#' something\r\nbr\r\na href='#' others\r\n"
result = "<a href=\"#\">something</a><br /><a href=\"#\">others</a>"
assert_html result, source
end
def test_binary
source = "| \xFF\xFF".dup
source.force_e... |
github | slim-template/slim | https://github.com/slim-template/slim | test/core/test_tabs.rb | Ruby | mit | 5,359 | main | 1,553 | require 'helper'
class TestSlimTabs < TestSlim
def teardown
Slim::Engine.set_options tabsize: 4
end
def test_single_tab1_expansion
Slim::Engine.set_options tabsize: 1
source = %Q{
|
\t0
\t1
\t2
\t3
\t4
\t5
\t6
\t7
\t8
}
result = %q{
0
1
2
3
4
... |
github | slim-template/slim | https://github.com/slim-template/slim | test/core/test_thread_options.rb | Ruby | mit | 5,359 | main | 515 | require 'helper'
class TestSlimThreadOptions < TestSlim
def test_thread_options
source = %q{p.test}
assert_html '<p class="test"></p>', source
assert_html "<p class='test'></p>", source, attr_quote: "'"
Slim::Engine.with_options(attr_quote: "'") do
assert_html "<p class='test'></p>", source
... |
github | slim-template/slim | https://github.com/slim-template/slim | test/core/test_html_structure.rb | Ruby | mit | 5,359 | main | 15,796 | require 'helper'
class TestSlimHtmlStructure < TestSlim
def test_simple_render
# Keep the trailing space behind "body "!
source = %q{
html
head
title Simple Test Title
body
p Hello World, meet Slim.
}
assert_html '<html><head><title>Simple Test Title</title></head><body><p>Hello World, meet... |
github | slim-template/slim | https://github.com/slim-template/slim | test/core/test_code_escaping.rb | Ruby | mit | 5,359 | main | 3,868 | require 'helper'
class TestSlimCodeEscaping < TestSlim
def test_escaping_evil_method
source = %q{
p = evil_method
}
assert_html '<p><script>do_something_evil();</script></p>', source
end
def test_render_without_html_safe
source = %q{
p = "<strong>Hello World\\n, meet \\"Slim\\"</strong>... |
github | slim-template/slim | https://github.com/slim-template/slim | test/core/test_pretty.rb | Ruby | mit | 5,359 | main | 2,962 | require 'helper'
class TestSlimPretty < TestSlim
def setup
super
Slim::Engine.set_options pretty: true
end
def teardown
Slim::Engine.set_options pretty: false
end
def test_pretty
source = %q{
doctype 5
html
head
title Hello World!
/! Meta tags
with long explanatory
m... |
github | slim-template/slim | https://github.com/slim-template/slim | test/core/test_splat_prefix_option.rb | Ruby | mit | 5,359 | main | 3,778 | require 'helper'
class TestSplatPrefixOption < TestSlim
def prefixes
['*','**','*!','*%','*^','*$']
end
def options(prefix)
{ splat_prefix: prefix }
end
def test_splat_without_content
prefixes.each do |prefix|
source = %Q{
#{prefix}hash
p#{prefix}hash
}
assert_html '<div a="... |
github | slim-template/slim | https://github.com/slim-template/slim | test/core/test_unicode.rb | Ruby | mit | 5,359 | main | 387 | require 'helper'
class TestSlimUnicode < TestSlim
def test_unicode_tags
source = "Статья года"
result = "<Статья>года</Статья>"
assert_html result, source
end
def test_unicode_attrs
source = "Статья года=123 content"
result = "<Статья года=\"123\">content</Статья>"
assert_html result, so... |
github | slim-template/slim | https://github.com/slim-template/slim | test/core/test_commands.rb | Ruby | mit | 5,359 | main | 6,290 | require 'helper'
require 'open3'
require 'tempfile'
class TestSlimCommands < Minitest::Test
# nothing complex
STATIC_TEMPLATE = "p Hello World!\n"
# requires a `name` variable to exist at render time
DYNAMIC_TEMPLATE = "p Hello \#{name}!\n"
# a more complex example
LONG_TEMPLATE = "h1 Hello\np\n | World... |
github | slim-template/slim | https://github.com/slim-template/slim | test/smart/test_smart_text.rb | Ruby | mit | 5,359 | main | 4,086 | require 'helper'
require 'slim/smart'
class TestSlimSmartText < TestSlim
def test_explicit_smart_text_recognition
source = %q{
>
a
>
b
>
c
>
d
> e
f
> g
h
i
}
result = %q{a
b
c
d
e
<f></f>
g
h
<i></i>}
assert_html result, source
end
def test_implicit_smart_text_recognition
sourc... |
github | slim-template/slim | https://github.com/slim-template/slim | test/sinatra/test_include.rb | Ruby | mit | 5,359 | main | 471 | require 'slim/include'
require_relative 'helper.rb'
begin
class SlimTest < Minitest::Test
it 'renders .slim files includes with js embed' do
slim_app { slim :embed_include_js }
assert ok?
assert_equal "<!DOCTYPE html><html><head><title>Slim Examples</title><script>alert('Slim supports embedded... |
github | slim-template/slim | https://github.com/slim-template/slim | test/sinatra/helper.rb | Ruby | mit | 5,359 | main | 3,288 | if ENV['COVERAGE']
require 'simplecov'
SimpleCov.start do
add_filter '/test/'
add_group 'sinatra-contrib', 'sinatra-contrib'
add_group 'rack-protection', 'rack-protection'
end
end
ENV['APP_ENV'] = 'test'
RUBY_ENGINE = 'ruby' unless defined? RUBY_ENGINE
require 'rack'
testdir = File.dirname(__FILE__... |
github | slim-template/slim | https://github.com/slim-template/slim | test/sinatra/test_core.rb | Ruby | mit | 5,359 | main | 2,637 | require_relative 'helper.rb'
begin
class SlimTest < Minitest::Test
it 'renders inline slim strings' do
slim_app { slim "h1 Hiya\n" }
assert ok?
assert_equal "<h1>Hiya</h1>", body
end
it 'renders .slim files in views path' do
slim_app { slim :hello }
assert ok?
assert_... |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim.rb | Ruby | mit | 5,359 | main | 431 | # frozen_string_literal: true
require 'temple'
require 'slim/parser'
require 'slim/filter'
require 'slim/do_inserter'
require 'slim/end_inserter'
require 'slim/embedded'
require 'slim/interpolation'
require 'slim/controls'
require 'slim/splat/filter'
require 'slim/splat/builder'
require 'slim/code_attributes'
require '... |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim/railtie.rb | Ruby | mit | 5,359 | main | 1,004 | # frozen_string_literal: true
module Slim
class Railtie < ::Rails::Railtie
initializer 'initialize slim template handler' do
ActiveSupport.on_load(:action_view) do
Slim::RailsTemplate = Temple::Templates::Rails(Slim::Engine,
register_as: :slim,... |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim/include.rb | Ruby | mit | 5,359 | main | 1,823 | # frozen_string_literal: true
require 'slim'
module Slim
# Handles inlined includes
#
# Slim files are compiled, non-Slim files are included as text with `#{interpolation}`
#
# @api private
class Include < Slim::Filter
define_options :file, include_dirs: [Dir.pwd, '.']
def on_html_tag(tag, attribu... |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim/end_inserter.rb | Ruby | mit | 5,359 | main | 1,980 | # frozen_string_literal: true
module Slim
# In Slim you don't need to close any blocks:
#
# - if Slim.awesome?
# | But of course it is!
#
# However, the parser is not smart enough (and that's a good thing) to
# automatically insert end's where they are needed. Luckily, this filter
# does *exactly*... |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim/erb_converter.rb | Ruby | mit | 5,359 | main | 348 | # frozen_string_literal: true
require 'slim'
module Slim
# Slim to ERB converter
#
# @example Conversion
# Slim::ERBConverter.new(options).call(slim_code) # outputs erb_code
#
# @api public
class ERBConverter < Engine
replace :StaticMerger, Temple::Filters::CodeMerger
replace :Generator, Temple... |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim/interpolation.rb | Ruby | mit | 5,359 | main | 1,129 | # frozen_string_literal: true
module Slim
# Perform interpolation of #{var_name} in the
# expressions `[:slim, :interpolate, string]`.
#
# @api private
class Interpolation < Filter
# Handle interpolate expression `[:slim, :interpolate, string]`
#
# @param [String] string Static interpolate
# @... |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim/smart.rb | Ruby | mit | 5,359 | main | 307 | # frozen_string_literal: true
require 'slim'
require 'slim/smart/filter'
require 'slim/smart/escaper'
require 'slim/smart/parser'
Slim::Engine.replace Slim::Parser, Slim::Smart::Parser
Slim::Engine.after Slim::Smart::Parser, Slim::Smart::Filter
Slim::Engine.after Slim::Interpolation, Slim::Smart::Escaper |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim/do_inserter.rb | Ruby | mit | 5,359 | main | 1,147 | # frozen_string_literal: true
module Slim
# In Slim you don't need the do keyword sometimes. This
# filter adds the missing keyword.
#
# - 10.times
# | Hello
#
# @api private
class DoInserter < Filter
BLOCK_REGEX = /(\A(if|unless|else|elsif|when|in|begin|rescue|ensure|case)\b)|\bdo\s*(\|[^\|]*... |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim/command.rb | Ruby | mit | 5,359 | main | 3,263 | # frozen_string_literal: true
require 'slim'
require 'optparse'
module Slim
Engine.set_options pretty: false
# Slim commandline interface
# @api private
class Command
def initialize(args)
@args = args
@options = {}
end
# Run command
def run
@opts = OptionParser.new(&method(:... |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim/parser.rb | Ruby | mit | 5,359 | main | 17,385 | # frozen_string_literal: true
module Slim
# Parses Slim code and transforms it to a Temple expression
# @api private
class Parser < Temple::Parser
define_options :file,
:default_tag,
tabsize: 4,
code_attr_delims: {
'(' => ')',
... |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim/grammar.rb | Ruby | mit | 5,359 | main | 676 | # frozen_string_literal: true
module Slim
# Slim expression grammar
# @api private
module Grammar
extend Temple::Grammar
TextTypes << :verbatim | :explicit | :implicit | :inline
Expression <<
[:slim, :control, String, Expression] |
[:slim, :output, Bool, String, Expressio... |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim/filter.rb | Ruby | mit | 5,359 | main | 819 | # frozen_string_literal: true
module Slim
# Base class for Temple filters used in Slim
#
# This base filter passes everything through and allows
# to override only some methods without affecting the rest
# of the expression.
#
# @api private
class Filter < Temple::HTML::Filter
# Pass-through handler... |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim/controls.rb | Ruby | mit | 5,359 | main | 2,082 | # frozen_string_literal: true
module Slim
# @api private
class Controls < Filter
define_options :disable_capture
IF_RE = /\A(if|unless)\b|\bdo\s*(\|[^\|]*\|)?\s*$/
# Handle control expression `[:slim, :control, code, content]`
#
# @param [String] code Ruby code
# @param [Array] content Tem... |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim/embedded.rb | Ruby | mit | 5,359 | main | 6,873 | # frozen_string_literal: true
module Slim
# @api private
class TextCollector < Filter
def call(exp)
@collected = ''.dup
super(exp)
@collected
end
def on_slim_interpolate(text)
@collected << text
nil
end
end
# @api private
class NewlineCollector < Filter
def ... |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim/code_attributes.rb | Ruby | mit | 5,359 | main | 2,145 | # frozen_string_literal: true
module Slim
# @api private
class CodeAttributes < Filter
define_options :merge_attrs
# Handle attributes expression `[:html, :attrs, *attrs]`
#
# @param [Array] attrs Array of temple expressions
# @return [Array] Compiled temple expression
def on_html_attrs(*at... |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim/translator.rb | Ruby | mit | 5,359 | main | 2,989 | # frozen_string_literal: true
require 'slim'
module Slim
# @api private
class Translator < Filter
define_options :tr,
tr_mode: :dynamic,
tr_fn: '_'
if defined?(::I18n)
set_options tr_fn: '::Slim::Translator.i18n_text',
tr: true
elsif define... |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim/engine.rb | Ruby | mit | 5,359 | main | 1,521 | # frozen_string_literal: true
# The Slim module contains all Slim related classes (e.g. Engine, Parser).
# Plugins might also reside within the Slim module (e.g. Include, Smart).
# @api public
module Slim
# Slim engine which transforms slim code to executable ruby code
# @api public
class Engine < Temple::Engine
... |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim/splat/builder.rb | Ruby | mit | 5,359 | main | 3,546 | # frozen_string_literal: true
module Slim
class InvalidAttributeNameError < StandardError; end
module Splat
# @api private
class Builder
# https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
INVALID_ATTRIBUTE_NAME_REGEX = /[ \0"'>\/=]/
def initialize(options)
@options ... |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim/splat/filter.rb | Ruby | mit | 5,359 | main | 3,085 | # frozen_string_literal: true
module Slim
module Splat
# @api private
class Filter < ::Slim::Filter
define_options :merge_attrs, :attr_quote, :sort_attrs, :default_tag, :format, :disable_capture,
hyphen_attrs: %w(data aria), use_html_safe: ''.respond_to?(:html_safe?),
... |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim/logic_less/context.rb | Ruby | mit | 5,359 | main | 3,150 | # frozen_string_literal: true
module Slim
class LogicLess
# @api private
class Context
def initialize(dict, lookup)
@scope = [Scope.new(dict, lookup)]
end
def [](name)
scope[name]
end
def lambda(name)
scope.lambda(name) do |*dict|
if dict.empty... |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim/logic_less/filter.rb | Ruby | mit | 5,359 | main | 2,263 | # frozen_string_literal: true
module Slim
# Handle logic less mode
# This filter can be activated with the option "logic_less"
# @api private
class LogicLess < Filter
# Default dictionary access order, change it with the option :dictionary_access
DEFAULT_ACCESS_ORDER = [:symbol, :string, :method, :insta... |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim/smart/filter.rb | Ruby | mit | 5,359 | main | 3,394 | # frozen_string_literal: true
module Slim
module Smart
# Perform newline processing in the
# expressions `[:slim, :text, type, Expression]`.
#
# @api private
class Filter < ::Slim::Filter
define_options smart_text: true,
smart_text_end_chars: '([{',
... |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim/smart/parser.rb | Ruby | mit | 5,359 | main | 1,316 | # frozen_string_literal: true
module Slim
module Smart
# @api private
class Parser < ::Slim::Parser
define_options implicit_text: true
def initialize(opts = {})
super
word_re = options[:implicit_text] ? '[_a-z0-9]' : '\p{Word}'
attr_keys = Regexp.union(@attr_shortcut.keys.... |
github | slim-template/slim | https://github.com/slim-template/slim | lib/slim/smart/escaper.rb | Ruby | mit | 5,359 | main | 1,034 | # frozen_string_literal: true
module Slim
module Smart
# Perform smart entity escaping in the
# expressions `[:slim, :text, type, Expression]`.
#
# @api private
class Escaper < ::Slim::Filter
define_options smart_text_escaping: true
def call(exp)
if options[:smart_text_escapin... |
github | rails-api/active_model_serializers | https://github.com/rails-api/active_model_serializers | active_model_serializers.gemspec | Ruby | mit | 5,333 | master | 806 | # coding: utf-8
Gem::Specification.new do |spec|
spec.name = 'active_model_serializers'
spec.version = "1.0.0-dev"
spec.platform = Gem::Platform::RUBY
spec.authors = ['Steve Klabnik']
spec.email = ['steve@steveklabnik.com']
spec.summary = 'Conventions-based JSON gene... |
github | rails/webpacker | https://github.com/rails/webpacker | Rakefile | Ruby | mit | 5,278 | master | 219 | # frozen_string_literal: true
require "bundler/gem_tasks"
require "rake/testtask"
Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList["test/**/*_test.rb"]
t.verbose = true
end
task default: :test |
github | rails/webpacker | https://github.com/rails/webpacker | Gemfile | Ruby | mit | 5,278 | master | 206 | source "https://rubygems.org"
gemspec
gem "rails"
gem "rake", ">= 11.1"
gem "rack-proxy", require: false
gem "semantic_range", require: false
group :test do
gem "minitest", "~> 5.0"
gem "byebug"
end |
github | rails/webpacker | https://github.com/rails/webpacker | webpacker.gemspec | Ruby | mit | 5,278 | master | 1,145 | $:.push File.expand_path("../lib", __FILE__)
require "webpacker/version"
Gem::Specification.new do |s|
s.name = "webpacker"
s.version = Webpacker::VERSION
s.authors = [ "David Heinemeier Hansson", "Gaurav Tiwari" ]
s.email = [ "david@basecamp.com", "gaurav@gauravtiwari.co.uk" ]
s.summary = "Use web... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/webpacker.rb | Ruby | mit | 5,278 | master | 1,113 | require "active_support/core_ext/module/attribute_accessors"
require "active_support/core_ext/string/inquiry"
require "active_support/logger"
require "active_support/tagged_logging"
module Webpacker
extend self
def instance=(instance)
@instance = instance
end
def instance
@instance ||= Webpacker::Ins... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/tasks/webpacker.rake | Ruby | mit | 5,278 | master | 1,158 | tasks = {
"webpacker:info" => "Provides information on Webpacker's environment",
"webpacker:install" => "Installs and setup webpack with Yarn",
"webpacker:compile" => "Compiles webpack bundles based on environment",
"webpacker:clean" => "Remov... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/tasks/yarn.rake | Ruby | mit | 5,278 | master | 1,272 | # frozen_string_literal: true
# Duplicate of the yarn tasks still present in Rails until Webpacker <5 have been deprecated
namespace :yarn do
desc "Install all JavaScript dependencies as specified via Yarn"
task :install do
begin
# Install only production deps when for not usual envs.
valid_node_e... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/tasks/webpacker/clobber.rake | Ruby | mit | 5,278 | master | 614 | require "webpacker/configuration"
namespace :webpacker do
desc "Remove the webpack compiled output directory"
task clobber: ["webpacker:verify_config", :environment] do
Webpacker.clobber
$stdout.puts "Removed webpack output path directory #{Webpacker.config.public_output_path}"
end
end
skip_webpacker_cl... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/tasks/webpacker/clean.rake | Ruby | mit | 5,278 | master | 710 | $stdout.sync = true
require "webpacker/configuration"
namespace :webpacker do
desc "Remove old compiled webpacks"
task :clean, [:keep, :age] => ["webpacker:verify_install", :environment] do |_, args|
Webpacker.ensure_log_goes_to_stdout do
Webpacker.clean(Integer(args.keep || 2), Integer(args.age || 3600... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/tasks/webpacker/check_yarn.rake | Ruby | mit | 5,278 | master | 1,349 | require "semantic_range"
namespace :webpacker do
desc "Verifies if Yarn is installed"
task :check_yarn do
begin
which_command = Gem.win_platform? ? "where" : "which"
raise Errno::ENOENT if `#{which_command} yarn`.strip.empty?
yarn_version = `yarn --version`.strip
raise Errno::ENOENT if ... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/tasks/webpacker/install.rake | Ruby | mit | 5,278 | master | 647 | install_template_path = File.expand_path("../../install/template.rb", __dir__).freeze
bin_path = ENV["BUNDLE_BIN"] || Rails.root.join("bin")
namespace :webpacker do
desc "Install Webpacker in this application"
task install: [:check_node, :check_yarn] do |task|
Webpacker::Configuration.installing = true
pr... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/tasks/webpacker/compile.rake | Ruby | mit | 5,278 | master | 1,339 | $stdout.sync = true
def yarn_install_available?
rails_major = Rails::VERSION::MAJOR
rails_minor = Rails::VERSION::MINOR
rails_major > 5 || (rails_major == 5 && rails_minor >= 1)
end
def enhance_assets_precompile
# yarn:install was added in Rails 5.1
deps = yarn_install_available? ? [] : ["webpacker:yarn_in... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/tasks/webpacker/check_binstubs.rake | Ruby | mit | 5,278 | master | 408 | namespace :webpacker do
desc "Verifies that bin/webpacker is present"
task :check_binstubs do
unless File.exist?(Rails.root.join("bin/webpacker"))
$stderr.puts "webpacker binstub not found.\n"\
"Have you run rails webpacker:install ?\n"\
"Make sure the bin directory and bin/webpacker... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/tasks/webpacker/yarn_install.rake | Ruby | mit | 5,278 | master | 595 | namespace :webpacker do
desc "Support for older Rails versions. Install all JavaScript dependencies as specified via Yarn"
task :yarn_install do
valid_node_envs = %w[test development production]
node_env = ENV.fetch("NODE_ENV") do
valid_node_envs.include?(Rails.env) ? Rails.env : "production"
end
... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/tasks/webpacker/verify_config.rake | Ruby | mit | 5,278 | master | 470 | require "webpacker/configuration"
namespace :webpacker do
desc "Verifies if the Webpacker config is present"
task :verify_config do
unless Webpacker.config.config_path.exist?
path = Webpacker.config.config_path.relative_path_from(Pathname.new(pwd)).to_s
$stderr.puts "Configuration #{path} file not ... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/tasks/webpacker/binstubs.rake | Ruby | mit | 5,278 | master | 614 | binstubs_template_path = File.expand_path("../../install/binstubs.rb", __dir__).freeze
bin_path = ENV["BUNDLE_BIN"] || Rails.root.join("bin")
namespace :webpacker do
desc "Installs Webpacker binstubs in this application"
task binstubs: [:check_node, :check_yarn] do |task|
prefix = task.name.split(/#|webpacker:... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/tasks/webpacker/info.rake | Ruby | mit | 5,278 | master | 767 | require "webpacker/version"
namespace :webpacker do
desc "Provide information on Webpacker's environment"
task :info do
Dir.chdir(Rails.root) do
$stdout.puts "Ruby: #{`ruby --version`}"
$stdout.puts "Rails: #{Rails.version}"
$stdout.puts "Webpacker: #{Webpacker::VERSION}"
$stdout.puts "... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/tasks/webpacker/check_node.rake | Ruby | mit | 5,278 | master | 1,290 | require "semantic_range"
namespace :webpacker do
desc "Verifies if Node.js is installed"
task :check_node do
begin
node_version = `node -v || nodejs -v`.strip
raise Errno::ENOENT if node_version.blank?
pkg_path = Pathname.new("#{__dir__}/../../../package.json").realpath
node_range = JSO... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/install/template.rb | Ruby | mit | 5,278 | master | 3,861 | # Install Webpacker
copy_file "#{__dir__}/config/webpacker.yml", "config/webpacker.yml"
copy_file "#{__dir__}/package.json", "package.json"
say "Copying webpack core config"
directory "#{__dir__}/config/webpack", "config/webpack"
if Dir.exist?(Webpacker.config.source_path)
say "The packs app source directory alread... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/webpacker/runner.rb | Ruby | mit | 5,278 | master | 807 | module Webpacker
class Runner
def self.run(argv)
$stdout.sync = true
new(argv).run
end
def initialize(argv)
@argv = argv
@app_path = File.expand_path(".", Dir.pwd)
@node_modules_bin_path = ENV["WEBPACKER_NODE_MODULES_BIN_PATH"] || `yarn bin`.chomp
@webpa... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/webpacker/env.rb | Ruby | mit | 5,278 | master | 1,115 | class Webpacker::Env
DEFAULT = "production".freeze
delegate :config_path, :logger, to: :@webpacker
def self.inquire(webpacker)
new(webpacker).inquire
end
def initialize(webpacker)
@webpacker = webpacker
end
def inquire
fallback_env_warning if config_path.exist? && !current
current || D... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/webpacker/compiler.rb | Ruby | mit | 5,278 | master | 3,896 | require "open3"
require "digest/sha1"
class Webpacker::Compiler
# Additional paths that test compiler needs to watch
# Webpacker::Compiler.watched_paths << 'bower_components'
#
# Deprecated. Use additional_paths in the YAML configuration instead.
cattr_accessor(:watched_paths) { [] }
# Additional environm... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/webpacker/dev_server.rb | Ruby | mit | 5,278 | master | 1,200 | class Webpacker::DevServer
DEFAULT_ENV_PREFIX = "WEBPACKER_DEV_SERVER".freeze
# Configure dev server connection timeout (in seconds), default: 0.01
# Webpacker.dev_server.connect_timeout = 1
cattr_accessor(:connect_timeout) { 0.01 }
attr_reader :config
def initialize(config)
@config = config
end
... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/webpacker/railtie.rb | Ruby | mit | 5,278 | master | 1,884 | require "rails/railtie"
require "webpacker/helper"
require "webpacker/dev_server_proxy"
class Webpacker::Engine < ::Rails::Engine
# Allows Webpacker config values to be set via Rails env config files
config.webpacker = ActiveSupport::OrderedOptions.new
initializer "webpacker.proxy" do |app|
if (Webpacker.c... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/webpacker/webpack_runner.rb | Ruby | mit | 5,278 | master | 1,211 | require "shellwords"
require "webpacker/runner"
module Webpacker
class WebpackRunner < Webpacker::Runner
WEBPACK_COMMANDS = [
"help",
"h",
"--help",
"-h",
"version",
"v",
"--version",
"-v",
"info",
"i"
].freeze
def run
env = Webpacker::Co... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/webpacker/manifest.rb | Ruby | mit | 5,278 | master | 4,011 | # Singleton registry for accessing the packs path using a generated manifest.
# This allows javascript_pack_tag, stylesheet_pack_tag, asset_pack_path to take a reference to,
# say, "calendar.js" or "calendar.css" and turn it into "/packs/calendar-1016838bab065ae1e314.js" or
# "/packs/calendar-1016838bab065ae1e314.css".... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/webpacker/helper.rb | Ruby | mit | 5,278 | master | 7,202 | module Webpacker::Helper
# Returns the current Webpacker instance.
# Could be overridden to use multiple Webpacker
# configurations within the same app (e.g. with engines).
def current_webpacker_instance
Webpacker.instance
end
# Computes the relative path for a given Webpacker asset.
# Returns the re... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/webpacker/dev_server_runner.rb | Ruby | mit | 5,278 | master | 2,826 | require "shellwords"
require "socket"
require "webpacker/configuration"
require "webpacker/dev_server"
require "webpacker/runner"
module Webpacker
class DevServerRunner < Webpacker::Runner
def run
load_config
detect_unsupported_switches!
detect_port!
execute_cmd
end
private
... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/webpacker/instance.rb | Ruby | mit | 5,278 | master | 881 | class Webpacker::Instance
cattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) }
attr_reader :root_path, :config_path
def initialize(root_path: Rails.root, config_path: Rails.root.join("config/webpacker.yml"))
@root_path, @config_path = root_path, config_path
end
... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/webpacker/configuration.rb | Ruby | mit | 5,278 | master | 2,555 | require "yaml"
require "active_support/core_ext/hash/keys"
require "active_support/core_ext/hash/indifferent_access"
class Webpacker::Configuration
class << self
attr_accessor :installing
end
attr_reader :root_path, :config_path, :env
def initialize(root_path:, config_path:, env:)
@root_path = root_p... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/webpacker/commands.rb | Ruby | mit | 5,278 | master | 2,109 | class Webpacker::Commands
delegate :config, :compiler, :manifest, :logger, to: :@webpacker
def initialize(webpacker)
@webpacker = webpacker
end
# Cleanup old assets in the compile directory. By default it will
# keep the latest version, 2 backups created within the past hour.
#
# Examples
#
# ... |
github | rails/webpacker | https://github.com/rails/webpacker | lib/webpacker/dev_server_proxy.rb | Ruby | mit | 5,278 | master | 1,060 | require "rack/proxy"
class Webpacker::DevServerProxy < Rack::Proxy
delegate :config, :dev_server, to: :@webpacker
def initialize(app = nil, opts = {})
@webpacker = opts.delete(:webpacker) || Webpacker.instance
opts[:streaming] = false if Rails.env.test? && !opts.key?(:streaming)
super
end
def per... |
github | rails/webpacker | https://github.com/rails/webpacker | test/engine_rake_tasks_test.rb | Ruby | mit | 5,278 | master | 878 | require "test_helper"
class EngineRakeTasksTest < Minitest::Test
def setup
remove_webpack_binstubs
end
def teardown
remove_webpack_binstubs
end
def test_task_mounted
output = Dir.chdir(mounted_app_path) { `rake -T` }
assert_includes output, "app:webpacker"
end
def test_binstubs
Dir... |
github | rails/webpacker | https://github.com/rails/webpacker | test/dev_server_test.rb | Ruby | mit | 5,278 | master | 1,013 | require "test_helper"
class DevServerTest < Webpacker::Test
def test_running?
refute Webpacker.dev_server.running?
end
def test_host
with_rails_env("development") do
assert_equal Webpacker.dev_server.host, "localhost"
end
end
def test_port
with_rails_env("development") do
assert... |
github | rails/webpacker | https://github.com/rails/webpacker | test/manifest_test.rb | Ruby | mit | 5,278 | master | 3,017 | require "test_helper"
class ManifestTest < Minitest::Test
def test_lookup_exception!
asset_file = "calendar.js"
error = assert_raises_manifest_missing_entry_error do
Webpacker.manifest.lookup!(asset_file)
end
assert_match "Webpacker can't find #{asset_file} in #{manifest_path}", error.message... |
github | rails/webpacker | https://github.com/rails/webpacker | test/webpack_runner_test.rb | Ruby | mit | 5,278 | master | 1,579 | require "test_helper"
require "webpacker/webpack_runner"
class WebpackRunnerTest < Webpacker::Test
def setup
@original_node_env, ENV["NODE_ENV"] = ENV["NODE_ENV"], "development"
@original_rails_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "development"
end
def teardown
ENV["NODE_ENV"] = @original_node_... |
github | rails/webpacker | https://github.com/rails/webpacker | test/compiler_test.rb | Ruby | mit | 5,278 | master | 1,921 | require "test_helper"
class CompilerTest < Minitest::Test
def remove_compilation_digest_path
Webpacker.compiler.send(:compilation_digest_path).tap do |path|
path.delete if path.exist?
end
end
def setup
remove_compilation_digest_path
end
def teardown
remove_compilation_digest_path
en... |
github | rails/webpacker | https://github.com/rails/webpacker | test/configuration_test.rb | Ruby | mit | 5,278 | master | 2,534 | require "test_helper"
class ConfigurationTest < Webpacker::Test
def setup
@config = Webpacker::Configuration.new(
root_path: Pathname.new(File.expand_path("test_app", __dir__)),
config_path: Pathname.new(File.expand_path("./test_app/config/webpacker.yml", __dir__)),
env: "production"
)
en... |
github | rails/webpacker | https://github.com/rails/webpacker | test/test_helper.rb | Ruby | mit | 5,278 | master | 831 | # frozen_string_literal: true
require "minitest/autorun"
require "rails"
require "rails/test_help"
require "byebug"
require_relative "test_app/config/environment"
Rails.env = "production"
Webpacker.instance = ::Webpacker::Instance.new
class Webpacker::Test < Minitest::Test
private
def reloaded_config
We... |
github | rails/webpacker | https://github.com/rails/webpacker | test/env_test.rb | Ruby | mit | 5,278 | master | 453 | require "test_helper"
class EnvTest < Webpacker::Test
def test_current
assert_equal Webpacker.env, Rails.env
end
def test_custom_without_config
with_rails_env("foo") do
assert_equal Webpacker.env, "production"
end
end
def test_custom_with_config
with_rails_env("staging") do
asse... |
github | rails/webpacker | https://github.com/rails/webpacker | test/helper_test.rb | Ruby | mit | 5,278 | master | 7,853 | require "test_helper"
class HelperTest < ActionView::TestCase
tests Webpacker::Helper
attr_reader :request
def setup
@request = Class.new do
def send_early_hints(links) end
def base_url
"https://example.com"
end
end.new
end
def test_asset_pack_path
assert_equal "/pack... |
github | rails/webpacker | https://github.com/rails/webpacker | test/command_test.rb | Ruby | mit | 5,278 | master | 3,504 | require "test_helper"
class CommandTest < Minitest::Test
def test_compile_command_returns_success_status_when_stale
Webpacker.compiler.stub :stale?, true do
Webpacker.compiler.stub :run_webpack, true do
assert_equal true, Webpacker.commands.compile
end
end
end
def test_compile_comman... |
github | rails/webpacker | https://github.com/rails/webpacker | test/dev_server_runner_test.rb | Ruby | mit | 5,278 | master | 2,645 | require "test_helper"
require "webpacker/dev_server_runner"
class DevServerRunnerTest < Webpacker::Test
def setup
@original_node_env, ENV["NODE_ENV"] = ENV["NODE_ENV"], "development"
@original_rails_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "development"
@original_webpacker_config = ENV["WEBPACKER_CONFIG... |
github | rails/webpacker | https://github.com/rails/webpacker | test/rake_tasks_test.rb | Ruby | mit | 5,278 | master | 2,352 | require "test_helper"
class RakeTasksTest < Minitest::Test
def test_rake_tasks
output = Dir.chdir(test_app_path) { `rake -T` }
assert_includes output, "webpacker"
assert_includes output, "webpacker:check_binstubs"
assert_includes output, "webpacker:check_node"
assert_includes output, "webpacker:c... |
github | rails/webpacker | https://github.com/rails/webpacker | test/webpacker_test.rb | Ruby | mit | 5,278 | master | 979 | require "test_helper"
class WebpackerTest < Webpacker::Test
def test_config_params
assert_equal Rails.env, Webpacker.config.env
assert_equal Webpacker.instance.root_path, Webpacker.config.root_path
assert_equal Webpacker.instance.config_path, Webpacker.config.config_path
with_rails_env("test") do
... |
github | rails/webpacker | https://github.com/rails/webpacker | test/mounted_app/test/dummy/config/application.rb | Ruby | mit | 5,278 | master | 225 | require "action_controller/railtie"
require "action_view/railtie"
require "webpacker"
module TestDummyApp
class Application < Rails::Application
config.secret_key_base = "abcdef"
config.eager_load = true
end
end |
github | rails/webpacker | https://github.com/rails/webpacker | test/test_app/config/application.rb | Ruby | mit | 5,278 | master | 269 | require "action_controller/railtie"
require "action_view/railtie"
require "webpacker"
module TestApp
class Application < ::Rails::Application
config.secret_key_base = "abcdef"
config.eager_load = true
config.active_support.test_order = :sorted
end
end |
github | drapergem/draper | https://github.com/drapergem/draper | Guardfile | Ruby | mit | 5,266 | master | 802 | def rspec_guard(options = {}, &block)
options = {
version: 2,
notification: false
}.merge(options)
guard 'rspec', options, &block
end
rspec_guard spec_paths: %w{spec/draper spec/generators} do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/sp... |
github | drapergem/draper | https://github.com/drapergem/draper | draper.gemspec | Ruby | mit | 5,266 | master | 1,627 | require_relative 'lib/draper/version'
Gem::Specification.new do |s|
s.name = "draper"
s.version = Draper::VERSION
s.authors = ["Jeff Casimir", "Steve Klabnik"]
s.email = ["jeff@casimircreative.com", "steve@steveklabnik.com"]
s.homepage = "https://github.com/drapergem/draper"
s.summa... |
github | drapergem/draper | https://github.com/drapergem/draper | Rakefile | Ruby | mit | 5,266 | master | 1,733 | require 'rake'
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
def run_in_dummy_app(command)
success = system("cd spec/dummy && #{command}")
raise "#{command} failed" unless success
end
task "default" => "ci"
desc "Run all tests for CI"
task "ci" => "spec"
desc "Run all specs"
task "spec" => "spec:al... |
github | drapergem/draper | https://github.com/drapergem/draper | Gemfile | Ruby | mit | 5,266 | master | 1,349 | source "https://rubygems.org"
gemspec
gem 'puma'
platforms :ruby do
if RUBY_VERSION >= "3.0.0"
gem 'sqlite3'
elsif RUBY_VERSION >= "2.5.0"
gem 'sqlite3', '~> 1.4.0'
else
gem 'sqlite3', '~> 1.3.6'
end
end
platforms :jruby do
gem "minitest"
gem "activerecord-jdbcsqlite3-adapter"
end
case rail... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.