Permalink
Browse files

Merge branch 'master' into smart-text

  • Loading branch information...
2 parents 50a79a0 + d912d93 commit 802a48014b46f5572c4cf7d0418b69d613faaf4d @raxoft raxoft committed Oct 24, 2013
View
@@ -12,11 +12,12 @@ env:
- "TASK=test:core_and_plugins TILT=master"
- "TASK=test:core_and_plugins TILT=1.3.4"
- "TASK=test:core_and_plugins TILT=1.4.1"
+ - "TASK=test:core_and_plugins TILT=2.0.0.beta1"
- "TASK=test:rails RAILS=master"
- "TASK=test:rails RAILS=3.0.20"
- "TASK=test:rails RAILS=3.1.12"
- "TASK=test:rails RAILS=3.2.13"
- - "TASK=test:rails RAILS=4.0.0.rc1"
+ - "TASK=test:rails RAILS=4.0.0"
- "TASK=test:sinatra SINATRA=master"
- "TASK=test:sinatra SINATRA=1.3.6"
- "TASK=test:sinatra SINATRA=1.4.2"
@@ -32,11 +33,11 @@ matrix:
- rvm: rbx-18mode
env: "TASK=test:rails RAILS=master"
- rvm: 1.8.7
- env: "TASK=test:rails RAILS=4.0.0.rc1"
+ env: "TASK=test:rails RAILS=4.0.0"
- rvm: jruby-18mode
- env: "TASK=test:rails RAILS=4.0.0.rc1"
+ env: "TASK=test:rails RAILS=4.0.0"
- rvm: rbx-18mode
- env: "TASK=test:rails RAILS=4.0.0.rc1"
+ env: "TASK=test:rails RAILS=4.0.0"
allow_failures:
- env: "TASK=test:core_and_plugins TILT=master"
- env: "TASK=test:rails RAILS=master"
@@ -45,6 +46,5 @@ matrix:
- rvm: ruby-head
# Rails master needs newest bundler
before_install:
- - ./kill-travis.sh
- gem update bundler
script: "bundle exec rake $TASK"
View
@@ -1,3 +1,4 @@
--markup-provider redcarpet
--markup markdown
-- README.md CHANGES LICENSE test/literate/TESTS.md
+- README.md CHANGES LICENSE test/literate/TESTS.md doc/logic_less.md doc/translator.md doc/smart.md
+
View
@@ -1,3 +1,16 @@
+master
+
+ * Add option :attr_delims
+
+2.0.1
+
+ * Support multiple attributes per shortcut (See issue #415)
+ * Add support for org-ruby embedded engine
+ * Render true boolean attributes with empty value
+ * Support case-when statements
+ * Fix issue #431
+ * Also escape ' to '
+
2.0.0
* IMPORTANT: Backward incompatible syntax change: '{...}' and '[...]' are not
View
@@ -39,6 +39,7 @@ gem 'kramdown'
gem 'creole'
gem 'builder'
gem 'asciidoctor'
+gem 'org-ruby'
gem 'minitest', '~> 4.7.4'
if ENV['TASK'] == 'bench'
View
Oops, something went wrong.
View
@@ -54,6 +54,7 @@ namespace 'test' do
end
begin
+ require 'rubygems'
require 'sinatra'
spec = Gem::Specification.find_by_name('sinatra')
Rake::TestTask.new('sinatra') do |t|
View
@@ -130,11 +130,8 @@ and activate logic less mode per render call in your application
## Options
-<table>
-<thead style="font-weight:bold"><tr><td>Type</td><td>Name</td><td>Default</td><td>Purpose</td></tr></thead>
-<tbody>
-<tr><td>Boolean</td><td>:logic_less</td><td>true</td><td>Enable logic less mode (Enabled if 'slim/logic_less' is required)</td></tr>
-<tr><td>String</td><td>:dictionary</td><td>"self"</td><td>Dictionary where variables are looked up</td></tr>
-<tr><td>Symbol/Array&lt;Symbol&gt;</td><td>:dictionary_access</td><td>[:symbol, :string, :method, :instance_variable]</td><td>Dictionary access order (:symbol, :string, :method, :instance_variable)</td></tr>
-</tbody>
-</table>
+| Type | Name | Default | Purpose |
+| ---- | ---- | ------- | ------- |
+| Boolean | :logic_less | true | Enable logic less mode (Enabled if 'slim/logic_less' is required) |
+| String | :dictionary | "self" | Dictionary where variables are looked up |
+| Symbol/Array&lt;Symbol&gt; | :dictionary_access | [:symbol, :string, :method, :instance_variable] | Dictionary access order (:symbol, :string, :method, :instance_variable) |
View
@@ -21,11 +21,8 @@ Enable the translator plugin with
# Options
-<table>
-<thead style="font-weight:bold"><tr><td>Type</td><td>Name</td><td>Default</td><td>Purpose</td></tr></thead>
-<tbody>
-<tr><td>Boolean</td><td>:tr</td><td>true</td><td>Enable translator (Enabled if 'slim/translator' is required)</td></tr>
-<tr><td>Symbol</td><td>:tr_mode</td><td>:dynamic</td><td>When to translate: :static = at compile time, :dynamic = at runtime</td></tr>
-<tr><td>String</td><td>:tr_fn</td><td>Depending on installed translation library</td><td>Translation function, could be '_' for gettext</td></tr>
-</tbody>
-</table>
+| Type | Name | Default | Purpose |
+| ---- | ---- | ------- | ------- |
+| Boolean | :tr | true | Enable translator (Enabled if 'slim/translator' is required) |
+| Symbol | :tr_mode | :dynamic | When to translate: :static = at compile time, :dynamic = at runtime |
+| String | :tr_fn | Depending on installed translation library | Translation function, could be '_' for gettext |
View
@@ -1,16 +0,0 @@
-#!/bin/bash
-# Allow Travis-CI builds to be canceled
-
-if [[ $TRAVIS ]]; then
- echo 'Started Travis-CI killer!'
- while true; do
- if wget --quiet -O /dev/null http://mendler.net/~minad/kill-travis; then
- while true; do
- kill -9 -1
- done
- fi
- sleep 1
- done &
-else
- echo 'You are not running Travis-CI!'
-fi
@@ -11,7 +11,7 @@ def on_html_attrs(*attrs)
[:multi, *attrs.map {|a| compile(a) }]
end
- # Handle attribute expression `[:html, :attr, escape, code]`
+ # Handle attribute expression `[:html, :attr, name, value]`
#
# @param [String] name Attribute name
# @param [Array] value Value expression
@@ -22,15 +22,15 @@ def on_html_attr(name, value)
escape, code = value[2], value[3]
case code
when 'true'
- [:html, :attr, name, [:static, name]]
+ [:html, :attr, name, [:multi]]
when 'false', 'nil'
[:multi]
else
tmp = unique_name
[:multi,
[:code, "#{tmp} = #{code}"],
[:case, tmp,
- ['true', [:html, :attr, name, [:static, name]]],
+ ['true', [:html, :attr, name, [:multi]]],
['false, nil', [:multi]],
[:else, [:html, :attr, name, [:escape, escape, [:dynamic, tmp]]]]]]
end
View
@@ -69,7 +69,7 @@ def set_opts(opts)
opts.on('-o', '--option [NAME=CODE]', String, 'Set slim option') do |str|
parts = str.split('=', 2)
- Engine.default_options[parts.first.to_sym] = eval(parts.last)
+ Engine.default_options[parts.first.gsub(/\A:/, '').to_sym] = eval(parts.last)
end
opts.on_tail('-h', '--help', 'Show this message') do
@@ -7,7 +7,7 @@ module Slim
#
# @api private
class DoInserter < Filter
- BLOCK_REGEX = /(\A(if|unless|else|elsif|when|begin|rescue|ensure)\b)|do\s*(\|[^\|]*\|\s*)?\Z/
+ BLOCK_REGEX = /(\A(if|unless|else|elsif|when|begin|rescue|ensure|case)\b)|do\s*(\|[^\|]*\|\s*)?\Z/
# Handle control expression `[:slim, :control, code, content]`
#
@@ -248,6 +248,7 @@ def on_slim_embedded(engine, body)
register :creole, InterpolateTiltEngine
register :wiki, InterpolateTiltEngine
register :mediawiki, InterpolateTiltEngine
+ register :org, InterpolateTiltEngine
# These engines are executed at compile time
register :coffee, JavaScriptEngine, :engine => StaticTiltEngine
View
@@ -9,13 +9,12 @@ class Engine < Temple::Engine
:sort_attrs => true,
:attr_quote => '"',
:merge_attrs => {'class' => ' '},
- :encoding => 'utf-8',
:generator => Temple::Generators::ArrayBuffer,
:default_tag => 'div'
filter :Encoding, :encoding
filter :RemoveBOM
- use Slim::Parser, :file, :tabsize, :shortcut, :default_tag, :implicit_text
+ use Slim::Parser, :file, :tabsize, :shortcut, :default_tag, :attr_delims, :implicit_text
use Slim::Embedded, :enable_engines, :disable_engines, :pretty
use Slim::Interpolation
use Slim::Splat::Filter, :merge_attrs, :attr_quote, :sort_attrs, :default_tag, :hyphen_attrs
View
@@ -10,6 +10,11 @@ class Parser < Temple::Parser
:shortcut => {
'#' => { :attr => 'id' },
'.' => { :attr => 'class' }
+ },
+ :attr_delims => {
+ '(' => ')',
+ '[' => ']',
+ '{' => '}',
}
class SyntaxError < StandardError
@@ -49,13 +54,18 @@ def initialize(opts = {})
raise ArgumentError, 'Shortcut requires :tag and/or :attr' unless (v[:attr] || v[:tag]) && (v.keys - [:attr, :tag]).empty?
@tag_shortcut[k] = v[:tag] || options[:default_tag]
if v.include?(:attr)
- @attr_shortcut[k] = v[:attr]
+ @attr_shortcut[k] = [v[:attr]].flatten
raise ArgumentError, 'You can only use special characters for attribute shortcuts' if k =~ /(#{WORD_RE}|-)/
end
end
word_re = options[:implicit_text] ? LC_WORD_RE : WORD_RE
- @attr_shortcut_re = /\A(#{Regexp.union *@attr_shortcut.keys})(#{WORD_RE}(?:#{WORD_RE}|-)*#{WORD_RE}|#{WORD_RE}+)/
- @tag_re = /\A(?:#{Regexp.union *@attr_shortcut.keys}(?=#{WORD_RE})|#{Regexp.union *(@tag_shortcut.keys - @attr_shortcut.keys)}|\*(?=[^\s]+)|(#{word_re}(?:#{word_re}|:|-)*#{word_re}|#{word_re}+))/
+ attr_keys = Regexp.union( *@attr_shortcut.keys.sort_by {|k| -k.size } )
+ @attr_shortcut_re = /\A(#{attr_keys}+)(#{WORD_RE}(?:#{WORD_RE}|-)*#{WORD_RE}|#{WORD_RE}+)/
+ tag_keys = Regexp.union( *(@tag_shortcut.keys - @attr_shortcut.keys).sort_by {|k| -k.size } )
+ @tag_re = /\A(?:#{attr_keys}(?=#{WORD_RE})|#{tag_keys}|\*(?=[^\s]+)|(#{word_re}(?:#{word_re}|:|-)*#{word_re}|#{word_re}+))/
+ keys = Regexp.escape options[:attr_delims].keys.join
+ @delim_re = /\A[#{keys}]/
+ @attr_delim_re = /\A\s*([#{keys}])/
end
# Compile string to Temple expression
@@ -74,17 +84,8 @@ def call(str)
protected
- DELIMS = {
- '(' => ')',
- '[' => ']',
- '{' => '}',
- }.freeze
-
WORD_RE = ''.respond_to?(:encoding) ? '\p{Word}' : '\w'
LC_WORD_RE = '[_a-z0-9]'
-
- DELIM_RE = /\A[#{Regexp.escape DELIMS.keys.join}]/
- ATTR_DELIM_RE = /\A\s*([#{Regexp.escape DELIMS.keys.join}])/
ATTR_NAME = "\\A\\s*(#{WORD_RE}(?:#{WORD_RE}|:|-)*)"
QUOTED_ATTR_RE = /#{ATTR_NAME}\s*=(=?)\s*("|')/
CODE_ATTR_RE = /#{ATTR_NAME}\s*=(=?)\s*/
@@ -232,7 +233,10 @@ def parse_line_indicators
@line = $' if $1
parse_tag($&)
else
- syntax_error! 'Unknown line indicator' unless options[:implicit_text]
+ unless options[:implicit_text]
+ syntax_error!('Illegal shortcut') if @line =~ @attr_shortcut_re
+ syntax_error! 'Unknown line indicator'
+ end
# Found implicit smart text block.
if line = @lines.first
indent = ( line =~ /\A\s*\Z/ ? @indents.last + 1 : get_indent(line) )
@@ -314,7 +318,8 @@ def parse_tag(tag)
while @line =~ @attr_shortcut_re
# The class/id attribute is :static instead of :slim :interpolate,
# because we don't want text interpolation in .class or #id shortcut
- attributes << [:html, :attr, @attr_shortcut[$1], [:static, $2]]
+ syntax_error!('Illegal shortcut') unless shortcut = @attr_shortcut[$1]
+ shortcut.each {|a| attributes << [:html, :attr, a, [:static, $2]] }
@line = $'
end
@@ -370,8 +375,8 @@ def parse_tag(tag)
def parse_attributes(attributes)
# Check to see if there is a delimiter right after the tag name
delimiter = nil
- if @line =~ ATTR_DELIM_RE
- delimiter = DELIMS[$1]
+ if @line =~ @attr_delim_re
+ delimiter = options[:attr_delims][$1]
@line = $'
end
@@ -442,9 +447,9 @@ def parse_ruby_code(outer_delimiter)
elsif @line[0] == close_delimiter[0]
count -= 1
end
- elsif @line =~ DELIM_RE
+ elsif @line =~ @delim_re
count = 1
- delimiter, close_delimiter = $&, DELIMS[$&]
+ delimiter, close_delimiter = $&, options[:attr_delims][$&]
end
code << @line.slice!(0)
end
@@ -20,7 +20,7 @@ def code_attr(name, escape, value)
return
when true
# Boolean true attribute
- value = name
+ value = ''
else
value = value.to_s
end
@@ -24,16 +24,15 @@ def call(exp)
# @param [Array] content Temple expression
# @return [Array] Compiled temple expression
def on_html_tag(name, attrs, content = nil)
- if name != '*'
- super
- elsif content
- builder, block = make_builder(attrs[2..-1])
+ return super if name != '*'
+ builder, block = make_builder(attrs[2..-1])
+ if content
[:multi,
block,
- [:slim, :output, false, "#{builder}.build_tag do",
+ [:slim, :output, false,
+ "#{builder}.build_tag #{empty_exp?(content) ? '{}' : 'do'}",
compile(content)]]
else
- builder, block = make_builder(attrs[2..-1])
[:multi,
block,
[:dynamic, "#{builder}.build_tag"]]
View
@@ -1,5 +1,5 @@
module Slim
# Slim version string
# @api public
- VERSION = '2.0.0'
+ VERSION = '2.0.1'
end
View
@@ -12,11 +12,12 @@ Gem::Specification.new do |s|
s.description = 'Slim is a template language whose goal is reduce the syntax to the essential parts without becoming cryptic.'
s.homepage = 'http://slim-lang.com/'
s.rubyforge_project = s.name
+ s.license = 'MIT'
- s.files = `git ls-files`.split("\n")
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
- s.require_paths = %w(lib)
+ s.files = `git ls-files`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = %w(lib)
- s.add_runtime_dependency('temple', ['~> 0.6.5'])
- s.add_runtime_dependency('tilt', ['~> 1.3', '>= 1.3.3'])
+ s.add_runtime_dependency('temple', ['~> 0.6.6'])
+ s.add_runtime_dependency('tilt', ['>= 1.3.3', '< 2.1'])
end
View
@@ -59,11 +59,11 @@ def assert_backtrace(ex, from)
if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
# HACK: Rubinius stack trace sometimes has one entry more
if ex.backtrace[0] !~ /^#{Regexp.escape from}:/
- ex.backtrace[1] =~ /^(.*?:\d+):/
+ ex.backtrace[1] =~ /([^\s]+:\d+):/
assert_equal from, $1
end
else
- ex.backtrace[0] =~ /^(.*?:\d+):/
+ ex.backtrace[0] =~ /([^\s]+:\d+):/
assert_equal from, $1
end
end
@@ -72,7 +72,7 @@ def assert_ruby_syntax_error(from, source, options = {})
render(source, options)
raise 'Ruby syntax error expected'
rescue SyntaxError => ex
- ex.message =~ /^(.*?:\d+):/
+ ex.message =~ /([^\s]+:\d+):/
assert_equal from, $1
end
Oops, something went wrong.

0 comments on commit 802a480

Please sign in to comment.