slim 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +17 -3
- data/lib/slim.rb +1 -1
- data/lib/slim/compiler.rb +2 -2
- data/slim.gemspec +5 -3
- data/test/slim/test_compiler.rb +3 -1
- data/vim/slim.vim +33 -0
- data/vim/test.slim +27 -0
- metadata +5 -3
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
## Slim
|
1
|
+
## Slim
|
2
2
|
|
3
3
|
Slim is a template language whose goal is reduce the syntax to the essential parts without becoming cryptic.
|
4
4
|
|
@@ -10,6 +10,18 @@ Slim is a Rails 3, Ruby 1.9.2 templating option. I do not intend on making a Ra
|
|
10
10
|
|
11
11
|
Simply put, I wanted to see if I could pull of a template language that required minimum use of special characters and at least matched Erb's speed. Yes, Slim is speedy.
|
12
12
|
|
13
|
+
## How?
|
14
|
+
|
15
|
+
Include Slim in your Gemfile:
|
16
|
+
|
17
|
+
gem 'slim'
|
18
|
+
|
19
|
+
In `config/application.rb`, add the following line near the top:
|
20
|
+
|
21
|
+
require 'slim/rails'
|
22
|
+
|
23
|
+
That's it!
|
24
|
+
|
13
25
|
### The syntax
|
14
26
|
|
15
27
|
I actually like the indentation and tag closing nature of Haml. I don't like the overall result of the markup though, it's a little cryptic. I'm sure, with practice, people read it like the Matrix, but it's never suited me. So why not try to improve it for me? There may be one or two other people with the same thoughts.
|
@@ -118,7 +130,7 @@ So here's what I came up with:
|
|
118
130
|
* __end__ is not required
|
119
131
|
* If you're making a method call, wrap the arguments in parenthesis (__TODO:__ make this a non requirement)
|
120
132
|
* Can put content on same line or nest it.
|
121
|
-
* If you nest content (e.g. put it on the next line), start the line with a backtick ('`')
|
133
|
+
* If you nest content (e.g. put it on the next line), start the line with a backtick ('`') or a pipe ('|')
|
122
134
|
* Indentation matters, but it's not as strict as Haml.
|
123
135
|
* If you want to indent 2 spaces, then 5. It's your choice. To nest markup you only need to indent by one space, the rest is gravy.
|
124
136
|
|
@@ -126,8 +138,10 @@ So here's what I came up with:
|
|
126
138
|
### Line indicators:
|
127
139
|
__Please note that all line indicators must be followed by a space__
|
128
140
|
|
129
|
-
* `
|
141
|
+
* `
|
130
142
|
* The backtick tells Slim to just copy the line. It essentially escapes any processing.
|
143
|
+
* |
|
144
|
+
* *Same as `\``.*
|
131
145
|
* -
|
132
146
|
* The dash denotes control code (similar to Haml). Examples of control code are loops and conditionals.
|
133
147
|
* =
|
data/lib/slim.rb
CHANGED
data/lib/slim/compiler.rb
CHANGED
@@ -7,7 +7,7 @@ module Slim
|
|
7
7
|
include Optimizer
|
8
8
|
AUTOCLOSED = %w(meta img link br hr input area param col base)
|
9
9
|
|
10
|
-
REGEX = /^(\s*)(
|
10
|
+
REGEX = /^(\s*)(!?`?\|?-?=?\w*)(\s*\w*=".+")?(.*)/
|
11
11
|
|
12
12
|
def compile
|
13
13
|
@_buffer = ["_buf = [];"]
|
@@ -39,7 +39,7 @@ module Slim
|
|
39
39
|
string = $4
|
40
40
|
|
41
41
|
line_type = case marker
|
42
|
-
when '`' then :text
|
42
|
+
when '`', '|' then :text
|
43
43
|
when '-' then :control_code
|
44
44
|
when '=' then :output_code
|
45
45
|
when '!' then :declaration
|
data/slim.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{slim}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andrew Stone"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-10-03}
|
13
13
|
s.description = %q{Slim is a template language whose goal is reduce the syntax to the essential parts without becoming cryptic.}
|
14
14
|
s.email = %q{andy@stonean.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -28,7 +28,9 @@ Gem::Specification.new do |s|
|
|
28
28
|
"test/helper.rb",
|
29
29
|
"test/slim/test_compiler.rb",
|
30
30
|
"test/slim/test_engine.rb",
|
31
|
-
"test/test_slim.rb"
|
31
|
+
"test/test_slim.rb",
|
32
|
+
"vim/slim.vim",
|
33
|
+
"vim/test.slim"
|
32
34
|
]
|
33
35
|
s.homepage = %q{http://github.com/stonean/slim}
|
34
36
|
s.rdoc_options = ["--charset=UTF-8"]
|
data/test/slim/test_compiler.rb
CHANGED
@@ -126,9 +126,11 @@ html
|
|
126
126
|
body
|
127
127
|
p
|
128
128
|
` Hello World, meet Slim.
|
129
|
+
p
|
130
|
+
| Hello World, meet Slim again.
|
129
131
|
HTML
|
130
132
|
|
131
|
-
expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<meta name=\"description\" content=\"This is a Slim Test, that's all\"/>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "</head>";_buf << "<body>";_buf << "<p>";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf << "</body>";_buf << "</html>";_buf.join;|
|
133
|
+
expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<meta name=\"description\" content=\"This is a Slim Test, that's all\"/>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "</head>";_buf << "<body>";_buf << "<p>";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf << "<p>";_buf << "Hello World, meet Slim again.";_buf << "</p>";_buf << "</body>";_buf << "</html>";_buf.join;|
|
132
134
|
|
133
135
|
output = TestEngine.new(string).compiled
|
134
136
|
|
data/vim/slim.vim
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
" Vim syntax file
|
2
|
+
" Language: Slim
|
3
|
+
" Maintainer: Andrew Stone <andy@stonean.com>
|
4
|
+
" Version: 1
|
5
|
+
" Last Change: 2010 Sep 25
|
6
|
+
" TODO: Feedback is welcomed.
|
7
|
+
|
8
|
+
" Quit when a syntax file is already loaded.
|
9
|
+
if exists("b:current_syntax")
|
10
|
+
finish
|
11
|
+
endif
|
12
|
+
|
13
|
+
if !exists("main_syntax")
|
14
|
+
let main_syntax = 'slim'
|
15
|
+
endif
|
16
|
+
|
17
|
+
" Allows a per line syntax evaluation.
|
18
|
+
let b:ruby_no_expensive = 1
|
19
|
+
|
20
|
+
" Include Ruby syntax highlighting
|
21
|
+
syn include @slimRuby syntax/ruby.vim
|
22
|
+
|
23
|
+
" Include HTML
|
24
|
+
runtime! syntax/html.vim
|
25
|
+
unlet! b:current_syntax
|
26
|
+
|
27
|
+
syntax region slimHtml start="^\s*[^-=]\w" end="$" contains=htmlTagName, htmlArg, htmlString
|
28
|
+
|
29
|
+
syntax region slimControl start="-" end="$" contains=@slimRuby keepend
|
30
|
+
syntax region slimOutput start=".*=\s" end="$" contains=@slimRuby keepend
|
31
|
+
|
32
|
+
|
33
|
+
let b:current_syntax = "slim"
|
data/vim/test.slim
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
! doctype html
|
2
|
+
head
|
3
|
+
title Slim Vim Test
|
4
|
+
meta name="keywords" content="slim, vim, syntax"
|
5
|
+
body
|
6
|
+
h1 = @page_title
|
7
|
+
p id="notice"
|
8
|
+
'
|
9
|
+
Welcome to the the syntax test. This file is to excercise the various markup.
|
10
|
+
|
11
|
+
- unless @users.empty?
|
12
|
+
table
|
13
|
+
- for user in users do
|
14
|
+
tr
|
15
|
+
td = user.name
|
16
|
+
- else
|
17
|
+
p There are no users.
|
18
|
+
|
19
|
+
script type="text/javascript"
|
20
|
+
'
|
21
|
+
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
22
|
+
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
23
|
+
|
24
|
+
script type="text/javascript"
|
25
|
+
'
|
26
|
+
var pageTracker = _gat._getTracker("UA-12345678-9");
|
27
|
+
pageTracker._trackPageview();
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
8
|
+
- 1
|
9
|
+
version: 0.4.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Andrew Stone
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-10-03 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -40,6 +40,8 @@ files:
|
|
40
40
|
- test/slim/test_compiler.rb
|
41
41
|
- test/slim/test_engine.rb
|
42
42
|
- test/test_slim.rb
|
43
|
+
- vim/slim.vim
|
44
|
+
- vim/test.slim
|
43
45
|
has_rdoc: true
|
44
46
|
homepage: http://github.com/stonean/slim
|
45
47
|
licenses: []
|