Giter VIP home page Giter VIP logo

hamlit's Introduction

Hamlit

Gem Version test

Hamlit is a high performance Haml implementation.

Project status

Hamlit's implementation was copied to Haml 6. From Haml 6, you don't need to switch to Hamlit.

Both Haml 6 and Hamlit are still maintained by k0kubun. While you don't need to immediately deprecate Hamlit, Haml 6 has more maintainers and you'd better start a new project with Haml rather than Hamlit, given no performance difference between them.

Introduction

What is Hamlit?

Hamlit is another implementation of Haml. With some Hamlit's characteristics for performance, Hamlit is 1.94x times faster than the original Haml 5 in this benchmark, which is an HTML-escaped version of slim-template/slim's one for fairness.

Hamlit Benchmark

      hamlit v2.13.0:   247404.4 i/s
        erubi v1.9.0:   244356.4 i/s - 1.01x slower
         slim v4.1.0:   238254.3 i/s - 1.04x slower
         faml v0.8.1:   197293.2 i/s - 1.25x slower
         haml v5.2.0:   127834.4 i/s - 1.94x slower

Why is Hamlit fast?

Less string concatenation by design

As written in Hamlit's characteristics, Hamlit drops some not-so-important features which require works on runtime. With the optimized language design, we can reduce the string concatenation to build attributes.

Static analyzer

Hamlit analyzes Ruby expressions with Ripper and render it on compilation if the expression is static. And Hamlit can also compile string literal with string interpolation to reduce string allocation and concatenation on runtime.

C extension to build attributes

While Hamlit has static analyzer and static attributes are rendered on compilation, dynamic attributes must be rendered on runtime. So Hamlit optimizes rendering on runtime with C extension.

Usage

See REFERENCE.md for details.

Rails

Add this line to your application's Gemfile or just replace gem "haml" with gem "hamlit". It enables rendering by Hamlit for *.haml automatically.

gem 'hamlit'

If you want to use view generator, consider using hamlit-rails.

Sinatra

Replace gem "haml" with gem "hamlit" in Gemfile, and require "hamlit".

While Haml disables escape_html option by default, Hamlit enables it for security. If you want to disable it, please write:

set :haml, { escape_html: false }

Command line interface

You can see compiled code or rendering result with "hamlit" command.

$ gem install hamlit
$ hamlit --help
Commands:
  hamlit compile HAML    # Show compile result
  hamlit help [COMMAND]  # Describe available commands or one specific command
  hamlit parse HAML      # Show parse result
  hamlit render HAML     # Render haml template
  hamlit temple HAML     # Show temple intermediate expression

$ cat in.haml
- user_id = 123
%a{ href: "/users/#{user_id}" }

# Show compiled code
$ hamlit compile in.haml
_buf = [];  user_id = 123;
; _buf << ("<a href='/users/".freeze); _buf << (::Hamlit::Utils.escape_html((user_id))); _buf << ("'></a>\n".freeze); _buf = _buf.join

# Render html
$ hamlit render in.haml
<a href='/users/123'></a>

Contributing

Reporting an issue

Please report an issue with following information:

  • Full error backtrace
  • Haml template
  • Ruby version
  • Hamlit version
  • Rails/Sinatra version

Coding styles

Please follow the existing coding styles and do not send patches including cosmetic changes.

License

Copyright (c) 2015 Takashi Kokubun

hamlit's People

Contributors

aliismayilov avatar bsmith-optoro avatar connorshea avatar creasty avatar dlwr avatar eagletmt avatar gogainda avatar hfaulds avatar k0kubun avatar kamina-zzz avatar machu avatar mbrand12 avatar mibamur avatar michaelglass avatar myklclason avatar ntkme avatar pocke avatar pushcx avatar r7kamura avatar raphaeleidus avatar rstacruz avatar shmargum avatar southwolf avatar sunny avatar svyatov avatar swiknaba avatar timoschilling avatar tnir avatar wakematta avatar walf443 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

hamlit's Issues

[0.2.0] hamlit cli render template exception: undefined method options

