Skip to content

Commit

Permalink
Update SLIM
Browse files Browse the repository at this point in the history
  • Loading branch information
andreyvit committed Mar 22, 2012
1 parent 401fbb6 commit e673ed7
Show file tree
Hide file tree
Showing 26 changed files with 309 additions and 152 deletions.
12 changes: 10 additions & 2 deletions SLIM.lrplugin/lib/slim/.travis.yml
@@ -1,16 +1,24 @@
rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- ruby-head
- jruby
- rbx-2.0
- rbx-18mode
env:
- "TASK=test"
- "TASK=test TEMPLE=master"
- "TASK=test:rails RAILS=master"
- "TASK=test:rails RAILS=3.0.11"
- "TASK=test:rails RAILS=3.1.3"
matrix:
exclude:
# Test Rails master only on 1.9.3+ Rubies
- rvm: 1.8.7
env: "TASK=test:rails RAILS=master"
- rvm: jruby
env: "TASK=test:rails RAILS=master"
- rvm: rbx-18mode
env: "TASK=test:rails RAILS=master"
script: "bundle exec rake test:ci"
notifications:
email: false
Expand Down
7 changes: 6 additions & 1 deletion SLIM.lrplugin/lib/slim/CHANGES
@@ -1,4 +1,9 @@
master
1.1.1

* Evaluating a html attribute now happens only once (#219)
* Code with trailing comma is treated as broken line (#226)
* Support option :remove_empty_attrs (default true)
* Require temple 0.4.0

1.1.0

Expand Down
2 changes: 1 addition & 1 deletion SLIM.lrplugin/lib/slim/lib/slim/compiler.rb
Expand Up @@ -79,7 +79,7 @@ def on_slim_attr(name, escape, code)
if delimiter = options[:attr_delimiter][name]
"#{tmp}.respond_to?(:join) ? #{tmp}.flatten.compact.join(#{delimiter.inspect}) : #{tmp}"
else
code
tmp
end
]]]]
end
Expand Down
9 changes: 6 additions & 3 deletions SLIM.lrplugin/lib/slim/lib/slim/engine.rb
Expand Up @@ -33,7 +33,8 @@ class Engine < Temple::Engine
# Symbol | :format | :xhtml | HTML output format
# String | :attr_wrapper | '"' | Character to wrap attributes in html (can be ' or ")
# Hash | :attr_delimiter | {'class' => ' '} | Joining character used if multiple html attributes are supplied (e.g. id1_id2)
# Symbol | :sort_attrs | true | Sort attributes by name
# Boolean | :sort_attrs | true | Sort attributes by name
# Boolean | :remove_empty_attrs| true | Remove attributes with empty value
# Boolean | :pretty | false | Pretty html indenting (This is slower!)
# String | :indent | ' ' | Indentation string
# Boolean | :streaming | false (true in Rails > 3.1) | Enable output streaming
Expand Down Expand Up @@ -61,8 +62,10 @@ class Engine < Temple::Engine
use Slim::Sections, :sections, :dictionary, :dictionary_access
use Slim::EndInserter
use Slim::Compiler, :disable_capture, :attr_delimiter
use Temple::HTML::AttributeMerger, :attr_delimiter, :sort_attrs
use Temple::HTML::Pretty, :format, :attr_wrapper, :pretty, :indent
html :AttributeMerger, :attr_delimiter
html :AttributeSorter, :sort_attrs
html :AttributeRemover, :remove_empty_attrs
html :Pretty, :format, :attr_wrapper, :pretty, :indent
filter :Escapable, :use_html_safe, :disable_escape
filter :ControlFlow
filter :MultiFlattener
Expand Down
12 changes: 8 additions & 4 deletions SLIM.lrplugin/lib/slim/lib/slim/parser.rb
Expand Up @@ -224,7 +224,7 @@ def parse_comment_block
end
end

