Giter Site home page Giter Site logo

pitr-ch / htmless Goto Github PK

View Code? Open in Web Editor NEW
17.0 17.0 4.0 556 KB

Fast extensible html5 builder written in pure Ruby. Replaces templating engines without loosing speed bringing back the power of OOP.

License: MIT License

Ruby 16.76% HTML 82.44% JavaScript 0.81%

htmless's People

Contributors

corprew avatar dependabot[bot] avatar pitr-ch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

htmless's Issues

yield just nested elements

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?

"undefined method `post' for class" when defining form element

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.

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.