gem install hamlit
echo '!!! 5' > foo.haml
hamlit render foo.haml
/Users/felix/.gem/ruby/2.2.0/gems/hamlit-0.2.0/lib/hamlit/engine.rb:29:in `block in create': undefined method `options' for Hamlit::HTML::Ugly:Class (NoMethodError)
    from /Users/felix/.gem/ruby/2.2.0/gems/hamlit-0.2.0/lib/hamlit/engine.rb:28:in `select'
    from /Users/felix/.gem/ruby/2.2.0/gems/hamlit-0.2.0/lib/hamlit/engine.rb:28:in `create'
    from /Users/felix/.gem/ruby/2.2.0/gems/hamlit-0.2.0/lib/hamlit/engine.rb:18:in `block in <class:Engine>'
    from /Users/felix/.gem/ruby/2.2.0/gems/temple-0.6.10/lib/temple/mixins/engine_dsl.rb:117:in `call'
    from /Users/felix/.gem/ruby/2.2.0/gems/temple-0.6.10/lib/temple/mixins/engine_dsl.rb:117:in `block in chain_proc_constructor'
    from /Users/felix/.gem/ruby/2.2.0/gems/temple-0.6.10/lib/temple/engine.rb:60:in `call'
    from /Users/felix/.gem/ruby/2.2.0/gems/temple-0.6.10/lib/temple/engine.rb:60:in `block in call_chain'
    from /Users/felix/.gem/ruby/2.2.0/gems/temple-0.6.10/lib/temple/engine.rb:60:in `map'
    from /Users/felix/.gem/ruby/2.2.0/gems/temple-0.6.10/lib/temple/engine.rb:60:in `call_chain'
    from /Users/felix/.gem/ruby/2.2.0/gems/temple-0.6.10/lib/temple/engine.rb:50:in `call'
    from /Users/felix/.gem/ruby/2.2.0/gems/hamlit-0.2.0/lib/hamlit/cli.rb:41:in `generate_code'
    from /Users/felix/.gem/ruby/2.2.0/gems/hamlit-0.2.0/lib/hamlit/cli.rb:10:in `render'
    from /Users/felix/.gem/ruby/2.2.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
    from /Users/felix/.gem/ruby/2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
    from /Users/felix/.gem/ruby/2.2.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
    from /Users/felix/.gem/ruby/2.2.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
    from /Users/felix/.gem/ruby/2.2.0/gems/hamlit-0.2.0/bin/hamlit:6:in `<top (required)>'
    from /Users/felix/.gem/ruby/2.2.0/bin/hamlit:23:in `load'
    from /Users/felix/.gem/ruby/2.2.0/bin/hamlit:23:in `<main>'
    from /Users/felix/.gem/ruby/2.2.0/bin/ruby_executable_hooks:15:in `eval'
    from /Users/felix/.gem/ruby/2.2.0/bin/ruby_executable_hooks:15:in `<main>'

Hyphenate aria attribute in addition to data attribute

Into file .haml
%nav{role: "navigation", :aria => { label: t('You are here', default: 'You are here:') } }
Parse with HAML(correct)
<nav aria-label="You are here:" role="navigation"></nav>
Parse with HAMLIT(incorrect)
<nav aria="{:label=>&quot;You are here:&quot;}" role="navigation"></nav>

Fix Ruby 1.9 compatibility

I discovered by trial that there seems to be an implicit ruby 2+ requirement for hamlit (first issue I hit was the use of ruby 2 keyword arguments).

I don't think that's necessarily a bad thing, but if this is intentional it might be good to declare the requirement in the readme and perhaps required_ruby_version in the gemspec.

If this is intentional, I'd be happy to do a P/R for it. Or if 1.9 compatibility is desired, delve into how big a deal this would be. But which is it?

Hamlit doesn't recognize windows style line endings

Here is my error:

Illegal nesting: content can't be both given on the same line as %html and nested within it.


!!!
%html{lang: 'en'}
  = render 'head'
  %body.sidebar-mini.skin-black-light.sidebar-collapse{class: "#{ controller.controller_name }" }
    .wrapper
      = render 'header'

Same code works just fine with haml.

I found the culprit - I develop on a windows machine ( using Sublime Text), and debian VM in a vagrant setup - to run my app. I have to use windows for dev - as I I need to use a bunch of windows apps for other stuff for my work. My production env is all Debian. Anyways my git is setup to checkout as window sstyle line endings and commit as Unix style. It was never an issue before - haml handles this just fine.

One solution is to change all the files I guess. But I wanted to bring this to your and anyone else running to this attention - as this is not an obvious error.

PS: On windows line end is usually CRLF ( Carrage Return LineFeed) , on unix it's just (LF)

'succeed', 'precede', and 'surround' are undefined

I'm trying to use succeed to make the full stops on my sentences not be bold, and not contain a space. This works in original haml.

Example code:

We need updated info from you on behalf of your organisation,
= succeed '.' do
  %strong= @organization.name
Use these forms below to attach updated info.

It is to look like this:

We need updated info from you on behalf of your organisation, John Doe Industries. Use these forms below to attach updated info.

Instead, I get

NoMethodError - undefined method `succeed'

TAB indent incompatible with haml

Haml

require 'haml'
Haml::Engine.new("%p\n\t%a").to_html()
=>  "<p>\n  <a></a>\n</p>\n"

Hamlit

require 'hamlit'
eval Hamlit::Engine.new.call("%p\n\t%a")
=> "<p></p>\n%a\n"

Less whitespace than HAML

The hamltit gem seems to render less whitespace than the haml Gem.

haml:

            <div class='menu-left'>
              <a class="btn btn-buzz-branded " href="/tickets"><i class="fa fa-inbox"></i>
              Inbox
              </a>
              <a class="btn btn-buzz-branded " href="/tickets/archive"><i class="fa fa-archive"></i>
              Archief
              </a>
              <a class="btn btn-buzz-branded " href="/tickets/new"><i class="fa fa-ticket"></i>
              Maak een nieuwe ticket
              </a>
            </div>

hamlit:

<div class='menu-left'>
<a class="btn btn-buzz-branded " href="/tickets"><i class="fa fa-inbox"></i>
Inbox
</a><a class="btn btn-buzz-branded " href="/tickets/archive"><i class="fa fa-archive"></i>
Archief
</a><a class="btn btn-buzz-branded " href="/tickets/new"><i class="fa fa-ticket"></i>
Maak een nieuwe ticket
</a></div>

Which has the result:

spaces

I consider the lack of whitespace to be better for a number of reasons, but unfortunately the application doesn't work well with this, and it's not quite "haml-compatible"...

`each` doesn't render

Context:
I use a hand build render way:

file = "foo.haml"
engine = Tilt[file] # => Hamlit::Template
template = engine.new(file, escape_html: false, escape_attrs: false)
template.render

Template:

%ul
  - (1..3).each do |i|
    %li

Result:

<ul></ul>

Cannot use empty conditional statements

For example

- if object.new_record?
  New
- else

Will raise
SyntaxError - syntax error, unexpected keyword_ensure, expecting keyword_end

In HAML, that would be kosher. Not a big deal... just thought you should know for documenting differences.

Object reference not supported?

I was wondering if object reference with [] is not supported in hamlit.

I have something along the lines of:

%div[article]
  'foo'

where article is a model object, and it gives me the error Illegal nesting: content can't be both given on the same line as %div and nested within it.. I'm fairly new to haml so this issue might be trivial, but I was just curious since using gem 'haml' works fine without any error.

Missing newline when using link_to with blocks

When using a rails helper like link_to, there is a difference in output when using a block or not.
For example:

%div
  %a{href: '#'} This is a link
  %a{href: '#'} This is a link
%div
  %a{href: '#'}
    This is a link
  %a{href: '#'}
    This is a link
%div
  = link_to 'This is a link', '#'
  = link_to 'This is a link', '#'
%div
  = link_to '#' do
    This is a link
  = link_to '#' do
    This is a link

Result:

<div>
<a href="#">This is a link</a>
<a href="#">This is a link</a>
</div>
<div>
<a href="#">
This is a link
</a>
<a href="#">
This is a link
</a>
</div>
<div>
<a href="#">This is a link</a>
<a href="#">This is a link</a>
</div>
<div>
<a href="#">This is a link
</a><a href="#">This is a link
</a></div>

All variations produce newlines between the <a>'s, except for the last link_to with block.
This results in the same missing margins as seen in this issue.

Maybe this is caused by the 'ugly-only' support, which i'm ok with. But having different results caused by using a block or not seems confusing.

Don't render falsy attributes

%input{checked: false}
%input{checked: nil}

Expected

<input>
<input>

Actual

<input checked='false'>
<input checked=''>

Counterintuitive illegal nesting issue

Stumbled upon another error:

ActionView::Template::Error (Illegal nesting: nesting within plain text is illegal.):
    1: %ul.nav.nav-list
    2:
    3:   %li
    4:     = link_to vendor_path(@vendor), class: 'home' do
    5:       %i.fa.fa-home
  app/views/vendors/_menu.haml:2:in `_app_views_vendors__menu_haml__2535218153765224401_70111489365600'
  app/views/layouts/portal.haml:35:in `_app_views_layouts_portal_haml__3700871400531794207_70111685449560'

Any ideas if I should fix my code (tried couple of attempts, unsuccessful), or if it's a hamlit issue?

HTML entities no longer parsed

This
&times;

used to correctly render the html entity, now it doesn't. "&times;" is outputted to the screen.

Applies to all entities.

Bug of parse_old_attributes

Hi, thanks for your great work, I'm seriously considering replacing haml-rails with hamlit in my project, but I'm in trouble with a bug of parse_old_attributes.

Reproducible ways

Accepted and correct

parse_old_attributes '{ data: { value: "#{I18n.t "foo"}"}}'
#=> {"data"=>{"value"=>"\"\#{I18n.t \"foo\"}\""}}

Accepted but incorrect

parse_old_attributes '{ value: "#{I18n.t "foo", count: 1}" }'
#=> {"value"=>"\"\#{I18n.t \"foo\", count: 1", "{"=>"\""}

parse_old_attributes '{ data: { value: "#{I18n.t "foo", count: 1}" } }'
#=> {"data"=>{"value"=>"\"\#{I18n.t \"foo\", count: 1", "{"=>"\""}}

Rejected

Watch braces at the end of buffer

parse_old_attributes '{ data: { value: "#{I18n.t "foo", count: 1}"}}'
# raises #<Hamlit::SyntaxError: Hamlit::SyntaxError>

Cannot render multibyte char attribute

Hello. I tried hamlit in my project written in Japanese. But hamlit could not render multibyte character attribute.

Source

%img{ alt: 'ใ“ใ‚“ใซใกใฏ' }

Expected

<img alt='ใ“ใ‚“ใซใกใฏ'>

Actual

$ gem list | grep hamlit
hamlit (0.3.2)
$ ruby --version
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]
$ hamlit render sample.haml
/Users/machu/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/hamlit-0.3.2/lib/hamlit/cli.rb:11:in `eval': (eval):1: syntax error, unexpected tSTRING_DEND, expecting ')' (SyntaxError)
...); _buf << ('ใ“ใ‚“ใซใกใฏ' }); _buf << ("'>\n".freeze);
...                               ^
(eval):2: syntax error, unexpected end-of-input, expecting ')'
; _buf = _buf.join
                  ^
        from /Users/machu/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/hamlit-0.3.2/lib/hamlit/cli.rb:11:in `render'
        from /Users/machu/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
        from /Users/machu/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
        from /Users/machu/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
        from /Users/machu/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
        from /Users/machu/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/hamlit-0.3.2/bin/hamlit:6:in `<top (required)>'
        from /Users/machu/.rbenv/versions/2.2.0/bin/hamlit:23:in `load'
        from /Users/machu/.rbenv/versions/2.2.0/bin/hamlit:23:in `<main>'

FYI

$ hamlit compile sample.haml
_buf = []; _buf << ("<img alt='".freeze); _buf << ('ใ“ใ‚“ใซใกใฏ' }); _buf << ("'>\n".freeze);
; _buf = _buf.join

The "plain" filter is escaped when it shouldn't be

I'm trying to use the :plain filter to output JSON-LD to a page.

Hamlit 1.7.2 outputs correctly but v2.0.1+ escapes the quotes. According to the haml spec this shouldn't happen. If I want to escape the script code I would use the :escaped filter.

Is this a bug or is there something else I should be doing?

Example:

%script{ type: 'application/ld+json' }
  :plain
    {
      "@context": "http://schema.org",
      "@type": "WebSite",
      "name": "My Website",
      "url": "#{root_url}"
    }

is output as:

<script type='application/ld+json'>
{
  &quot;@context&quot;: &quot;http://schema.org&quot;,
  &quot;@type&quot;: &quot;WebSite&quot;,
  &quot;name&quot;: &quot;My Website&quot;,
  &quot;url&quot;: &quot;http://example.com/&quot;
}
</script>

Force usage of hamlit in Rails when haml gem is also bundled?

I'm in the situation where I am trying to use hamlit in my Rails application, but unfortunately I have a Gemfile dependency on rails_admin, which has a dependency on the original haml gem. With both haml and hamlit bundled, it seems like the original haml gem wins out. Is there a way that I can force Rails to use hamlit and not haml when rendering templates?

Thanks for the help.

Indentation is only allowed with hard tabs or 2 spaces

Haml allows N-spaces indentation. Is it intentional?
(Also, the exception seems to be telling a wrong information about spaces.)

Input

%div
    %div

Expected

<div>
<div></div>
</div>

Actual

inconsistent indentation: 2 spaces used for indentation, but the rest of the document was indented using 4 spaces (Hamlit::SyntaxError)

Hamlit 2.0.1 parsing error

On version 2.0.1 I get this error:

ActionView::Template::Error (Unbalanced brackets.):
  %span#guest_activity_result_link
    = render 'link'
  = form_tag guest_activity_results_path(params[:type_id],params[:view], guest_business_unit_id: params[:guest_business_unit_id], f
rom: params[:from], to: params[:to], done: params[:done], format: :js), method: :get, class: 'form-activities-result form-inline js-form-guest-activity-results', remote: true do
    = hidden_field_tag :from, params[:from], id: 'params_from'
  app/views/guest_activity_results/index.html.haml:1:in `_app_views_guest_activity_results_index_html_haml___4289206552145283933_6985009
8929540'

on this haml file:

%span#guest_activity_result_link
  = render 'link'
= form_tag guest_activity_results_path(params[:type_id],params[:view], guest_business_unit_id: params[:guest_business_unit_id], from: params[:from], to: params[:to], done: params[:done], format: :js), method: :get, class: 'form-activities-result form-inline js-form-guest-activity-results', remote: true do
  = hidden_field_tag :from, params[:from], id: 'params_from'
  = hidden_field_tag :to, params[:to], id: 'params_to'
  .row-fluid
    - if params[:view] == 'daily'
      %span#percentuale
        .span2.label_menu
          = t('fatte')
          %span#done
          = t('di')
          %span#tot
        .span3
          #progress-bar.progress
            .bar.bar-success#percentage-done{ data: { tot: 0 } }
            .bar.bar-warning#percentage-partial-done{ data: { tot: 0 } }
            .bar.bar-danger#percentage-not-done{ data: { tot: 0 } }
    .pull-right
      %span.mychzn
        = select_tag :business_unit_id, grouped_options_for_select(sel_units, params[:business_unit_id]), include_blank: true, data: { placeholder: t('select_unit_placeholder') }, multiple: true, class: 'chzn-select input-xlarge', id: 'select_business_unit_id'
      %span.mychzn.activities_config_result
        - if params[:type_id] != 'general'
          = select_tag :activities_config_id, options_for_select(sel_activities_configs(current_bu,nil,false,false,@area,params[:type_id], Date.parse(params[:from] || params[:to] || Date.current.to_s)), params[:activities_config_id]), include_blank: true, data: { placeholder: t('select_activity_placeholder') }, multiple: true, class: 'chzn-select input-xlarge', id: 'select_activities_config_id'
        - else
          = select_tag :activities_config_id, grouped_options_for_select(sel_activities_configs(current_bu,@activity.id,false,false,nil,params[:type_id], Date.parse(params[:from] || params[:to] || Date.current.to_s)), params[:activities_config_id]), include_blank: true, multiple: true, data: { placeholder: t('select_activity_placeholder') }, class: 'chzn-select input-xlarge', id: 'select_activities_config_id'
      =# image_submit_tag "icone/#{get_theme}/search.png", title: t('command.find'), class: 'js-tooltip'
      = button_tag t('command.find'), class: 'btn btn-success', disabled: true, id: 'button_search_guest_activity'
  .row-fluid
    .pull-right
      #check_done.form-inline
- if params[:view] == 'daily'
  %span#render-day-link
    = render 'day_link'

