slim-template / html2slim Goto Github PK
View Code? Open in Web Editor NEWconvert html files to slim
convert html files to slim
https://github.com/fredwu/haml2slim
Would be nice to have a unified tool doing html/haml/erb conversions.
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
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
ruby -v
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
rails -v
Rails 7.0.8.1
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 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!
erb2slim is raising an error because
File.exists?
was removed in ruby 3.2 in favor of File.exist?
I updated the Devise wiki on converting the generated views to slim, as it was previously written to convert to haml and then slim. The instructions now tell users to use erb2slim
to convert directly. There's a dozen or so files that are converted, and they're all fine except for one: app/views/devise/shared/_links.slim
. That file looks like this.
The original erb file can be found here.
html2slim.rb:23:in `to_slim': invalid byte sequence in GBK (ArgumentError)
I'm getting this:
td.features-subhead
td %td %td %td %tr
th Phone/Teamviewer Support
td %td %td %td %tr
from this:
<tr>
<td class="features-subhead"> </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>
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]'
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>'
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.
Hi!
How to avoid attributes list wrapping with [ ]
(or any other delimiters)?
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.
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
| ,
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.
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!
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?)
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.
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.
Hi ,
do you want to transfer this repo to the slim-template organization? I will give you access there if you want.
Daniel (@minad, for the Slim team)
Rename to erb2slim and add erb support.
Yeah, I know you are old school ;)
On the following line there is a stray B
that prevents anything from getting converted. Once I removed it, it worked fine. FYI
https://github.com/slim-template/html2slim/blob/master/lib/html2slim/converter.rb#L4
Thanks for making this tool BTW, very handy!
Hello, how can I keep empty lines from the original erb file so that the code don't appear all glued?
Should have an option for wrap-width, and allow wrapping at that cutoff.
Running erb2slim on an html.erb file:
If there is a space before the class name, it adds in an extra dot class selector, which results in an error.
<div class=" my-class">
</div>
..my-class
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.