slim-template / slim Goto Github PK
View Code? Open in Web Editor NEWSlim is a template language whose goal is to reduce the syntax to the essential parts without becoming cryptic.
Home Page: https://slim-template.github.io
License: MIT License
Slim is a template language whose goal is to reduce the syntax to the essential parts without becoming cryptic.
Home Page: https://slim-template.github.io
License: MIT License
Slim should allow you to simply do:
script type="text/javascript"
var a = 'something useful'
function my_func(){
//blah blah
}
And similarily
p
This is my awesome paragraph I wrote without having to start the line with a backtick.
Right now you'll have to do:
meta name="#{something}" value="#{anotherthing}"
I propose we allow for this syntax:
meta name=something value=anotherthing
If the Ruby code you wish to evaluate contains a space, you'll have to enclose it in parens/brackets/braces:
meta name=(1 + 1) value=anotherthing
This allows us to add another cool feature: If the Ruby code returns true, we can simply output name
(or name="name"
in XHTML-mode). If it returns false/nil we don't include the parameter at all.
If someone wants it for textmate, I want it too for emacs :)
Need an Erb2Slim converter.
I'm finding it really hard to parse (in my head) the following line (assuming meta tags have content):
meta name="keywords" content="template language" real content
It's so hard to see where the attributes and the real content starts. It's much cleaner with parentheses:
meta(name="keywords" content="template language") real content
This also fixes another "problem": How to write a tag which has content that starts with an equal sign:
meta(name="keywords")= ruby_code
meta(name="keywords") = Equal sign
Example:
= content_tag(:p) do
- if true
| test
If you're running Rails 3 and does a = foo
, it should not escape it if foo.html_safe?
returns true. What if we add a new method in slim.rb:
def escape_html_with_html_safe(str)
if str.to_s.html_safe?
str
else
escape_html(str)
end
end
And a option (let's say :html_safe => true
) to Slim::Compiler which then uses escape_html_with_html_safe instead of escape_html for escaping.
Template should take filename as template parameter to report errors correctly.
With 0.6.x line, block variables (like for or each do) no longer evaluate properly.
Looking at the optimized generated code:
Seems that the escape_html is treating item
as a method when is actually a local variable.
Is there a way to make slim format/indent the HTML? It's really hard to debug with everything on online. As a temporary hack, I'm using this middleware in dev:
class ResponseBodyFormatter
def initialize(app)
@app = app
end
def call(env)
status, headers, response = @app.call(env)
unless response.body.blank?
response.body = Nokogiri::HTML.parse(response.body).to_xhtml
end
[status, headers, response]
end
end
Have a great set submitted by activestylus:
I thought the most obvious thing would be to use measuring tape as a motif, since slim is like haml without the fat. Here are 6 quick examples I cooked up to get the ball rolling: http://i56.tinypic.com/2w2j81t.png
1 of them is without tape in case you think an understated look works best. Let me know!
I would like to know what you think...please let me know in the comments. If you want to submit a logo, please do so.
Note Since we can't leave this open ended. I will close this issue Sunday Oct 24th (6pm EST) and make a decision. If you want to submit a logo, please have it in by Friday Oct 22nd. Thank you!!!!
I was using Textmate to edit a slim file. Textmate doesn't always append a newline at end of the file like I think other editors (vim?) do. So when I ran it, I got this error:
ActionView::Template::Error (undefined local variable or method `yiel' for #<#<Class:0x00000100c1fc18>:0x00000100c1d170>):
7: body
8: #container
9: #box
10: = yield
I made sure the file ended in a newline and that seemed to fix it, but it does seem like a case slim should handle. And this I did check on 0.7.0 :)
Since Rails 3 pretty much takes care of automatic escaping of values, is there a way to turn off escaping in slim? It's kind of annoying to have to put == everywhere instead of =
To reflect the switch to Temple, etc, etc.
Slim/Haml like syntax is wonderful, but the '-' character makes it too easy to let your code creep into your views. It would be very useful if you can provide an option to the Slim renderer that the '-' character is not allowed. Instead another character could be used that provides mustache like data passing:
Hi everyone,
I'm using Slim 0.7.0 and with this template:
== form_for(@user) do |f|
p
== f.label(:name, 'Name')
== f.text_field(:name)
I'm getting this HTML (I've indented for clarity):
Name
The p tag should be inside the form tag. Any ideas?
More details at http://groups.google.com/group/slim-template/browse_thread/thread/712d71d08ec8ed69
I've been checking out slim, converting my haml views to slim, happily deleting percent signs, but one annoyance I've run into is that you can't use method without parentheses. Example, this works:
== yield(:sidebar)
But this:
== yield :sidebar
Gives this error:
foo.slim:1: syntax error, unexpected tSYMBEG, expecting keyword_end
...d=\"sidebar\">";_buf << yield :sidebar;_buf << "</div></div>...
... ^
Investigate Rails Handler/Rails change needed to use Tilt::CompileSite
Right now, all the text is parsed as if it was inside a double quote. You can easily break Slim by p Hello "World"
.
What is the intended spec of pieces of text? Only allow interpolation? Also allow \n
etc?
Need an HTML to Slim converter.
The current master branch is effectively dead since all efforts are going into the temple branch, may I suggest that we promote the temple branch as master. Yay/Nay?
Right now the parser is essentially a class with two gigantic methods (compile
and parse_tag
). This is really getting confusing since we're adding more features, etc.
I know there are some other outstanding tickets, and in fact I'm working on some of the other tickets as well. But I would just like to make a note here, that before releasing the next version (0.7.0.beta.1), we need to clean up the code to be more readable.
The line numbering is broken at some places. This is important for error reporting. For example:
Broken lines:
p
= "long ruby line" + \
"which is broken"
Embedded engines:
p
:markdown
a
b
c
@judofyr: Do you have ideas on how to fix this?
We could make a new bugfix release now from the master branch. After that we merge the logic-less function.
We could also merge it before. Would not hurt because the function is disabled by default.
I miss being able to do this
= link_to "foo", "bar"
Slim makes me go all explicit
== link_to( "foo" , "bar" )
Also, I don't know how you guys feel about this, but in 90% of my cases I don't want html escaped
Seems to make more sense to have:
= unescaped
== escaped
Visually those double equals stand out so you clearly see which strings are escaped. Right now my template looks like a minefield of =='s
Perhaps this could be set via config?? Just thinking out loud..
this is pretty nice - just wondered if you'd seen jade (which seems to have similar ideas)
The temple version is very slow due to the multiple filtering stages. I like the temple design but is it really worth it?
i.e. Haml uses ':engine' instead of 'engine:' which we use now for Slim.
http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#filters
Haml supports this (one of its killer features imo) and I would love to see it in slim. Would even look into implementing it myself. Some syntax idea:
html
body
markdown:
Hello world
===========
How are you doing?
For choosing a template engine slim could simply rely on tilt (which of course would offer crazy options like emedding haml, slim, erb...).
So what do you think?
To get a bit coverage and traffic, etc, etc, hopefully we'll make it.
As suggested by my colleague @ryan-allen. :-)
A few days ago I made a commit which enables optional end statements (f0102c9). Unfortunately this works only for cases like
- if test
p
- else
p
- end
But not for cases where capture is involved because the compiler inserts ends itself for the capture blocks. This does not work:
= hello_world "Hello Ruby!" do
- if true
| Hello from within a block!
- end
- end
I implemented a fix for this problem but it gets really ugly. See the two last commits in the branch
http://github.com/stonean/slim/tree/output-with-optional-end
What do you think? Shall we remove the support for optional end statements or use the ugly code? Or shall we keep it but not for output blocks?
Optional ends for output blocks are especially ugly:
= output do
...
- end
I would rather prefer
= output do
...
= end
But it all gets inconsistent....
This does not work:
p#some_id.some_class data-info="info for js"
The tests seem to be a bit unstructured. There are a lot of helpers which are used for one or two tests. Maybe switch the framework.
After bf63286 there's a lot of freedom when choosing delimiters for attributes. You can do meta|name="foo"|
or meta[name="foo"]
etc. I've been thinking about how to implement #14 and there's a need for delimiters there too (for more complex Ruby code like tag attr=(users.size - 1)
. I want to be consistent with the delimiters used for attributes, but I can't keep up the full freedom here.
I believe we have two options (to keep it consistent):
By choosing 1 all Slim templates will look the same, but by choosing 2 the users can choose the style that matches best for their template. Example:
meta(name=(1 + 1)) Hello # You're forced to something like this with option 1
meta(name=[1 + 1]) Hello # More freedom, but not full freedom with option 2
I think option 2 is the best compromise: some freedom, but still strict enough that every Slim template looks somewhat similar.
Just making a note here. We need it fixed before pushing out the next release. Need to add tests for it too.
Enough said:
http://github.com/stonean/slim/blob/master/lib/slim.rb#L3-5
Some users don't want the overhead bundler means. We rather prefer Isolate.
Also, adding the lib path are you're doing at line 3 is bad (IMHO). You should not be playing with $:
.
Time to go on a feature freeze. Vet out the current functionality and build a proper doc site with gh-pages. So, tests, tests and more tests are welcome!
Find in the following gist:
https://gist.github.com/e1291eb84136699e3a05
The removal of $:
playing and the usage of Bundler only during development.
Also corrected the coverage exclusion and tested that these changes work properly with rake and normal code invocation (ruby -Ilib my_script.rb
)
This applies cleanly over master.
Thank you.
The following code:
# Find any literal class/id attributes
while line =~ /^(#|\.)(\w+)/
key = ATTR_SHORTHAND[$1]
value = '"%s"' % $2
attributes << [key, value]
line = $'
end
Doesn't do well against the id/class elements standard:
In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A1 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, or a hyphen followed by a digit. Identifiers can also contain escaped characters and any ISO 10646 character as a numeric code (see next item). For instance, the identifier "B&W?" may be written as "B&W?" or "B\26 W\3F".
Now that our API is mostly stable, it's a good time to start implementing these tools so that more users could make the switch. :-)
The template is here: http://gist.github.com/647523.
I have also tried using the syntax at http://slim-lang.com/docs.html where you specify:
== render :partial, 'user'
...no joy
The error:
/Users/buddha/Sites/jl/app/views/layouts/jpage.html.slim:1: syntax error, unexpected tLABEL, expecting keyword_do or '{' or '('
...s";_buf << render partial: 'layouts/nav';_buf << "</div...
... ^
/Users/buddha/Sites/jl/app/views/layouts/jpage.html.slim:1: syntax error, unexpected tLABEL, expecting keyword_do or '{' or '('
...(yield);_buf << render partial: 'layouts/footer';_buf << ren...
... ^
/Users/buddha/Sites/jl/app/views/layouts/jpage.html.slim:1: syntax error, unexpected tLABEL, expecting keyword_do or '{' or '('
...footer';_buf << render partial: 'layouts/madeby';_buf << "</...
...
and the stack trace:
actionpack (3.0.0) lib/action_view/template.rb:255:in module_eval' actionpack (3.0.0) lib/action_view/template.rb:255:in
compile'
actionpack (3.0.0) lib/action_view/template.rb:134:in block in render' activesupport (3.0.0) lib/active_support/notifications.rb:54:in
instrument'
actionpack (3.0.0) lib/action_view/template.rb:127:in render' actionpack (3.0.0) lib/action_view/render/layouts.rb:80:in
_render_layout'
actionpack (3.0.0) lib/action_view/render/rendering.rb:62:in block in _render_template' activesupport (3.0.0) lib/active_support/notifications.rb:52:in
block in instrument'
activesupport (3.0.0) lib/active_support/notifications/instrumenter.rb:21:in instrument' activesupport (3.0.0) lib/active_support/notifications.rb:52:in
instrument'
actionpack (3.0.0) lib/action_view/render/rendering.rb:56:in _render_template' actionpack (3.0.0) lib/action_view/render/rendering.rb:26:in
render'
actionpack (3.0.0) lib/abstract_controller/rendering.rb:114:in _render_template' actionpack (3.0.0) lib/abstract_controller/rendering.rb:108:in
render_to_body'
actionpack (3.0.0) lib/action_controller/metal/renderers.rb:47:in render_to_body' actionpack (3.0.0) lib/action_controller/metal/compatibility.rb:55:in
render_to_body'
actionpack (3.0.0) lib/abstract_controller/rendering.rb:101:in render_to_string' actionpack (3.0.0) lib/abstract_controller/rendering.rb:92:in
render'
actionpack (3.0.0) lib/action_controller/metal/rendering.rb:17:in render' actionpack (3.0.0) lib/action_controller/metal/instrumentation.rb:40:in
block (2 levels) in render'
activesupport (3.0.0) lib/active_support/core_ext/benchmark.rb:5:in block in ms' /Users/buddha/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/benchmark.rb:309:in
realtime'
activesupport (3.0.0) lib/active_support/core_ext/benchmark.rb:5:in ms' actionpack (3.0.0) lib/action_controller/metal/instrumentation.rb:40:in
block in render'
actionpack (3.0.0) lib/action_controller/metal/instrumentation.rb:78:in cleanup_view_runtime' activerecord (3.0.0) lib/active_record/railties/controller_runtime.rb:15:in
cleanup_view_runtime'
actionpack (3.0.0) lib/action_controller/metal/instrumentation.rb:39:in render' actionpack (3.0.0) lib/action_controller/metal/implicit_render.rb:10:in
default_render'
actionpack (3.0.0) lib/action_controller/metal/implicit_render.rb:5:in send_action' actionpack (3.0.0) lib/abstract_controller/base.rb:150:in
process_action'
actionpack (3.0.0) lib/action_controller/metal/rendering.rb:11:in process_action' actionpack (3.0.0) lib/abstract_controller/callbacks.rb:18:in
block in process_action'
activesupport (3.0.0) lib/active_support/callbacks.rb:435:in _run__192140777088512817__process_action__2373947522437712861__callbacks' activesupport (3.0.0) lib/active_support/callbacks.rb:409:in
_run_process_action_callbacks'
activesupport (3.0.0) lib/active_support/callbacks.rb:93:in run_callbacks' actionpack (3.0.0) lib/abstract_controller/callbacks.rb:17:in
process_action'
actionpack (3.0.0) lib/action_controller/metal/instrumentation.rb:30:in block in process_action' activesupport (3.0.0) lib/active_support/notifications.rb:52:in
block in instrument'
activesupport (3.0.0) lib/active_support/notifications/instrumenter.rb:21:in instrument' activesupport (3.0.0) lib/active_support/notifications.rb:52:in
instrument'
actionpack (3.0.0) lib/action_controller/metal/instrumentation.rb:29:in process_action' actionpack (3.0.0) lib/action_controller/metal/rescue.rb:17:in
process_action'
actionpack (3.0.0) lib/abstract_controller/base.rb:119:in process' actionpack (3.0.0) lib/abstract_controller/rendering.rb:40:in
process'
actionpack (3.0.0) lib/action_controller/metal.rb:133:in dispatch' actionpack (3.0.0) lib/action_controller/metal/rack_delegation.rb:14:in
dispatch'
actionpack (3.0.0) lib/action_controller/metal.rb:173:in block in action' actionpack (3.0.0) lib/action_dispatch/routing/route_set.rb:62:in
call'
actionpack (3.0.0) lib/action_dispatch/routing/route_set.rb:62:in dispatch' actionpack (3.0.0) lib/action_dispatch/routing/route_set.rb:27:in
call'
rack-mount (0.6.13) lib/rack/mount/route_set.rb:148:in block in call' rack-mount (0.6.13) lib/rack/mount/code_generation.rb:93:in
block in recognize'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:68:in optimized_each' rack-mount (0.6.13) lib/rack/mount/code_generation.rb:92:in
recognize'
rack-mount (0.6.13) lib/rack/mount/route_set.rb:139:in call' actionpack (3.0.0) lib/action_dispatch/routing/route_set.rb:492:in
call'
actionpack (3.0.0) lib/action_dispatch/middleware/best_standards_support.rb:17:in call' actionpack (3.0.0) lib/action_dispatch/middleware/head.rb:14:in
call'
rack (1.2.1) lib/rack/methodoverride.rb:24:in call' actionpack (3.0.0) lib/action_dispatch/middleware/params_parser.rb:21:in
call'
actionpack (3.0.0) lib/action_dispatch/middleware/flash.rb:182:in call' actionpack (3.0.0) lib/action_dispatch/middleware/session/abstract_store.rb:149:in
call'
actionpack (3.0.0) lib/action_dispatch/middleware/cookies.rb:287:in call' activerecord (3.0.0) lib/active_record/query_cache.rb:32:in
block in call'
activerecord (3.0.0) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in cache' activerecord (3.0.0) lib/active_record/query_cache.rb:12:in
cache'
activerecord (3.0.0) lib/active_record/query_cache.rb:31:in call' activerecord (3.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in
call'
actionpack (3.0.0) lib/action_dispatch/middleware/callbacks.rb:46:in block in call' activesupport (3.0.0) lib/active_support/callbacks.rb:415:in
_run_call_callbacks'
actionpack (3.0.0) lib/action_dispatch/middleware/callbacks.rb:44:in call' rack (1.2.1) lib/rack/sendfile.rb:107:in
call'
actionpack (3.0.0) lib/action_dispatch/middleware/remote_ip.rb:48:in call' actionpack (3.0.0) lib/action_dispatch/middleware/show_exceptions.rb:46:in
call'
railties (3.0.0) lib/rails/rack/logger.rb:13:in call' rack (1.2.1) lib/rack/runtime.rb:17:in
call'
activesupport (3.0.0) lib/active_support/cache/strategy/local_cache.rb:72:in call' rack (1.2.1) lib/rack/lock.rb:11:in
block in call'
internal:prelude:10:in synchronize' rack (1.2.1) lib/rack/lock.rb:11:in
call'
actionpack (3.0.0) lib/action_dispatch/middleware/static.rb:30:in call' railties (3.0.0) lib/rails/application.rb:168:in
call'
railties (3.0.0) lib/rails/application.rb:77:in method_missing' railties (3.0.0) lib/rails/rack/log_tailer.rb:14:in
call'
rack (1.2.1) lib/rack/content_length.rb:13:in call' rack (1.2.1) lib/rack/handler/webrick.rb:52:in
service'
/Users/buddha/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/httpserver.rb:111:in service' /Users/buddha/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/httpserver.rb:70:in
run'
/Users/buddha/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Pygments is used by github for gists etc
Escaped:
= hello_world
Not:
= hello_world do
| ruby
Yes, I am aware of that it's quite hard to fix it, so I propose that we simply remove the feature all together. Beside, they're usage seems very limited. Do you have an example of how you use them?
is the commit hook enabled? the documentation is then available at http://rdoc.info/github/stonean/slim
Need tests for lib/slim/rails.rb
It's current broken, so let's make it compatible.
I'm working on it.
Anyone cooked one up yet?
Also, is there a google group for this gem yet?
This test shouldn't fail:
def test_render_with_no_trailing_character
source = %q{
p
= hello_world}
assert_html '<p>Hello World from @env</p>', source
end
We need a syntax for explicitly closed tags. Options:
img/ src="img.jpg"
img/(src="img.jpg")
img src="img.jpg" /
img(src="img.jpg")/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.