Giter Site home page Giter Site logo

slime-lang / slime Goto Github PK

View Code? Open in Web Editor NEW
365.0 10.0 56.0 302 KB

Minimalistic HTML templates for Elixir, inspired by Slim.

Home Page: http://slime-lang.com

License: MIT License

Elixir 96.25% HTML 3.43% Erlang 0.32%
slime elixir template-engine slim-framework slim markup markup-language

slime's People

Contributors

aptinio avatar awea avatar aydarlukmanov avatar bfad avatar bozydar avatar dkln avatar doomspork avatar feymartynov avatar gekola avatar gusaiani avatar henrik avatar kerryb avatar lasseebert avatar liamwhite avatar little-bobby-tables avatar lobo-tuerto avatar lpil avatar paradox460 avatar rakoth avatar sionide21 avatar smeevil avatar smpallen99 avatar sobolevn avatar sztosz avatar tmbb avatar tokafish avatar uasi avatar utkarshkukreti avatar vicmargar avatar yordis 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

slime's Issues

evaluation with character sequence 'do' in a word

After a lot of head scratching I found the following :

=number_input f, :amount, class: "js-donation-amount"

This blows up with :

== Compilation error on file web/views/investment_view.ex ==
** (EEx.SyntaxError) web/templates/investment/new.html.slim:1: unexpected token ' end '
    (eex) lib/eex/compiler.ex:59: EEx.Compiler.generate_buffer/4
    (phoenix) lib/phoenix/template.ex:320: Phoenix.Template.compile/2
    (phoenix) lib/phoenix/template.ex:154: Phoenix.Template."-MACRO-__before_compile__/2-fun-0-"/3
    (elixir) lib/enum.ex:1261: Enum."-reduce/3-lists^foldl/2-0-"/3
    (phoenix) expanding macro: Phoenix.Template.__before_compile__/1
    web/views/investment_view.ex:1: Sheep.InvestmentView (module)

This happens when I use any character sequence containing "do" in it for the class: attribute
It seems it's not limited to the class attribute though but any for that matter.

Textarea adds blank lines

When I upgrade a project from slim_fast 0.7.0 to 0.9.1, the Slim code

textarea id="code" name="code" = "foo"

that previously on 0.7.0 would output

<textarea id="code" name="code">foo</textarea>

now on 0.9.1 outputs

<textarea id="code" name="code">foo
</textarea>

This leads to extra linebreaks in the received input, that were not intended.

Automatically self-close some tags

With #50 we can explicitly ask for a self-closing tag.

Ruby Slim also automatically closes the usual suspects – see docs:

Note, that this is usually not necessary since the standard html tags (img, br, ...) are closed automatically.

We don't seem to do that currently, but it might be fairly easy to add on top of @vicmargar's work in #50.

List of self-closing tags: http://stackoverflow.com/questions/13915201/what-tags-in-html5-are-acknowledged-of-being-self-closing

SlimFast v1.0

