Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No, I actually hate instance_eval, but it can be done better #5

Open
czaks opened this issue Mar 31, 2015 · 3 comments
Open

No, I actually hate instance_eval, but it can be done better #5

czaks opened this issue Mar 31, 2015 · 3 comments

Comments

@czaks
Copy link

czaks commented Mar 31, 2015

How about supporting a theoretical code like this?

class Page
  include Paggio::HTML

  def initialize(title, content)
    @title   = title
    @content = content
  end

  def to_html
    html do
      head do
        title @title
      end

      body do
        @content
      end
    end
  end
end

puts Page.new("foo", "bar").to_html

What I done here, is include a mixin, which moves all HTML tag methods into the class context. Sure, we would need to be extra careful not to override those. This way, it would encourage object-oriented programming with no problems related to instance_eval use.

This is how https://github.com/erector/erector works, afaik.

@meh
Copy link
Member

meh commented Mar 31, 2015

instance_eval is optional, if you pass a parameter to the first block it will call it instead of using instance_eval.

a = "hue"

Paggio.html do |_|
  _.div a
end

The above will work.

@meh meh closed this as completed Mar 31, 2015
@czaks
Copy link
Author

czaks commented Apr 1, 2015

I know, I proposed an alternative syntax, which is cleaner and doesn't need
instance_eval at all.

I am recently searching for a robust markaby-like template library that
would work both in opal and ruby for my bigger project. Your code seems
slick and clean and is already used by opal-browser, that's why I am trying
to start talk here.
31 mar 2015 19:04 "meh." notifications@github.com napisał(a):

Closed #5 #5.


Reply to this email directly or view it on GitHub
#5 (comment).

@meh meh reopened this Apr 1, 2015
@meh
Copy link
Member

meh commented Apr 1, 2015

The problem is that there are no HTML methods, it's all method_missing based, which would end up making the class very hard to debug if the mixin defined a method_missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants