Skip to content

Commit

Permalink
update to 1.9 hash syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
minad committed Dec 2, 2014
1 parent 4d125f8 commit 8009687
Show file tree
Hide file tree
Showing 37 changed files with 213 additions and 213 deletions.
6 changes: 3 additions & 3 deletions benchmarks/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ def header
end

def item
[ { :name => 'red', :current => true, :url => '#red' },
{ :name => 'green', :current => false, :url => '#green' },
{ :name => 'blue', :current => false, :url => '#blue' } ]
[ { name: 'red', current: true, url: '#red' },
{ name: 'green', current: false, url: '#green' },
{ name: 'blue', current: false, url: '#blue' } ]
end
end
18 changes: 9 additions & 9 deletions benchmarks/run-benchmarks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def init_compiled_benches
erb = ERB.new(@erb_code)
erubis = Erubis::Eruby.new(@erb_code)
fast_erubis = Erubis::FastEruby.new(@erb_code)
haml_pretty = Haml::Engine.new(@haml_code, :format => :html5)
haml_ugly = Haml::Engine.new(@haml_code, :format => :html5, :ugly => true)
haml_pretty = Haml::Engine.new(@haml_code, format: :html5)
haml_ugly = Haml::Engine.new(@haml_code, format: :html5, ugly: true)

context = Context.new

Expand All @@ -41,7 +41,7 @@ def run_erb; #{erb.src}; end
def run_erubis; #{erubis.src}; end
def run_temple_erb; #{Temple::ERB::Engine.new.call @erb_code}; end
def run_fast_erubis; #{fast_erubis.src}; end
def run_slim_pretty; #{Slim::Engine.new(:pretty => true).call @slim_code}; end
def run_slim_pretty; #{Slim::Engine.new(pretty: true).call @slim_code}; end
def run_slim_ugly; #{Slim::Engine.new.call @slim_code}; end
}

Expand All @@ -59,9 +59,9 @@ def init_tilt_benches
tilt_erb = Tilt::ERBTemplate.new { @erb_code }
tilt_erubis = Tilt::ErubisTemplate.new { @erb_code }
tilt_temple_erb = Temple::ERB::Template.new { @erb_code }
tilt_haml_pretty= Tilt::HamlTemplate.new(:format => :html5){ @haml_code }
tilt_haml_ugly = Tilt::HamlTemplate.new(:format => :html5, :ugly => true){ @haml_code }
tilt_slim_pretty= Slim::Template.new(:pretty => true) { @slim_code }
tilt_haml_pretty= Tilt::HamlTemplate.new(format: :html5){ @haml_code }
tilt_haml_ugly = Tilt::HamlTemplate.new(format: :html5, ugly: true){ @haml_code }
tilt_slim_pretty= Slim::Template.new(pretty: true) { @slim_code }
tilt_slim_ugly = Slim::Template.new { @slim_code }

context = Context.new
Expand All @@ -83,10 +83,10 @@ def init_parsing_benches
bench('(3) erubis') { Erubis::Eruby.new(@erb_code).result(context_binding) }
bench('(3) fast erubis') { Erubis::FastEruby.new(@erb_code).result(context_binding) }
bench('(3) temple erb') { Temple::ERB::Template.new { @erb_code }.render(context) }
bench('(3) slim pretty') { Slim::Template.new(:pretty => true) { @slim_code }.render(context) }
bench('(3) slim pretty') { Slim::Template.new(pretty: true) { @slim_code }.render(context) }
bench('(3) slim ugly') { Slim::Template.new { @slim_code }.render(context) }
bench('(3) haml pretty') { Haml::Engine.new(@haml_code, :format => :html5).render(context) }
bench('(3) haml ugly') { Haml::Engine.new(@haml_code, :format => :html5, :ugly => true).render(context) }
bench('(3) haml pretty') { Haml::Engine.new(@haml_code, format: :html5).render(context) }
bench('(3) haml ugly') { Haml::Engine.new(@haml_code, format: :html5, ugly: true).render(context) }
end

