Coder Social home page Coder Social logo

html2slim's People

Contributors

84a3580426e34a70a6a31fa4500b136c avatar bash0c7 avatar bobmazanec avatar crackedmind avatar damirsvrtan avatar ismaelga avatar joaomilho avatar justinaiken avatar minad avatar robbyoconnor avatar sanadan avatar tsukasaoishi 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

html2slim's Issues

DOCTYPE not properly converted

When i run

erb2slim application.html.erb application.html.slim

The doctype doesn't get converted properly. Instead of getting it properly such as:

doctype html

From the original .erb file

<!DOCTYPE html>

I actually get like this:

doctype

Fails while installing hpricot

What can I do? No idea -_-

$ bundle install

Installing hpricot 0.8.6 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: ~/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/hpricot-0.8.6/ext/fast_xs
~/.asdf/installs/ruby/3.3.0/bin/ruby extconf.rb
checking for stdio.h... yes
creating Makefile

current directory: ~/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/hpricot-0.8.6/ext/fast_xs
make DESTDIR\= sitearchdir\=./.gem.20240322-49101-wmq9bj sitelibdir\=./.gem.20240322-49101-wmq9bj clean

current directory: ~/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/hpricot-0.8.6/ext/fast_xs
make DESTDIR\= sitearchdir\=./.gem.20240322-49101-wmq9bj sitelibdir\=./.gem.20240322-49101-wmq9bj
compiling fast_xs.c
fast_xs.c:165:39: error: incompatible function pointer types passing 'VALUE (VALUE)' (aka 'unsigned long (unsigned long)') to parameter of type 'VALUE (*)(VALUE, VALUE)' (aka 'unsigned long (*)(unsigned long,
unsigned long)') [-Wincompatible-function-pointer-types]
        array = rb_rescue(unpack_utf8, self, unpack_uchar, self);
                                             ^~~~~~~~~~~~
~/.asdf/installs/ruby/3.3.0/include/ruby-3.3.0/ruby/internal/iterator.h:364:62: note: passing argument to parameter 'r_proc' here
VALUE rb_rescue(VALUE (*b_proc)(VALUE), VALUE data1, VALUE (*r_proc)(VALUE, VALUE), VALUE data2);
                                                             ^
1 error generated.
make: *** [fast_xs.o] Error 1

make failed, exit code 2

Gem files will remain installed in ~/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/hpricot-0.8.6 for inspection.
Results logged to ~/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/extensions/arm64-darwin-23/3.3.0/hpricot-0.8.6/gem_make.out

  ~/.asdf/installs/ruby/3.3.0/lib/ruby/3.3.0/rubygems/ext/builder.rb:125:in `run'
  ~/.asdf/installs/ruby/3.3.0/lib/ruby/3.3.0/rubygems/ext/builder.rb:51:in `block in make'
  ~/.asdf/installs/ruby/3.3.0/lib/ruby/3.3.0/rubygems/ext/builder.rb:43:in `each'
  ~/.asdf/installs/ruby/3.3.0/lib/ruby/3.3.0/rubygems/ext/builder.rb:43:in `make'
  ~/.asdf/installs/ruby/3.3.0/lib/ruby/3.3.0/rubygems/ext/ext_conf_builder.rb:42:in `build'
  ~/.asdf/installs/ruby/3.3.0/lib/ruby/3.3.0/rubygems/ext/builder.rb:193:in `build_extension'
  ~/.asdf/installs/ruby/3.3.0/lib/ruby/3.3.0/rubygems/ext/builder.rb:227:in `block in build_extensions'
  ~/.asdf/installs/ruby/3.3.0/lib/ruby/3.3.0/rubygems/ext/builder.rb:224:in `each'
  ~/.asdf/installs/ruby/3.3.0/lib/ruby/3.3.0/rubygems/ext/builder.rb:224:in `build_extensions'
  ~/.asdf/installs/ruby/3.3.0/lib/ruby/3.3.0/rubygems/installer.rb:852:in `build_extensions'
  ~/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.4.21/lib/bundler/rubygems_gem_installer.rb:72:in `build_extensions'
  ~/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.4.21/lib/bundler/rubygems_gem_installer.rb:28:in `install'
  ~/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.4.21/lib/bundler/source/rubygems.rb:203:in `install'
  ~/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.4.21/lib/bundler/installer/gem_installer.rb:54:in `install'
  ~/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.4.21/lib/bundler/installer/gem_installer.rb:16:in `install_from_spec'
  ~/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.4.21/lib/bundler/installer/parallel_installer.rb:130:in `do_install'
  ~/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.4.21/lib/bundler/installer/parallel_installer.rb:121:in `block in worker_pool'
  ~/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.4.21/lib/bundler/worker.rb:62:in `apply_func'
  ~/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.4.21/lib/bundler/worker.rb:57:in `block in process_queue'
  <internal:kernel>:187:in `loop'
  ~/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.4.21/lib/bundler/worker.rb:54:in `process_queue'
  ~/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bundler-2.4.21/lib/bundler/worker.rb:90:in `block (2 levels) in create_threads'