def parse_text_block(first_line = nil, text_indent = nil)
def parse_text_block(first_line = nil, text_indent = nil, in_tag = false)
result = [:multi]
if !first_line || first_line.empty?
text_indent = nil
Expand Down Expand Up @@ -253,7 +253,11 @@ def parse_text_block(first_line = nil, text_indent = nil)
# The text block lines must be at least indented
# as deep as the first line.
offset = text_indent ? indent - text_indent : 0
syntax_error!('Unexpected text indentation') if offset < 0
if offset < 0
syntax_error!("Text line not indented deep enough.\n" +
"The first text line defines the necessary text indentation." +
(in_tag ? "\nAre you trying to nest a child tag in a tag containing text? Use | for the text block!" : ''))
end

result << [:newline] << [:slim, :interpolate, (text_indent ? "\n" : '') + (' ' * offset) + @line]

Expand All @@ -267,7 +271,7 @@ def parse_text_block(first_line = nil, text_indent = nil)

def parse_broken_line
broken_line = @line.strip
while broken_line[-1] == ?\\
while broken_line =~ /[,\\]\Z/
next_line || syntax_error!('Unexpected end of file')
broken_line << "\n" << @line.strip
end
Expand Down Expand Up @@ -312,7 +316,7 @@ def parse_tag(tag)
@stacks << content
when /\A( ?)(.*)\Z/
# Text content
tag << parse_text_block($2, @orig_line.size - @line.size + $1.size)
tag << parse_text_block($2, @orig_line.size - @line.size + $1.size, true)
end
end

Expand Down
2 changes: 1 addition & 1 deletion SLIM.lrplugin/lib/slim/lib/slim/version.rb
@@ -1,5 +1,5 @@
module Slim
# Slim version string
# @api public
VERSION = '1.1.0'
VERSION = '1.1.1'
end
2 changes: 1 addition & 1 deletion SLIM.lrplugin/lib/slim/slim.gemspec
Expand Up @@ -19,7 +19,7 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = %w(lib)

s.add_runtime_dependency('temple', ['~> 0.3.5'])
s.add_runtime_dependency('temple', ['~> 0.4.0'])
s.add_runtime_dependency('tilt', ['~> 1.3.2'])

s.add_development_dependency('rake', ['>= 0.8.7'])
Expand Down
10 changes: 2 additions & 8 deletions SLIM.lrplugin/lib/slim/test/rails/test/test_slim.rb
@@ -1,6 +1,6 @@
require File.expand_path('../helper', __FILE__)

class TestSlim < ActionController::IntegrationTest
class TestSlim < ActionDispatch::IntegrationTest
test "normal view" do
get "slim/normal"
assert_response :success
Expand Down Expand Up @@ -59,13 +59,7 @@ class TestSlim < ActionController::IntegrationTest
post "parents", 'parent[name]' => "p1", 'parent[children_attributes][0][name]' => "c1"
get "parents/1/edit"

