slim 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -8,7 +8,7 @@ Slim is a Rails 3, Ruby 1.9.2 templating option. I do not intend on making a Ra
8
8
 
9
9
  ## Why?
10
10
 
11
- Simply put, I wanted to see if I could pull of a minimalistic template language that was at least matched Erb's speed. Yes, Slim is speedy.
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
13
  ### The syntax
14
14
 
@@ -16,7 +16,8 @@ I actually like the indentation and tag closing nature of Haml. I don't like th
16
16
 
17
17
 
18
18
  So here's what I came up with:
19
-
19
+
20
+ ! doctype html
20
21
  html
21
22
  head
22
23
  title Slim Examples
@@ -48,11 +49,48 @@ So here's what I came up with:
48
49
  ` $(content).do_something();
49
50
 
50
51
 
52
+ ### How do I?
53
+
54
+ #### Add content to a tag
55
+
56
+ # Either start on the same line as the tag
57
+
58
+ body
59
+ h1 id="headline" Welcome to my site.
60
+
61
+ # Or nest it. __Note:__ Must use backtick (with following space) to escape processing
62
+
63
+ body
64
+ h1 id="headline"
65
+ ` Welcome to my site.
66
+
67
+ #### Add content to a tag with code
68
+
69
+ # Can make the call on the same line
70
+
71
+ body
72
+ h1 id="headline" = page_headline
73
+
74
+ # Or nest it.
75
+
76
+ body
77
+ h1 id="headline"
78
+ = page_headline
79
+
80
+ #### Set an attribute's value with a method?
81
+
82
+ # Just use standard Ruby interpolation.
83
+
84
+ body
85
+ table
86
+ - for user in users do
87
+ tr id="user_#{user.id}"
88
+
89
+
51
90
  ### Things to know:
52
91
 
53
92
  * Standard Ruby syntax after '-' and '='
54
93
  * __end__ is not required
55
- * Ruby code must be on it's own line (__TODO:__ allow inline)
56
94
  * If you're making a method call, wrap the arguments in parenthesis (__TODO:__ make this a non requirement)
57
95
  * Can put content on same line or nest it.
58
96
  * If you nest content (e.g. put it on the next line), start the line with a backtick ('`')
@@ -61,6 +99,7 @@ So here's what I came up with:
61
99
 
62
100
 
63
101
  ### Line indicators:
102
+ __Please note that all line indicators must be followed by a space__
64
103
 
65
104
  * `
66
105
  * The backtick tells Slim to just copy the line. It essentially escapes any processing.
@@ -73,9 +112,4 @@ So here's what I came up with:
73
112
  ` ! doctype html renders <!doctype html> `
74
113
 
75
114
 
76
- ### Stuff I need to do (in no particular order)
77
-
78
- * Tackle Encoding.
79
- * Optimize the compiled code. I know it can be even faster.
80
- * Tackle the __TODO's__ above
81
- * ??? Suggestions...
115
+ ### Please add feature requests and bugs to the Github issue tracker.
@@ -8,7 +8,7 @@ require 'slim/engine'
8
8
  module Slim
9
9
  class << self
10
10
  def version
11
- '0.1.0'
11
+ '0.2.0'
12
12
  end
13
13
  end
14
14
  end
@@ -70,7 +70,12 @@ module Slim
70
70
  end
71
71
 
72
72
  if string
73
- @compiled << "_buf << \"#{string}\";"
73
+ string.lstrip!
74
+ if string =~ /^=(.*)/
75
+ @compiled << "_buf << #{$1.strip};"
76
+ else
77
+ @compiled << "_buf << \"#{string}\";"
78
+ end
74
79
  end
75
80
  when :text
76
81
  @compiled << "_buf << \"#{string}\";"
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{slim}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
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-09-15}
12
+ s.date = %q{2010-09-17}
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 = [
@@ -10,6 +10,10 @@ require 'slim'
10
10
 
11
11
 
12
12
  class Env
13
+ def id_helper
14
+ "notice"
15
+ end
16
+
13
17
  def show_first?
14
18
  false
15
19
  end
@@ -270,6 +270,24 @@ TEMPLATE
270
270
  assert_equal expected, output
271
271
  end
272
272
 
273
+ def test_simple_html_with_params_and_code_call
274
+ string = <<TEMPLATE
275
+ html
276
+ head
277
+ title Simple Test Title
278
+ meta name="description" content="This is a Slim Test, that's all"
279
+ body
280
+ p id="first" = hello_world
281
+ TEMPLATE
282
+
283
+ expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "<meta name=\"description\" content=\"This is a Slim Test, that's all\"/>";_buf << "</head>";_buf << "<body>";_buf << "<p id=\"first\">";_buf << hello_world;_buf << "</p>";_buf << "</body>";_buf << "</html>";_buf.join;|
284
+
285
+ output = TestEngine.new(string).compiled
286
+
287
+ assert_equal expected, output
288
+ end
289
+
290
+
273
291
  # Use this to do a line by line check. Much easier to see where the problem is.
274
292
  def iterate_it(expected, output)
275
293
  es = expected.split(';')
@@ -76,6 +76,42 @@ HTML
76
76
  assert_equal expected, engine.render(@env)
77
77
  end
78
78
 
79
+ def test_render_with_call_to_set_attribute
80
+ string = <<HTML
81
+ html
82
+ head
83
+ title Simple Test Title
84
+ body
85
+ h1 This is my title
86
+ p id="#\{id_helper}"
87
+ = hello_world
88
+ HTML
89
+
90
+ engine = Slim::Engine.new(string)
91
+
92
+ expected = "<html><head><title>Simple Test Title</title></head><body><h1>This is my title</h1><p id=\"notice\">Hello World from @env</p></body></html>"
93
+
94
+ assert_equal expected, engine.render(@env)
95
+ end
96
+
97
+ def test_render_with_call_to_set_attribute_and_call_to_set_content
98
+ string = <<HTML
99
+ html
100
+ head
101
+ title Simple Test Title
102
+ body
103
+ h1 This is my title
104
+ p id="#\{id_helper}" = hello_world
105
+ HTML
106
+
107
+ engine = Slim::Engine.new(string)
108
+
109
+ expected = "<html><head><title>Simple Test Title</title></head><body><h1>This is my title</h1><p id=\"notice\">Hello World from @env</p></body></html>"
110
+
111
+ assert_equal expected, engine.render(@env)
112
+ end
113
+
114
+
79
115
 
80
116
 
81
117
  end
@@ -2,6 +2,6 @@ require 'helper'
2
2
 
3
3
  class TestSlim < MiniTest::Unit::TestCase
4
4
  def test_version_is_current
5
- assert_equal '0.0.1', Slim.version
5
+ assert_equal '0.1.0', Slim.version
6
6
  end
7
7
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
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-09-15 00:00:00 -04:00
17
+ date: 2010-09-17 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20