An error occurred while installing hpricot (0.8.6), and Bundler cannot continue.

In Gemfile:
  html2slim-ruby3 was resolved to 0.2.1, which depends on
    hpricot

Using

html2slim-ruby3

ruby -v
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]

rails -v
Rails 7.0.8.1

erb2slim doesn't properly convert multiline embedded ruby segments

Following code

<%
record = list_record if local_assigns[:list_record] # compat with render :partial :collection
columns ||= list_columns
row_id ||= element_row_id(:action => :list, :id => record.id)
tr_class = cycle("", "even-record") + ' ' + list_row_class(record)
action_links ||= active_scaffold_config.action_links.member
data_refresh ||= record.to_param
-%>

results in broken slim template code:

| <% record = list_record if local_assigns[:list_record] columns ||= list_columns row_id ||= element_row_id(:action => :list, :id => record.id) tr_class = cycle("", "even-record") + ' ' + list_row_class(record) action_links ||= active_scaffold_config.action_links.member data_refresh ||= record.to_param -%>

When I convert the meta part of the erb file, the result is a bit different

When I convert this,

<% set_meta_tags title: 'よくある質問' %>
<% set_meta_tags \
  description: 'クリーマクラフトパーティ(Creema craft party)のよくある質問はこちら。', \
  open_graph: { \
    description: 'クリーマクラフトパーティ(Creema craft party)のよくある質問はこちら。' \
  } %>

the result is this.

- set_meta_tags title: '出展ガイド'
- set_meta_tags \
-   description: 'クリーマクラフトパーティ(Creema craft party)のよくある質問はこちら。', \
-   open_graph: { \
-     description: 'クリーマクラフトパーティ(Creema craft party)のよくある質問はこちら。' \
-   }

I might want this.

- set_meta_tags title: 'フードの出展申込'
- set_meta_tags \
  description: 'クリーマクラフトパーティ(Creema craft party)のよくある質問はこちら。', \
  open_graph: { \
    description: 'クリーマクラフトパーティ(Creema craft party)のよくある質問はこちら。' \
  }

Thank you for your corparation!

Percent symbols in output?

I'm getting this:

   td.features-subhead &nbsp;
          td           %td           %td           %td         %tr
          th Phone/Teamviewer Support
          td           %td           %td           %td         %tr

from this:

<tr>
                <td class="features-subhead"> &nbsp; </td>
                <td> </td>
                <td> </td>
                <td> </td>
                <td> </td>
            </tr>
            <tr>
                <th>Phone/Teamviewer Support</th>
                <td> </td>
                <td> </td>
                <td> </td>
                <td> </td>
            </tr>

erb2slim doesn't handle ERB fragments within a tag definition properly

This:

<tr>
  <td class="firstcol <%= ' first_row_cell'.html_safe if params[:iphone] -%>">
    <%= f.label :login, "Email" %>
  </td>
  <td <%= 'class="first_row_cell"'.html_safe if params[:iphone] -%> >
    <%= f.text_field 'login', :value => base_login, :class => 'textfield', :placeholder => '[email protected]' %> 
  </td>
</tr>

Becomes:

tr
  |  <td class="firstcol 
  = ' first_row_cell'.html_safe if params[:iphone] -
  | "> 
  = f.label :login, "Email"
  |  <td 
  = 'class="first_row_cell"'.html_safe if params[:iphone] -
  |  > 
  = f.text_field 'login', :value => base_login, :class => 'textfield', :placeholder => '[email protected]'

