inesita-rb / inesita

Frontend web application framework in Ruby using Opal.
https://inesita.fazibear.me/
MIT License
259 stars 15 forks source link

class_name builder #7

Closed fazibear closed 8 years ago

fazibear commented 8 years ago

Add simple helper method to build class names from hash with boolean values.

For example:

def render
  div class: build_class({'monday' => Time.now.monday?})
    text 'something'
  end
end
rubydesign commented 8 years ago

Here is what i wrote, creates div class/id and text in one sweep https://github.com/salama/salama-debugger/blob/master/lib/base/element_view.rb#L22

just to have a look @fazibear , if you want

fazibear commented 8 years ago

Sure, but I want to avoid construction like this:

def render
  div class: "#{'monday' unless Time.now.monday?}" do
    text 'monday'
  end
end

And your soulution don't resolve a problem. Anyway, there not much difference between class: "monday active" and `class: ".monday.active". Better solution is:

def render
  div.monday.active do
    text 'monday'
  end
end

And this is what I want to archive with opal-virtual-dom gem in a future.

fazibear commented 8 years ago

added class_names helper