After reviewing the Slim documentation (here) it appears that we are almost at feature parity with the Ruby implementation. To me reaching feature parity would constitute a v1.0 of SlimFast. With that in mind I attempted to identify the outstanding functionality and created issues where necessary:

  • Closed tags (#43)
  • Splat attributes (#44)
  • Dynamic tags (#45)

Are there any features missing or any we should not consider to be part of a v1.0 release?

Thoughts, concerns, feedback?

cc @Rakoth @henrik

id attributes are not merged

  test "shorthand and literal id attributes are merged" do
    template = ~s(#id-one id="id-two")
    assert render(template) == ~s(<div id="id-one id-two"></div>)
  end

This fails.

Over-escaped quotes in attributes

Seems like with 0.7.1, this:

link rel="stylesheet" href="#{static_path(@conn, "/css/app.css")}"

Started producing this output:

<link rel="stylesheet" href=&quot;/css/app.css?vsn=625AD8D&quot;>

Which breaks styling because the quotes are over-escaped.

Same result if I try

link rel="stylesheet" href=static_path(@conn,"/css/app.css")

(without a space after the comma, due to #32)

How to install

Hi Sean,

tried to put slim_fast to work.
Created a blank Phoenix app.
Added package as dependency in mix.exs like all others.
Ran mix deps.get.

Then I tried a few things, ranging from simply changing my template’s suffix to .slim to adding SlimFast.evaluate(slim, site_title: "Website Title") to different files, none of which worked :)

Can you give us some pointers on how to put it to work?

Once I understand it, I’ll be happy to add it to the README if that’s helpful.

Thanks

Come up with a catchy tag line / description

Slim:

A lightweight templating engine.
Slim is a template language whose goal is reduce the syntax to the essential parts without becoming cryptic.

Jade:

Jade - robust, elegant, feature rich template engine for Node.js

HAML:

Beautiful, DRY, well-indented, clear markup: templating haiku.

Add support for CLI

It would be great to have slim_fast accessible on the command line. Additionally, it might be fun to benchmark the original Ruby implementation of slim against slim_fast.

Support multi-line verbatim text

SlimFast supports verbatim and verbatim w/ whitespace but only on one line. Per the slim documentation, any subsequent lines with a deeper indentation are included.

Support splat attributes

Splat converts a hash into attribute key/value pairs.

Slim:

.card*{'data-url'=>place_path(place), 'data-id'=>place.id} = place.name

HTML:

<div class="card" data-id="1234" data-url="/place/1234">Slim's house</div>

See slim docs: Splat Attributes.

No way to conditionally add attribute?

I want to either set the "checked" attribute of a checkbox, or to have no such attribute at all. Because if the attribute is present but the value is e.g. an empty string, the box is still considered to be checked.

Not sure how to do this with slim_fast. Tried things like:

# Compilation error
input type="checkbox" name="meta" value="true" checked=(if @meta, do: "true")

# Not rendered correctly at all
input*[ type: "checkbox", name: "Meta", value: "true", checked: @meta ]

Ended up working around it by rendering the entire element in two different logic branches:

      = if @meta do
        input type="checkbox" name="meta" value="true" checked="checked"

      = unless @meta do
        input type="checkbox" name="meta" value="true"

Language reference/guide

It would be great to have a language guide somewhere, something like http://jade-lang.com/reference/ or http://www.rubydoc.info/gems/slim/frames. It could go through all the syntax we support, with examples. Especially seeing as we don't map exactly to Ruby Slim.

We could also mention any current limitations with stuff we have yet to implement, gotchas and such.

https://github.com/elixir-lang/ex_doc supports "extras" so maybe that would make sense. Or could we get a usable guide out of the moduledocs (#18) without writing "extras"?

Attribute order matters ?

Hi there, I've recently imported some slim template from a Ruby project, at first everything was fine. Then something happens !

I write a test in test/rendering/attributes_test.exs to make this more understable:

test "attributes order doesn't matter" do
  assert render("a#bar.foo") == ~s(<a class="foo" id="bar"></a>) # => true
  assert render("a.foo#bar") == ~s(<a class="foo" id="bar"></a>) # => false
end

unescaped attributes

Hi. Is there a way to avoid escaping of an attribute? Slim has '==' for that but looks like it doesn't work in Slime

Support closed tags

This:

img src="image.png"/

Should produce this:

<img src="image.png"/>

ExUnit sample (test/renderer_test.exs):

test "render closed tag" do
  assert render(~s(img src="image.png"/)) == ~s(<img src="image.png"/>)
end

Slim docs: Closed tags

setting style via variable

A case i found :

-style = get_flash(@conn, :email_error) && "" || "display: none"
.alert-box.warning.js-news-letter-error.text-center style=style data-alert="data-alert"
  .js-error-message= get_flash(@conn, :email_error)

renders to :

<div class="alert-box warning js-news-letter-error text-center" data-alert="data-alert" style="display:" none=""><div class="js-error-message"></div></div>

where the problems is style="display:" none="" which should be style="display: none"

Benchmark SlimFast and Ruby Slim

I think it would be interesting to compare SlimFast and the original Slim implementation. Putting together a simple benchmark could be fun.

Sample Projects

It might be helpful to put together sample projects for integrating slim_fast into a Plug and Phoenix app.

Remove unqualified import statements

Unqualified import statements make it unclear where functions are defined, and offer no advantage over full qualified names, or aliased names.

Refactor Slime.Parser

I'm finding this module very difficult to read and to modify, and I think it would be a good candidate for refactoring.

Use of module attributes over string literals makes it difficult to understand which function definition is going to match without scrolling to the top of the module to read their assignments.

Lots of the functions are complex and difficult to understand the intent of.

Better syntax error messages

** (SyntaxError) web/templates/page/index.html.slim:1: syntax error before: '|'
** (SyntaxError) web/templates/layout/app.html.slim:1: unexpected token: "}". "(" starting at line 1 is missing terminator ")"
I've been trying to convert from ruby slim to slim fast. It's annoying to only get "line 1 syntax errors".
Have I missed some configuration setting?
Is this planned on making it better in the future?

Doesn't support else (?)

Had no luck with this:

      = if @meta do
        input type="checkbox" name="meta" value="true" checked="checked"
      = else  # also tried "- else"
        input type="checkbox" name="meta" value="true"

So I ended up working around it like this:

      = if @meta do
        input type="checkbox" name="meta" value="true" checked="checked"

      = unless @meta do
        input type="checkbox" name="meta" value="true"

Code-as-attributes doesn't work, e.g. src=static_path(@conn, "x.css")

This gives a "missing terminator" error:

link rel="stylesheet" href=static_path(@conn, "/css/app.css")

This works, though:

link rel="stylesheet" href="#{static_path(@conn, "/css/app.css")}"

The equivalent of the first example works in the Ruby version of Slim.

Maybe it could make sense to include a valid example of a dynamic attribute value in the README docs?

Blank lines in the template generate empty divs

When writing a template, leaving a blank line between two elements generates an empty <div> in the resulting HTML code. This only seems to happen if the blank line contains a certain number of whitespace characters, a common scenario when using editors that auto-indent. This doesn't seem to be the desired behavior (it does not happen in the Ruby implementation of Slim).

Example:

  p First Paragraph

  p Second Paragraph

(note: GitHub is stripping white spaces, but that blank line between the two p elements includes 2 white spaces, preserving indentation of said elements)

Generates:

<p>First Paragraph</p>
<div></div>
<p>Second Paragraph</p>

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.