.row-fluid#list-activity-plan.content-ajax
  - if params[:view] == 'daily'
    %table#jqgrid-guest-activities{ data: {
     guest_info_path: summary_guest_business_unit_path(I18n.locale, 0, popup: true, all_expanded: true),
     type: params[:type_id],
     create: guest_activities_path(format: :json),
     label: { motivation: %w(socialization riabilitation).include?(params[:type_id]) ? t('giudizio') : t('motivation'), autonomia: t('autonomia'), partecipazione: t('partecipazione') },
     general: %w(socialization riabilitation).include?(params[:type_id]).to_s,
     checkall: (check_all_guest_activity_results_path(params[:type_id], params[:view], from: params[:from], to: params[:to], format: :json) if get_parameters.fetch(:guest_activity_results, {}).fetch(:execute_all, false)),
     invio: t('send_to_diary'),
     delete: t('command.destroy'),
     confirm: t('command.confirm'),
     motivation: select_for_jqgrid(@activities_configs, :motivation),
     partecipazione: select_for_jqgrid(@activities_configs, :partecipazione),
     autonomia: select_for_jqgrid(@activities_configs, :autonomia),
     date: Date.current.to_formatted_s(:db),
     edit: guest_activities_path,
     user: current_user.id,
     index: guest_activity_results_path(params[:type_id], params[:view], business_unit_id: params[:business_unit_id], activities_config_id: params[:activities_config_id], from: params[:from], to: params[:to], done: params[:done], format: :json) }
     }
    #jqgrid-guest-activities-pager
  - else
    = render('handsontable_div')
#modal-search.modal.hide.fade{"aria-hidden" => "true", "aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1"}
  .modal-header
    %button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"}
      %i.icon-close
    %h3#myModalLabel.title
      = image_tag "icone/cerca_55x55.png"
      = t('command.find')
  = form_tag guest_activity_results_path(params[:type_id],params[:view],done: params[:done],format: :js),method: :get,remote: true,class: 'form-horizontal form-activities-result' do
    .modal-body
      - if params[:view] == 'daily' || params[:view] == 'weekly' || params[:view] == 'last_week'
        .control-group
          = label_tag :from,t('dal'), :class => 'control-label'
          .controls
            = text_field_tag :from,local_date(Date.current),:class => 'date_from_max input-small'
        - if params[:view] == 'daily'
          .control-group
            = label_tag :to,t('al') , :class => 'control-label'
            .controls
              = text_field_tag :to,local_date(Date.current),:class => 'date_to_max input-small'
      - else
        .control-group
          = label_tag :from,t('month'), :class => 'control-label'
          .controls.mychzn
            = select_month(Date.today,{},{:class => 'chzn-select',:name => :month,:id => :from})
    .modal-footer
      = submit_tag t('command.find'), class: 'btn btn-success', data: { disable_with: t('command.searching') }
      %button.btn{"aria-hidden" => "true", "data-dismiss" => "modal"}= t('command.close')
#modal-modify.modal.hide.fade.big_modal{"aria-hidden" => "true", "aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1"}
  .modal-header
    %button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"}
      %i.icon-close
    %h3#myModalLabel.title
      = image_tag "icone/valutazioni_55x51.png"
      = t('activity_label')
  %span#spam-modal-modify
#add-plan.modal.big_modal.hide.fade{"aria-hidden" => "true", "aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1"}
  .modal-header
    %button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"}
      %i.icon-close
    %h3#myModalLabel.title
      = image_tag "icone/valutazioni_55x51.png"
      = t('registra_attivita')
  %span#form
#modal-process.modal.hide.fade{"aria-hidden" => "true", "aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1"}
  .modal-header
    %button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"}
      %i.icon-close
    %h4#myModalLabel
      = image_tag "icone/valutazioni_55x51.png"
      = "#{t('protocol')} "
      %span#activity
      = t('di')
      %span#guest
  %span#process
#modal_plan_activity.modal.hide.fade{"aria-hidden" => "true", "aria-labelledby" => "myModalLabel", "data-model" => "", :role => "dialog", :tabindex => "-1"}
  .modal-header
    %button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"}
      %i.icon-close
    %h3#modal_plan_activity_header.title
      = image_tag "icone/attivita_quotidiane_55x51.png"
      = t('activity_planning')
      %span#act
      = t('di')
      %span#guest
  #form
    #modal_plan_activity_body.modal-body
    .modal-footer
      %button.btn{"aria-hidden" => "true", "data-dismiss" => "modal"}= t('command.close')
= bootstrap_modal_div id: 'guest_informations', class: 'big_modal', title_key: 'guest_informations'

On version 1.7.2 there were no problems.

Support the haml -r flag

I want to try converting our codebase from haml to hamlit but we're currently using the pattern haml -r ./haml-includes.rb ... to include common variable definitions.

Syntax error where haml doesn't complain.

Hamlit::SyntaxError around this line:

= render partial: "application_body", locals: {webpro: webpro, application: @application}

        #tab-application.tab-pane{:role => "tabpanel", :class => has_messages ? "" : "active"}
          - if @application.can_rummage?
            = render partial: "application_body", locals: {webpro: webpro, application: @application}
          - else
            .field
              %h4= t("job_applications.professional_background")

please declare ruby version dependency

always installing latest and then failing ... would be nice to see a real error and be able to check which version requires which ruby version on rubygems

Block-support and Capture

Hey Takashi, first of all, thanks for that great gem. We can't wait to integrate it with Cells to have lightning-fast HAML rendering! ๐Ÿป ๐Ÿ’ฅ ๐Ÿป

I have a bit of trouble with blocks and capturing, though. Here's a sample Hamlit template. Note that this is unrelated to Rails!

%New

= form model do |f|
  ID
  = f.input :id

Really simple, just a form invocation with a block. Internally, I want to capture that block. However, here's the compiled template.

_buf = []; _buf << ("<New></New>\n".freeze); 
; 
; _hamlit_compiler0 = form model do |f|; 
; _buf << ("ID\n".freeze); 
; _buf << (f.input :id); _buf << ("\n".freeze); end; _buf << (_hamlit_compiler0); 
; _buf = _buf.join

As you can see, the result of the form method is assigned to _hamlit_compiler0 (good!). The content of the block, whatsoever, is assigned to the global _buf (bad!!!). How am I supposed to change _buf to another variable to capture that? Is there any trick I'm missing?

In Slim, this works by assigning each block to a separate variable:

@output_buffer = [];
 @output_buffer << (\"<New></New>\".freeze);
 \n;
 \n;
 _slim_controls1 = form model do |f|;
 _slim_controls2 = '';
 \n;
 _slim_controls2 << (\"ID\".freeze);
 \n;
 _slim_controls2 << ((f.input :id).to_s);
 \n;
 _slim_controls2;
 end;

Here, I don't have to do anything to capture the block content. Am I doing anything wrong with Hamlit? Can you help me?

Hamlit 2.2.0 + Rails5Beta1 + Ruby 2.2 64bit

I can't install this gem on Ruby 2.2 64bit(windows) with Rails 5 and Hamlit 2.2.0

The error on bunde install is:

Installing hamlit 2.2.0 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory: C:/Ruby22-64bit/lib/ruby/gems/2.2.0/gems/hamlit-2.2.0/ext/hamlit

C:/Ruby22-64bit/bin/ruby.exe -r ./siteconf20160131-6508-1gturbz.rb extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.

Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=C:/Ruby22-64bit/bin/$(RUBY_BASE_NAME)
C:/Ruby22-64bit/lib/ruby/2.2.0/fileutils.rb:357:in symlink': symlink() function is unimplemented on this machine (NotImplementedError) from C:/Ruby22-64bit/lib/ruby/2.2.0/fileutils.rb:357:inblock in ln_s'
from C:/Ruby22-64bit/lib/ruby/2.2.0/fileutils.rb:1586:in fu_each_src_dest0' from C:/Ruby22-64bit/lib/ruby/2.2.0/fileutils.rb:355:inln_s'
from extconf.rb:10:in block in <main>' from extconf.rb:8:ineach'
from extconf.rb:8:in `

'

extconf failed, exit code 1

Gem files will remain installed in C:/Ruby22-64bit/lib/ruby/gems/2.2.0/gems/hamlit-2.2.0 for inspection.
Results logged to C:/Ruby22-64bit/lib/ruby/gems/2.2.0/extensions/x64-mingw32/2.2.0/hamlit-2.2.0/gem_make.out

Any solution?
Thanks!

Object reference error

While trying to quickly migrate our production app to hamlit, I've spotted some tests failing with errors similar to this:

ActionView::Template::Error (Illegal nesting: content can't be both given on the same line as %tr and nested within it.):
    1: - decorator =  ReturnDecorator.new(self, return_record)
    2: %tr[return_record]
    3:   %td#auth_id= return_record.auth_id
    4:   %td#state= decorator.state
    5:   %td#customer
    6:     - if current_user.vendor?
  app/views/returns/_return_record.haml:3:in `_app_views_returns__return_record_haml__1226260404814508471_70111479409320'

It looks like there's no [object_reference] method in hamlit?

How do I port the function to make and hamlit aware of it?

Hamlit and cache blocks

Hi,

I am trying to switch from haml to hamlit and I am having some issues with the following type of code:

  - cache "test" do
    %h2 Test

While the code above was working with haml it is not being rendered with hamlit. I did not find anything in the docs regarding how this should be handled.

Should I change the code? How? I noticed that hamlit-block exists but I could not understand how it is supposed to affect the code above.

Thanks for the work with hamlit. Looks promising!

Comments cannot be included into script

[IMO] It could be ok even if this feature isn't supported.

= 'string' # comment

Expected

string

Actual

/home/eagletmt/.ghq/github.com/k0kubun/hamlit/lib/hamlit/cli.rb:11:in `eval': (eval):2: syntax error, unexpected end-of-input, expecting ')' (SyntaxError)
; _buf << ("\n".freeze); _buf = _buf.join
                                         ^
        from /home/eagletmt/.ghq/github.com/k0kubun/hamlit/lib/hamlit/cli.rb:11:in `render'
        from /home/eagletmt/gems/ruby/2.3.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
        from /home/eagletmt/gems/ruby/2.3.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
        from /home/eagletmt/gems/ruby/2.3.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
        from /home/eagletmt/gems/ruby/2.3.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
        from /home/eagletmt/.ghq/github.com/k0kubun/hamlit/bin/hamlit:6:in `<top (required)>'
        from /home/eagletmt/gems/ruby/2.3.0/bin/hamlit:23:in `load'
        from /home/eagletmt/gems/ruby/2.3.0/bin/hamlit:23:in `<main>'

FYI

% bundle exec hamlit compile in.haml
_buf = []; _buf << (('string' # comment).to_s); 
; _buf << ("\n".freeze); _buf = _buf.join

remove_filter?

HAML has a remove_filter method. I noticed there's a test for Hamlit's remove_filter method here. but I can't get it to work when adding the following to hamlit.rb:

Hamlit::Filters.remove_filter "Coffee"

This is the error I get: undefined method 'remove_filter' for Hamlit::Filters:Class (NoMethodError)

Any ideas?

Case statement does'nt work

I saw that you have few tests that tests case statement. But it doen't give you full coverage.

- test = 1
= case test
  - when 1 then 1
  - when 2 then 2
  - else 0

It raise error
"syntax error, unexpected keyword_ensure, expecting end-of-input"

Than I understand that your case syntax little bit different.

- test = 1
= case test
- when 1 then 1
- when 2 then 2
- else 0

But it still raise error
"syntax error, unexpected ')', expecting keyword_when ...Utils.escape_html_safe((case 1))).to_s)); "
So final code that works

- test = 1
- case test
- when 1
  1
- when 2 
  2
- else 0

or we can rewrite it to

- test = 1
- if test == 1
  1
- elsif test == 2
  2
- else 0

But It doesn't looks good for me. And I doesn't like that there is difference in syntax between haml and hamlit.

[2.4.0] Symlink error on Windows x64

current directory: C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/hamlit-2.4.0/ext/hamlit
C:/Ruby23-x64/bin/ruby.exe -r ./siteconf20160603-6444-1o9hsk7.rb extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.

Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=C:/Ruby23-x64/bin/$(RUBY_BASE_NAME)
C:/Ruby23-x64/lib/ruby/2.3.0/fileutils.rb:358:in symlink': Permission denied @ rb_file_s_symlink - (C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/hamlit-2.4.0/ext/hamlit/houdini/buffer.c, buffer.c) (Errno::EACCES) from C:/Ruby23-x64/lib/ruby/2.3.0/fileutils.rb:358:inblock in ln_s'
from C:/Ruby23-x64/lib/ruby/2.3.0/fileutils.rb:1587:in fu_each_src_dest0' from C:/Ruby23-x64/lib/ruby/2.3.0/fileutils.rb:356:inln_s'
from extconf.rb:11:in block in <main>' from extconf.rb:8:ineach'
from extconf.rb:8:in `

'

extconf failed, exit code 1

Sinatra does not work?

  • Exchanged hamlit for haml in my bundle
  • pushed to Heroku, refreshed. Saw RAW html where HTML should have been rendered?

eg route:

 get 'fizzy' do
      haml  :junk, layout: :layout_internal
 end

So why does this fail? My views/ contains a file named junk.haml that contains perfect HAML

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.