assert_html '<form accept-charset="UTF-8" action="/parents/1" class="edit_parent" enctype="multipart/form-data" id="edit_parent_1" method="post">'+
'<div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="_method" type="hidden" value="put" />'+
'</div><h1>Parent</h1><input id="parent_name" name="parent[name]" size="30" type="text" value="p1" />'+
'<h2>Children</h2>'+
'<ul><li><input id="parent_children_attributes_0_name" name="parent[children_attributes][0][name]" size="30" type="text" value="c1" /></li>'+
'<input id="parent_children_attributes_0_id" name="parent[children_attributes][0][id]" type="hidden" value="1" /></ul>'+
'</form>'
assert_match(%r{<form accept-charset="UTF-8" action="/parents/1" class="edit_parent" enctype="multipart/form-data" id="edit_parent_1" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="_method" type="hidden" value="[^"]+" /></div><h1>Parent</h1><input id="parent_name" name="parent\[name\]" size="30" type="text" value="p1" /><h2>Children</h2><ul><li><input id="parent_children_attributes_0_name" name="parent\[children_attributes\]\[0\]\[name\]" size="30" type="text" value="c1" /></li><input id="parent_children_attributes_0_id" name="parent\[children_attributes\]\[0\]\[id\]" type="hidden" value="1" /></ul></form>}, @response.body)
end

protected
Expand Down
10 changes: 8 additions & 2 deletions SLIM.lrplugin/lib/slim/test/slim/helper.rb
Expand Up @@ -9,7 +9,7 @@

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

class TestSlim < MiniTest::Unit::TestCase
def setup
Expand Down Expand Up @@ -72,7 +72,7 @@ def assert_runtime_error(message, source, options = {})
end

class Env
attr_reader :var
attr_reader :var, :x

class ::HtmlSafeString < String
def html_safe?
Expand All @@ -88,6 +88,7 @@ def html_safe?

def initialize
@var = 'instance'
@x = 0
end

def id_helper
Expand Down Expand Up @@ -144,6 +145,11 @@ def method_which_returns_true
def output_number
1337
end

def succ_x
@x = @x.succ
end

end

class ViewEnv
Expand Down
Expand Up @@ -6,7 +6,7 @@ def test_replace
p Test
}
chain = proc do |engine|
engine.replace(Temple::HTML::Pretty, :ReplacementFilter) do |exp|
engine.replace(:Pretty, :ReplacementFilter) do |exp|
[:dynamic, '1+1']
end
end
Expand Down
9 changes: 9 additions & 0 deletions SLIM.lrplugin/lib/slim/test/slim/test_code_output.rb
Expand Up @@ -149,6 +149,15 @@ def test_render_with_backslash_end
assert_html '<p>Hello Ruby!</p>7', source
end

def test_render_with_comma_end
source = %q{
p = message("Hello",
"Ruby!")
}

assert_html '<p>Hello Ruby!</p>', source
end

def test_render_with_no_trailing_character
source = %q{
p
Expand Down
9 changes: 9 additions & 0 deletions SLIM.lrplugin/lib/slim/test/slim/test_html_structure.rb
Expand Up @@ -459,4 +459,13 @@ def test_block_expansion_nesting
}
assert_html %{<html><body><div class=\"content\">Text</div></body></html>}, source
end

def test_eval_attributes_once
source = %q{
input[value=succ_x]
input[value=succ_x]
}
assert_html %{<input value="1" /><input value="2" />}, source
end

end
18 changes: 17 additions & 1 deletion SLIM.lrplugin/lib/slim/test/slim/test_parser_errors.rb
Expand Up @@ -26,7 +26,23 @@ def test_unexpected_text_indentation
text
}

assert_syntax_error "Unexpected text indentation\n (__TEMPLATE__), Line 4\n text\n ^\n", source
assert_syntax_error "Text line not indented deep enough.\nThe first text line defines the necessary text indentation.\n (__TEMPLATE__), Line 4\n text\n ^\n", source
end

def test_unexpected_text_indentation_in_tag
source = %q{
ul
li List1
ul
li a
li b
li List2
ul
li a
li b
}

assert_syntax_error "Text line not indented deep enough.\nThe first text line defines the necessary text indentation.\nAre you trying to nest a child tag in a tag containing text? Use | for the text block!\n (__TEMPLATE__), Line 4\n ul\n ^\n", source
end

def test_malformed_indentation
Expand Down
3 changes: 1 addition & 2 deletions SLIM.lrplugin/lib/temple/.travis.yml
@@ -1,7 +1,6 @@
rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- ruby-head
- rbx-2.0
- jruby
- rbx-18mode
6 changes: 5 additions & 1 deletion SLIM.lrplugin/lib/temple/CHANGES
@@ -1,4 +1,8 @@
master
0.4.0

* Split Temple::HTML::AttributeMerger in AttributeSorter,
AttributeMerger and AttributeRemover
* Fix issue #58

0.3.5

Expand Down
67 changes: 35 additions & 32 deletions SLIM.lrplugin/lib/temple/lib/temple.rb
@@ -1,48 +1,51 @@
require 'temple/version'