undefined method `to_slim' for #<Hpricot::CData:0x00000001aef078> (NoMethodError)

I bought a theme from Themeforrest and tried to convert it using html2slim. I believe I encountered an error in the library and this is for your reference.

Is there a way this can be corrected. If you like I can give you the source code of the page that was attempted to be converted.

ziyan@ziyan-K55VD:~/Desktop/jdeen/layout/fullwidth$ html2slim index.html --trace
/home/ziyan/.rvm/gems/ruby-head/gems/html2slim-0.0.4/lib/html2slim/hpricot_monkeypatches.rb:51:in `block in to_slim': undefined method `to_slim' for #<Hpricot::CData:0x00000001aef078> (NoMethodError)
  from /home/ziyan/.rvm/gems/ruby-head/gems/html2slim-0.0.4/lib/html2slim/hpricot_monkeypatches.rb:51:in `map'
  from /home/ziyan/.rvm/gems/ruby-head/gems/html2slim-0.0.4/lib/html2slim/hpricot_monkeypatches.rb:51:in `to_slim'
  from /home/ziyan/.rvm/gems/ruby-head/gems/html2slim-0.0.4/lib/html2slim/hpricot_monkeypatches.rb:51:in `block in to_slim'
  from /home/ziyan/.rvm/gems/ruby-head/gems/html2slim-0.0.4/lib/html2slim/hpricot_monkeypatches.rb:51:in `map'
  from /home/ziyan/.rvm/gems/ruby-head/gems/html2slim-0.0.4/lib/html2slim/hpricot_monkeypatches.rb:51:in `to_slim'
  from /home/ziyan/.rvm/gems/ruby-head/gems/html2slim-0.0.4/lib/html2slim/hpricot_monkeypatches.rb:51:in `block in to_slim'
  from /home/ziyan/.rvm/gems/ruby-head/gems/html2slim-0.0.4/lib/html2slim/hpricot_monkeypatches.rb:51:in `map'
  from /home/ziyan/.rvm/gems/ruby-head/gems/html2slim-0.0.4/lib/html2slim/hpricot_monkeypatches.rb:51:in `to_slim'
  from /home/ziyan/.rvm/gems/ruby-head/gems/html2slim-0.0.4/lib/html2slim/hpricot_monkeypatches.rb:61:in `block in to_slim'
  from /home/ziyan/.rvm/gems/ruby-head/gems/html2slim-0.0.4/lib/html2slim/hpricot_monkeypatches.rb:61:in `map'
  from /home/ziyan/.rvm/gems/ruby-head/gems/html2slim-0.0.4/lib/html2slim/hpricot_monkeypatches.rb:61:in `to_slim'
  from /home/ziyan/.rvm/gems/ruby-head/gems/html2slim-0.0.4/lib/html2slim/converter.rb:11:in `initialize'
  from /home/ziyan/.rvm/gems/ruby-head/gems/html2slim-0.0.4/lib/html2slim.rb:7:in `new'
  from /home/ziyan/.rvm/gems/ruby-head/gems/html2slim-0.0.4/lib/html2slim.rb:7:in `convert!'
  from /home/ziyan/.rvm/gems/ruby-head/gems/html2slim-0.0.4/lib/html2slim/command.rb:93:in `_process'
  from /home/ziyan/.rvm/gems/ruby-head/gems/html2slim-0.0.4/lib/html2slim/command.rb:68:in `process!'
  from /home/ziyan/.rvm/gems/ruby-head/gems/html2slim-0.0.4/lib/html2slim/command.rb:15:in `run'
  from /home/ziyan/.rvm/gems/ruby-head/gems/html2slim-0.0.4/bin/html2slim:7:in `<top (required)>'
  from /home/ziyan/.rvm/gems/ruby-head/bin/html2slim:23:in `load'
  from /home/ziyan/.rvm/gems/ruby-head/bin/html2slim:23:in `<main>'
  from /home/ziyan/.rvm/gems/ruby-head/bin/ruby_noexec_wrapper:14:in `eval'
  from /home/ziyan/.rvm/gems/ruby-head/bin/ruby_noexec_wrapper:14:in `<main>'

Ruby API for conversion

I wish it would provide and document Ruby API so that Libraries(Rails Engines) could use them to let users have options to have the views in .slim format as well.

JRuby support

Hi,

using jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on Java HotSpot(TM) 64-Bit Server VM 1.7.0_10-b18 [darwin-x86_64] I'm getting LoadError: load error: fast_xs -- java.lang.RuntimeException: callback-style handles are no longer supported in JRuby

Seems to be caused by hpricot and recent JRuby changes.

