sal 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -6
- data/lib/sal/compiler.rb +15 -11
- data/lib/sal/engine.rb +1 -1
- data/lib/sal/version.rb +1 -1
- metadata +42 -48
data/README.md
CHANGED
@@ -10,13 +10,13 @@ With all the other options, why sal.rb?
|
|
10
10
|
|
11
11
|
Having spent many years in `<% %>` land with JSP and ERB templates and seeing the issues that arise with this approach, I wanted to eliminate the ability to freely code in views. My first attempt implementing this idea was [RuHL](https://github.com/stonean/ruhl).
|
12
12
|
|
13
|
-
RuHL had issues though. First and least important from a proof a concept angle was the name. RuHL rules! Bleh.
|
13
|
+
RuHL had issues though. First and least important from a proof a concept angle was the name. RuHL rules! Bleh.
|
14
14
|
|
15
15
|
More to the point: RuHL wasn't compilable and therefore didn't fit easily into the world of Ruby templates. After a short time, the frameworks I had support for (Rails and Sinatra) progressed past RuHL's ability to hack its way into the framework.
|
16
16
|
|
17
17
|
Earlier this year I started work on [sal.js](https://github.com/stonean/sal.js) to tackle another view related issue. It just so happens that the idea behind RuHL was the way to make sal.js a reality. While working on sal.js, I refined the approach RuHL took to make it smarter.
|
18
18
|
|
19
|
-
As it happens, request were made to bring RuHL up-to-date and make it work with the latest and greatest. Also as it happens, this was turning out to be more work that I wanted to put into RuHL knowing the architecture simply wouldn't work in the long term.
|
19
|
+
As it happens, request were made to bring RuHL up-to-date and make it work with the latest and greatest. Also as it happens, this was turning out to be more work that I wanted to put into RuHL knowing the architecture simply wouldn't work in the long term.
|
20
20
|
|
21
21
|
After weeks of distractions and no real clue how to make a compilable RuHL , the solution presented itself and here we are.
|
22
22
|
|
@@ -27,7 +27,7 @@ sal.rb works by parsing your HTML looking for a data-sal attribute and executing
|
|
27
27
|
The simplest of return values is a string. This tells sal to make this value the contents of the tag.
|
28
28
|
|
29
29
|
Lets say there's a method called title:
|
30
|
-
|
30
|
+
|
31
31
|
def title
|
32
32
|
'This is different'
|
33
33
|
end
|
@@ -47,7 +47,7 @@ As you've no doubt noticed, the data-sal attribute is gone and the contents have
|
|
47
47
|
The next return value sal knows about is a hash. With the exception of an :html key, sal simply treats each of the keys as attributes to be added to the tag. The value of the html key becomes the value of the tag.
|
48
48
|
|
49
49
|
Lets say there's a method called login_link:
|
50
|
-
|
50
|
+
|
51
51
|
def login_link
|
52
52
|
if logged_in?
|
53
53
|
{ :href => '/logout', :html => 'Log out' }
|
@@ -58,7 +58,7 @@ Lets say there's a method called login_link:
|
|
58
58
|
|
59
59
|
Then you have some markup in your template like so:
|
60
60
|
|
61
|
-
<a data-sal="
|
61
|
+
<a data-sal="login_link">Login link</a>
|
62
62
|
|
63
63
|
If logged_in is false you'll get:
|
64
64
|
|
@@ -96,7 +96,7 @@ This will give you the Rails-y format for input tags. For example, if current_us
|
|
96
96
|
def full_name
|
97
97
|
first_name + " " + last_name
|
98
98
|
end
|
99
|
-
|
99
|
+
end
|
100
100
|
|
101
101
|
<!-- first_name = 'John', last_name = 'Smith, email = 'jsmith@test.com' -->
|
102
102
|
<div>
|
data/lib/sal/compiler.rb
CHANGED
@@ -23,17 +23,21 @@ module Sal
|
|
23
23
|
def on_sal_code(code, tag, attrs, content)
|
24
24
|
tmp1, tmp2 = unique_name, unique_name
|
25
25
|
content = compile(content)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
[:
|
30
|
-
|
31
|
-
|
32
|
-
[:
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
26
|
+
if code == 'yield'
|
27
|
+
[:dynamic, code]
|
28
|
+
else
|
29
|
+
[:if, "(#{tmp1} = _saldict['#{code}'])",
|
30
|
+
[:multi,
|
31
|
+
[:code, "#{tmp2} = _saldict"],
|
32
|
+
[:code, "_saldict = #{tmp1}"],
|
33
|
+
[:case, tmp1,
|
34
|
+
['Array',
|
35
|
+
[:block, "#{tmp1}.each do |_saldict|",
|
36
|
+
[:html, :tag, tag, ada(attrs), content]]],
|
37
|
+
[:else,
|
38
|
+
[:html, :tag, tag, ada(attrs), content]]],
|
39
|
+
[:code, "_saldict = #{tmp2}"]]]
|
40
|
+
end
|
37
41
|
end
|
38
42
|
|
39
43
|
private
|
data/lib/sal/engine.rb
CHANGED
@@ -12,6 +12,6 @@ module Sal
|
|
12
12
|
filter :StaticMerger # Merge several statics into a single static
|
13
13
|
filter :DynamicInliner # Merge several static/dynamic into single dynamic
|
14
14
|
|
15
|
-
|
15
|
+
wildcard(:Generator) { options[:generator].new(options) }
|
16
16
|
end
|
17
17
|
end
|
data/lib/sal/version.rb
CHANGED
metadata
CHANGED
@@ -1,61 +1,58 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: sal
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.3
|
4
5
|
prerelease:
|
5
|
-
version: 0.2.2
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Andrew Stone
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
date: 2011-05-15 00:00:00 -04:00
|
12
|
+
date: 2011-10-20 00:00:00.000000000 -04:00
|
14
13
|
default_executable:
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
17
16
|
name: nokogiri
|
18
|
-
|
19
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
17
|
+
requirement: &2161648640 !ruby/object:Gem::Requirement
|
20
18
|
none: false
|
21
|
-
requirements:
|
19
|
+
requirements:
|
22
20
|
- - ~>
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version:
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.4'
|
25
23
|
type: :runtime
|
26
|
-
version_requirements: *id001
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: temple
|
29
24
|
prerelease: false
|
30
|
-
|
25
|
+
version_requirements: *2161648640
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: temple
|
28
|
+
requirement: &2161648120 !ruby/object:Gem::Requirement
|
31
29
|
none: false
|
32
|
-
requirements:
|
30
|
+
requirements:
|
33
31
|
- - ~>
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version:
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.3'
|
36
34
|
type: :runtime
|
37
|
-
version_requirements: *id002
|
38
|
-
- !ruby/object:Gem::Dependency
|
39
|
-
name: tilt
|
40
35
|
prerelease: false
|
41
|
-
|
36
|
+
version_requirements: *2161648120
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: tilt
|
39
|
+
requirement: &2161647640 !ruby/object:Gem::Requirement
|
42
40
|
none: false
|
43
|
-
requirements:
|
41
|
+
requirements:
|
44
42
|
- - ~>
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version:
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '1.2'
|
47
45
|
type: :runtime
|
48
|
-
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *2161647640
|
49
48
|
description: sal.rb is an attribute language.
|
50
|
-
email:
|
49
|
+
email:
|
51
50
|
- andy@stonean.com
|
52
51
|
executables: []
|
53
|
-
|
54
52
|
extensions: []
|
55
|
-
|
56
|
-
extra_rdoc_files:
|
53
|
+
extra_rdoc_files:
|
57
54
|
- README.md
|
58
|
-
files:
|
55
|
+
files:
|
59
56
|
- README.md
|
60
57
|
- lib/sal.rb
|
61
58
|
- lib/sal/compiler.rb
|
@@ -68,30 +65,27 @@ files:
|
|
68
65
|
has_rdoc: true
|
69
66
|
homepage: http://github.com/stonean/sal.rb
|
70
67
|
licenses: []
|
71
|
-
|
72
68
|
post_install_message:
|
73
|
-
rdoc_options:
|
69
|
+
rdoc_options:
|
74
70
|
- --charset=UTF-8
|
75
|
-
require_paths:
|
71
|
+
require_paths:
|
76
72
|
- lib
|
77
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
74
|
none: false
|
79
|
-
requirements:
|
80
|
-
- -
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version:
|
83
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
80
|
none: false
|
85
|
-
requirements:
|
86
|
-
- -
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version:
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
89
85
|
requirements: []
|
90
|
-
|
91
86
|
rubyforge_project: sal
|
92
87
|
rubygems_version: 1.6.2
|
93
88
|
signing_key:
|
94
89
|
specification_version: 3
|
95
90
|
summary: sal is a template language.
|
96
91
|
test_files: []
|
97
|
-
|