module Temple
autoload :InvalidExpression, 'temple/generators'
autoload :Generator, 'temple/generators'
autoload :Generators, 'temple/generators'
autoload :Engine, 'temple/engine'
autoload :Utils, 'temple/utils'
autoload :Filter, 'temple/filter'
autoload :Templates, 'temple/templates'
autoload :Grammar, 'temple/grammar'
autoload :ImmutableHash, 'temple/hash'
autoload :MutableHash, 'temple/hash'
autoload :InvalidExpression, 'temple/generators'
autoload :Generator, 'temple/generators'
autoload :Generators, 'temple/generators'
autoload :Engine, 'temple/engine'
autoload :Utils, 'temple/utils'
autoload :Filter, 'temple/filter'
autoload :Templates, 'temple/templates'
autoload :Grammar, 'temple/grammar'
autoload :ImmutableHash, 'temple/hash'
autoload :MutableHash, 'temple/hash'

module Mixins
autoload :Dispatcher, 'temple/mixins/dispatcher'
autoload :EngineDSL, 'temple/mixins/engine_dsl'
autoload :GrammarDSL, 'temple/mixins/grammar_dsl'
autoload :Options, 'temple/mixins/options'
autoload :DefaultOptions, 'temple/mixins/options'
autoload :Template, 'temple/mixins/template'
autoload :Dispatcher, 'temple/mixins/dispatcher'
autoload :CompiledDispatcher, 'temple/mixins/dispatcher'
autoload :EngineDSL, 'temple/mixins/engine_dsl'
autoload :GrammarDSL, 'temple/mixins/grammar_dsl'
autoload :Options, 'temple/mixins/options'
autoload :DefaultOptions, 'temple/mixins/options'
autoload :Template, 'temple/mixins/template'
end

module ERB
autoload :Engine, 'temple/erb/engine'
autoload :Parser, 'temple/erb/parser'
autoload :Trimming, 'temple/erb/trimming'
autoload :Template, 'temple/erb/template'
autoload :Engine, 'temple/erb/engine'
autoload :Parser, 'temple/erb/parser'
autoload :Trimming, 'temple/erb/trimming'
autoload :Template, 'temple/erb/template'
end

module Filters
autoload :ControlFlow, 'temple/filters/control_flow'
autoload :MultiFlattener, 'temple/filters/multi_flattener'
autoload :StaticMerger, 'temple/filters/static_merger'
autoload :DynamicInliner, 'temple/filters/dynamic_inliner'
autoload :Escapable, 'temple/filters/escapable'
autoload :Eraser, 'temple/filters/eraser'
autoload :Validator, 'temple/filters/validator'
autoload :ControlFlow, 'temple/filters/control_flow'
autoload :MultiFlattener, 'temple/filters/multi_flattener'
autoload :StaticMerger, 'temple/filters/static_merger'
autoload :DynamicInliner, 'temple/filters/dynamic_inliner'
autoload :Escapable, 'temple/filters/escapable'
autoload :Eraser, 'temple/filters/eraser'
autoload :Validator, 'temple/filters/validator'
end

module HTML
autoload :Dispatcher, 'temple/html/dispatcher'
autoload :Filter, 'temple/html/filter'
autoload :Fast, 'temple/html/fast'
autoload :Pretty, 'temple/html/pretty'
autoload :AttributeMerger, 'temple/html/attribute_merger'
autoload :Dispatcher, 'temple/html/dispatcher'
autoload :Filter, 'temple/html/filter'
autoload :Fast, 'temple/html/fast'
autoload :Pretty, 'temple/html/pretty'
autoload :AttributeMerger, 'temple/html/attribute_merger'
autoload :AttributeSorter, 'temple/html/attribute_sorter'
autoload :AttributeRemover, 'temple/html/attribute_remover'
end
end

0 comments on commit e673ed7

Please sign in to comment.