erb2slim generates text commands wrong for trailing space.

This:

<p><font face="verdana" size="5" color="#555555"><strong>Dear <%= @name %>,</strong></font></p>

Becomes this (note trailing whitespace after 'Dear'):

p
  font[face="verdana" size="5" color="#555555"]
    strong
      | Dear 
      = @name
      | ,

When it SHOULD be:

p
  font[face="verdana" size="5" color="#555555"]
    strong
      ' Dear
      = @name
      | ,

hpricot crashes Ruby when input is empty

IO.popen("html2slim", 'r+') do |io|
  io.write ""
  io.close_write
  puts io.read
end

Crashes with:

/home/me/.rvm/gems/ruby-2.2.0/gems/hpricot-0.8.6/lib/hpricot/parse.rb:33: [BUG] Segmentation fault at 0x00000000000008
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0015 p:---- s:0071 e:000070 CFUNC  :scan
c:0014 p:0062 s:0066 e:000065 METHOD /home/me/.rvm/gems/ruby-2.2.0/gems/hpricot-0.8.6/lib/hpricot/parse.rb:33
c:0013 p:0026 s:0059 e:000058 METHOD /home/me/.rvm/gems/ruby-2.2.0/gems/hpricot-0.8.6/lib/hpricot/parse.rb:4
c:0012 p:0009 s:0053 e:000052 METHOD /home/me/.rvm/gems/ruby-2.2.0/gems/html2slim-0.1.1/lib/html2slim/converter.rb:11 [FINISH]
c:0

(etc.)

System:

hpricot (0.8.6)
html2slim (0.1.1)
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux]

Probably a hpricot issue, but hpricot is no longer maintained AFAIK.

erb2slim doesn't understand `elsif`

This:

<tr class="module_header">
  <td class="header_medium">
    <% if graph_values[:type] == "reviews" -%>
      Get Verified Reviews, Double Your Calls
    <% elsif graph_values[:type] == "tows" -%>
      Get Tows, Increase Monthly Revenue
    <% else -%>
      <% if graph_values[:your_shop][:percent] > graph_values[:top_shop][:percent] -%>
        Great Job Answering the Phone!
      <% else -%>
        Answer the Phone!
      <% end -%>
    <% end -%>
  </td>
</tr>

Becomes:

tr.module_header
  td.header_medium
    - if graph_values[:type] == "reviews"
      |  Get Verified Reviews, Double Your Calls 
    | <ruby code="elsif graph_values[:type] == "tows""> Get Tows, Increase Monthly Revenue 
    - else
      - if graph_values[:your_shop][:percent] > graph_values[:top_shop][:percent]
        |  Great Job Answering the Phone! 
      - else
        |  Answer the Phone! 

Invalid output when converting helper call with multi-line args and block

When converting passwords/edit.html.erb of the Clearance gem, the following snippet...

<%= form_for :password_reset,
      url: user_password_path(@user, token: @user.confirmation_token),
      html: { method: :put } do |form| %>
  <div class="password-field">
    <%= form.label :password %>
    <%= form.password_field :password %>
  </div>

  <div class="submit-field">
    <%= form.submit %>
  </div>
<% end %>

...Is converted to:

= form_for :password_reset,
-         url: user_password_path(@user, token: @user.confirmation_token),
-         html: { method: :put } do |form|
.password-field
  = form.label :password
  = form.password_field :password
.submit-field
  = form.submit

Note the incorrect field indentation, in addition to the incorrect argument formatting. Perhaps it is the same underlying issue though? (i.e. if the multi-line arguments were correctly recognized and formatted, then the block would be too?)

Bump version

The latest release on github and RubyGems.org in 0.2.0 on March 21, 2015. Since then, we have had an important Rails 3 compatibility update. Can we please bump the version to 0.2.1? Thank you.

Accept input from STDIN as well as a file

I would like to be able to do pbpaste | html2slim | pbcopy to process the contents of the clipboard.

Current usage:

Usage: html2slim INPUT_FILENAME_OR_DIRECTORY [OUTPUT_FILENAME_OR_DIRECTORY] [options]

Desired usage:

Usage: html2slim [INPUT_FILENAME_OR_DIRECTORY [OUTPUT_FILENAME_OR_DIRECTORY]] [options]

erb2slim should be changed similarly, of course.

Empty lines are removed

Hello, how can I keep empty lines from the original erb file so that the code don't appear all glued?

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.