pitr-ch / htmless Goto Github PK
View Code? Open in Web Editor NEWFast extensible html5 builder written in pure Ruby. Replaces templating engines without loosing speed bringing back the power of OOP.
License: MIT License
Fast extensible html5 builder written in pure Ruby. Replaces templating engines without loosing speed bringing back the power of OOP.
License: MIT License
Introduction: I'm actually trying to develop a framework for UI components for one of our complex rails projects. It's somewhat similar to Cells, but allows you to specify multiple blocks of markup code as parameters for such a component.
Capturing multiple blocks seems non-trivial and already opened a request in the haml repo: haml/haml#931
Now I'm testing many, many templating systems against my use case. (Spoiler: https://github.com/apotonick/erbse allows this but has an ugly syntax.)
Problem: yield
returns all content instead of just the nested one.
Example: (reduced to the problem)
require 'htmless'
class ComponentContext
def my_block
puts '... my_block captured:'
puts yield
puts '......................'
puts
nil
end
end
class MyBuilder < Htmless::Formatted
def ui_component
ctx = ComponentContext.new
content = yield ctx
puts '... ui_component captured:'
puts content
puts '..........................'
nil
end
end
html = MyBuilder.new.go_in do
body do
ui_component do |comp|
text 'component content'
comp.my_block do
text 'my_block content'
end
end
end
end.to_html
puts '---'
puts html
Output:
... my_block captured:
<body>component contentmy_block content
......................
... ui_component captured:
..........................
---
<body>component contentmy_block content
</body>
The output shows that my_block
not only captures the nested text my_block content
but everything else inside the Builder block.
The yield
further outside in ui_component
captures nothing of the markup.
@pitr-ch: Do you have a tip for me?
When I attempt to build a POST form, I cannot seem to specify a 'method' attribute by any means. Take for example:
form.attributes('method' => 'post') do
#stuff
end
This yields the following error:
undefined method `post' for class
I receive a similar error if I attempt to assign a type
to a button
element.
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.