def run
Expand Down
10 changes: 5 additions & 5 deletions lib/slim/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'optparse'

module Slim
Engine.set_options :pretty => false
Engine.set_options pretty: false

# Slim commandline interface
# @api private
Expand Down Expand Up @@ -40,7 +40,7 @@ def set_opts(opts)
end

opts.on('--rails', 'Generate rails compatible code (Implies --compile)') do
Engine.set_options :disable_capture => true, :generator => Temple::Generators::RailsOutputBuffer
Engine.set_options disable_capture: true, generator: Temple::Generators::RailsOutputBuffer
@options[:compile] = true
end

Expand All @@ -59,7 +59,7 @@ def set_opts(opts)
end

opts.on('-p', '--pretty', 'Produce pretty html') do
Engine.set_options :pretty => true
Engine.set_options pretty: true
end

opts.on('-o', '--option name=code', String, 'Set slim option') do |str|
Expand Down Expand Up @@ -95,9 +95,9 @@ def process
result =
if @options[:erb]
require 'slim/erb_converter'
ERBConverter.new(:file => @options[:file]).call(@options[:input].read)
ERBConverter.new(file: @options[:file]).call(@options[:input].read)
elsif @options[:compile]
Engine.new(:file => @options[:file]).call(@options[:input].read)
Engine.new(file: @options[:file]).call(@options[:input].read)
else
Template.new(@options[:file]) { @options[:input].read }.render
end
Expand Down
20 changes: 10 additions & 10 deletions lib/slim/embedded.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ class SassEngine < TiltEngine

def tilt_render(tilt_engine, tilt_options, text)
text = tilt_engine.new(tilt_options.merge(
:style => options[:pretty] ? :expanded : :compressed,
:cache => false)) { text }.render
style: options[:pretty] ? :expanded : :compressed,
cache: false)) { text }.render
text.chomp!
[:static, text]
end
Expand Down Expand Up @@ -229,7 +229,7 @@ def on_slim_embedded(engine, body)
class JavaScriptEngine < TagEngine
disable_option_validator!

set_options :tag => :script, :attributes => { :type => 'text/javascript' }
set_options tag: :script, attributes: { type: 'text/javascript' }

def on_slim_embedded(engine, body)
super(engine, [:html, :js, body])
Expand All @@ -254,12 +254,12 @@ def on_slim_embedded(engine, body)
register :org, InterpolateTiltEngine

# These engines are executed at compile time
register :coffee, JavaScriptEngine, :engine => StaticTiltEngine
register :opal, JavaScriptEngine, :engine => StaticTiltEngine
register :less, TagEngine, :tag => :style, :attributes => { :type => 'text/css' }, :engine => StaticTiltEngine
register :styl, TagEngine, :tag => :style, :attributes => { :type => 'text/css' }, :engine => StaticTiltEngine
register :sass, TagEngine, :pretty, :tag => :style, :attributes => { :type => 'text/css' }, :engine => SassEngine
register :scss, TagEngine, :pretty, :tag => :style, :attributes => { :type => 'text/css' }, :engine => SassEngine
register :coffee, JavaScriptEngine, engine: StaticTiltEngine
register :opal, JavaScriptEngine, engine: StaticTiltEngine
register :less, TagEngine, tag: :style, attributes: { type: 'text/css' }, engine: StaticTiltEngine
register :styl, TagEngine, tag: :style, attributes: { type: 'text/css' }, engine: StaticTiltEngine
register :sass, TagEngine, :pretty, tag: :style, attributes: { type: 'text/css' }, engine: SassEngine
register :scss, TagEngine, :pretty, tag: :style, attributes: { type: 'text/css' }, engine: SassEngine

# These engines are precompiled, code is embedded
register :erb, ERBEngine
Expand All @@ -268,7 +268,7 @@ def on_slim_embedded(engine, body)

