Giter Site home page Giter Site logo

slim-template / slim Goto Github PK

View Code? Open in Web Editor NEW
5.3K 5.3K 499.0 2.34 MB

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

Ruby 99.25% HTML 0.01% JavaScript 0.02% Slim 0.72%
ruby slim template-engines

slim's People

Contributors

aerostitch avatar aligo avatar benreyn avatar bronson avatar chibicode avatar crackedmind avatar czj avatar dmke avatar donv avatar fredwu avatar henrik avatar jfirebaugh avatar judofyr avatar k0kubun avatar minad avatar noraj avatar ojiry avatar olleolleolle avatar raxoft avatar rbrown avatar scoz avatar sds avatar thewatts avatar uwekubosch avatar victorteokw avatar vis-kid avatar voxik avatar y-yagi avatar yui-knk avatar yuya-matsushima avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slim's Issues

Allow pure Ruby attribute values

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.

Use parentheses for attributes

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

Integrate with Rails 3's html_safe

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.

Filename

Template should take filename as template parameter to report errors correctly.

Formatted HTML?

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

Slim Logo!

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!!!!

Problem if file doesn't end in newline

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 :)

Disable automatic escaping?

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 =

Can't use method calls without parenthesis

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>...
...                               ^

Rails integration

Investigate Rails Handler/Rails change needed to use Tilt::CompileSite

What is the spec for text?

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?

Refactor the parser

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.

Line numbering for embedded engines

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?

New release

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.

Syntactic sugar please

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..

jade

this is pretty nice - just wondered if you'd seen jade (which seems to have similar ideas)

slim parsing is slow

The temple version is very slow due to the multiple filtering stages. I like the temple design but is it really worth it?

Embedding other templating lanuages

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?

optional ends

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....

Restructure the tests

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.

What kind of delimiters should we allow?

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):

  1. Only allow one type of delimiters (parens, brackets or braces)
  2. Allow a selection of delimiters (what about you can freely use parens, brackets and braces where you want?)

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.

Feature freeze prep for release.

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!

Do not play with load path

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.

malfunction html id/class finder

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".

Haml2Slim converter

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. :-)

slim templates throwing syntax errors in rails 3

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:incompile'
actionpack (3.0.0) lib/action_view/template.rb:134:in block in render' activesupport (3.0.0) lib/active_support/notifications.rb:54:ininstrument'
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:inblock 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:ininstrument'
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:inrender'
actionpack (3.0.0) lib/abstract_controller/rendering.rb:114:in _render_template' actionpack (3.0.0) lib/abstract_controller/rendering.rb:108:inrender_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:inrender_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:inrender'
actionpack (3.0.0) lib/action_controller/metal/rendering.rb:17:in render' actionpack (3.0.0) lib/action_controller/metal/instrumentation.rb:40:inblock (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:inrealtime'
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:inblock 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:incleanup_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:indefault_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:inprocess_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:inblock 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:inprocess_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:inblock 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:ininstrument'
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:inprocess_action'
actionpack (3.0.0) lib/abstract_controller/base.rb:119:in process' actionpack (3.0.0) lib/abstract_controller/rendering.rb:40:inprocess'
actionpack (3.0.0) lib/action_controller/metal.rb:133:in dispatch' actionpack (3.0.0) lib/action_controller/metal/rack_delegation.rb:14:indispatch'
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:incall'
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:incall'
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:inblock 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:inrecognize'
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:incall'
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:incall'
rack (1.2.1) lib/rack/methodoverride.rb:24:in call' actionpack (3.0.0) lib/action_dispatch/middleware/params_parser.rb:21:incall'
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:incall'
actionpack (3.0.0) lib/action_dispatch/middleware/cookies.rb:287:in call' activerecord (3.0.0) lib/active_record/query_cache.rb:32:inblock 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:incache'
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:incall'
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:incall'
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:incall'
railties (3.0.0) lib/rails/rack/logger.rb:13:in call' rack (1.2.1) lib/rack/runtime.rb:17:incall'
activesupport (3.0.0) lib/active_support/cache/strategy/local_cache.rb:72:in call' rack (1.2.1) lib/rack/lock.rb:11:inblock in call'
internal:prelude:10:in synchronize' rack (1.2.1) lib/rack/lock.rb:11:incall'
actionpack (3.0.0) lib/action_dispatch/middleware/static.rb:30:in call' railties (3.0.0) lib/rails/application.rb:168:incall'
railties (3.0.0) lib/rails/application.rb:77:in method_missing' railties (3.0.0) lib/rails/rack/log_tailer.rb:14:incall'
rack (1.2.1) lib/rack/content_length.rb:13:in call' rack (1.2.1) lib/rack/handler/webrick.rb:52:inservice'
/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:inrun'
/Users/buddha/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'

Output code with blocks are inconsistent

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?

Syntax for explicitly closed tags

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")/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.