# Embedded javascript/css
register :javascript, JavaScriptEngine
register :css, TagEngine, :tag => :style, :attributes => { :type => 'text/css' }
register :css, TagEngine, tag: :style, attributes: { type: 'text/css' }

# Embedded ruby code
register :ruby, RubyEngine
Expand Down
16 changes: 8 additions & 8 deletions lib/slim/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ class Engine < Temple::Engine
# This overwrites some Temple default options or sets default options for Slim specific filters.
# It is recommended to set the default settings only once in the code and avoid duplication. Only use
# `define_options` when you have to override some default settings.
define_options :pretty => false,
:sort_attrs => true,
:format => :xhtml,
:attr_quote => '"',
:merge_attrs => {'class' => ' '},
:generator => Temple::Generators::ArrayBuffer,
:default_tag => 'div'
define_options pretty: false,
sort_attrs: true,
format: :xhtml,
attr_quote: '"',
merge_attrs: {'class' => ' '},
generator: Temple::Generators::ArrayBuffer,
default_tag: 'div'
define_deprecated_options :attr_delims

filter :Encoding
Expand All @@ -26,7 +26,7 @@ class Engine < Temple::Engine
html :AttributeSorter
html :AttributeMerger
use Slim::CodeAttributes
use(:AttributeRemover) { Temple::HTML::AttributeRemover.new(:remove_empty_attrs => options[:merge_attrs].keys) }
use(:AttributeRemover) { Temple::HTML::AttributeRemover.new(remove_empty_attrs: options[:merge_attrs].keys) }
html :Pretty
filter :Escapable
filter :ControlFlow
Expand Down
2 changes: 1 addition & 1 deletion lib/slim/include.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Slim
#
# @api private
class Include < Slim::Filter
define_options :file, :include_dirs => [Dir.pwd, '.']
define_options :file, include_dirs: [Dir.pwd, '.']

def on_html_tag(tag, attributes, content)
return super if tag != 'include'
Expand Down
6 changes: 3 additions & 3 deletions lib/slim/logic_less/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class LogicLess < Filter
# Default dictionary access order, change it with the option :dictionary_access
DEFAULT_ACCESS_ORDER = [:symbol, :string, :method, :instance_variable].freeze

define_options :logic_less => true,
:dictionary => 'self',
:dictionary_access => DEFAULT_ACCESS_ORDER
define_options logic_less: true,
dictionary: 'self',
dictionary_access: DEFAULT_ACCESS_ORDER

def initialize(opts = {})
super
Expand Down
10 changes: 5 additions & 5 deletions lib/slim/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ class Parser < Temple::Parser
:default_tag,
:code_attr_delims,
:attr_list_delims,
:tabsize => 4,
:shortcut => {
'#' => { :attr => 'id' },
'.' => { :attr => 'class' }
tabsize: 4,
shortcut: {
'#' => { attr: 'id' },
'.' => { attr: 'class' }
},
:attr_delims => {
attr_delims: {
'(' => ')',
'[' => ']',
'{' => '}',
Expand Down
2 changes: 1 addition & 1 deletion lib/slim/smart/escaper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Smart
#
# @api private
class Escaper < ::Slim::Filter
define_options :smart_text_escaping => true
define_options smart_text_escaping: true

def call(exp)
if options[:smart_text_escaping]
Expand Down
6 changes: 3 additions & 3 deletions lib/slim/smart/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module Smart
#
# @api private
class Filter < ::Slim::Filter
define_options :smart_text => true,
:smart_text_end_chars => '([{',
:smart_text_begin_chars => ',.;:!?)]}'
define_options smart_text: true,
smart_text_end_chars: '([{',
smart_text_begin_chars: ',.;:!?)]}'

def initialize(opts = {})
super
Expand Down
2 changes: 1 addition & 1 deletion lib/slim/smart/parser.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Slim
module Smart
class Parser < ::Slim::Parser
define_options :implicit_text => true
define_options implicit_text: true

def initialize(opts = {})
super
Expand Down
2 changes: 1 addition & 1 deletion lib/slim/splat/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Splat
class Filter < ::Slim::Filter
OPTIONS = [:merge_attrs, :attr_quote, :sort_attrs, :default_tag, :hyphen_attrs, :format, :use_html_safe]
define_options OPTIONS
set_options :hyphen_attrs => %w(data aria), :use_html_safe => ''.respond_to?(:html_safe?)
set_options hyphen_attrs: %w(data aria), use_html_safe: ''.respond_to?(:html_safe?)

def call(exp)
@splat_options = nil
Expand Down
10 changes: 5 additions & 5 deletions lib/slim/template.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
module Slim
# Tilt template implementation for Slim
# @api public
Template = Temple::Templates::Tilt(Slim::Engine, :register_as => :slim)
Template = Temple::Templates::Tilt(Slim::Engine, register_as: :slim)

if defined?(::ActionView)
# Rails template implementation for Slim
# @api public
RailsTemplate = Temple::Templates::Rails(Slim::Engine,
:register_as => :slim,
register_as: :slim,
# Use rails-specific generator. This is necessary
# to support block capturing and streaming.
:generator => Temple::Generators::RailsOutputBuffer,
generator: Temple::Generators::RailsOutputBuffer,
# Disable the internal slim capturing.
# Rails takes care of the capturing by itself.
:disable_capture => true,
:streaming => defined?(::Fiber))
disable_capture: true,
streaming: defined?(::Fiber))
end
end
22 changes: 11 additions & 11 deletions lib/slim/translator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

module Slim
class Translator < Filter
define_options :tr_mode => :dynamic,
:tr_fn => '_',
:tr => false
define_options tr_mode: :dynamic,
tr_fn: '_',
tr: false

if defined?(::I18n)
set_options :tr_fn => '::Slim::Translator.i18n_text',
:tr => true
set_options tr_fn: '::Slim::Translator.i18n_text',
tr: true
elsif defined?(::GetText)
set_options :tr_fn => '::GetText._',
:tr => true
set_options tr_fn: '::GetText._',
tr: true
elsif defined?(::FastGettext)
set_options :tr_fn => '::FastGettext::Translation._',
:tr => true
set_options tr_fn: '::FastGettext::Translation._',
tr: true
end

def self.i18n_text(text)
Expand All @@ -38,9 +38,9 @@ def initialize(opts = {})
super
case options[:tr_mode]
when :static
@translator = StaticTranslator.new(:tr_fn => options[:tr_fn])
@translator = StaticTranslator.new(tr_fn: options[:tr_fn])
when :dynamic
@translator = DynamicTranslator.new(:tr_fn => options[:tr_fn])
@translator = DynamicTranslator.new(tr_fn: options[:tr_fn])
else
raise ArgumentError, "Invalid translator mode #{options[:tr_mode].inspect}"
end
Expand Down
6 changes: 3 additions & 3 deletions test/core/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require 'slim'
require 'slim/grammar'

Slim::Engine.after Slim::Parser, Temple::Filters::Validator, :grammar => Slim::Grammar
Slim::Engine.after Slim::Parser, Temple::Filters::Validator, grammar: Slim::Grammar
Slim::Engine.before :Pretty, Temple::Filters::Validator

class TestSlim < MiniTest::Unit::TestCase
Expand Down Expand Up @@ -99,7 +99,7 @@ def id_helper
end

def hash
{:a => 'The letter a', :b => 'The letter b'}
{a: 'The letter a', b: 'The letter b'}
end

def show_first?(show = false)
Expand Down Expand Up @@ -157,7 +157,7 @@ def output_number
end

def person
[{:name => 'Joe'}, {:name => 'Jack'}]
[{name: 'Joe'}, {name: 'Jack'}]
end

def people
Expand Down
Loading

0 comments on commit 8009687

Please sign in to comment.