Sha256: c14d0abfc892e7818842ae394929adb66b03b6dcd57ab373df89cfdf06530912

Contents?: true

Size: 908 Bytes

Versions: 33

Compression:

Stored size: 908 Bytes

Contents

format :html do
  # Classy home for classes and klasses
  def class_up klass, classier, force=false
    key = klass.to_s
    return if !force && class_list[key]
    class_list[key] = [class_list[key], classier.to_s].compact.join(" ")
  end

  def class_down klass, classier
    class_list.delete klass if class_list[klass] == classier
  end

  def with_class_up klass, classier, force=false
    class_up klass, classier, force
    yield
  ensure
    class_down klass, classier
  end

  # don't use in the given block the additional class that
  # was added to `klass`
  def without_upped_class klass
    tmp_class = class_list.delete klass
    result = yield tmp_class
    class_list[klass] = tmp_class
    result
  end

  def class_list
    @class_list ||= {}
  end

  def classy *classes
    classes = Array.wrap(classes).flatten
    [classes, class_list[classes.first]].flatten.compact.join " "
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
card-1.96.8 mod/standard/set/all/rich_html/classy.rb
card-1.96.7 mod/standard/set/all/rich_html/classy.rb
card-1.96.6 mod/standard/set/all/rich_html/classy.rb
card-1.96.5 mod/standard/set/all/rich_html/classy.rb
card-1.96.4 mod/standard/set/all/rich_html/classy.rb
card-1.96.3 mod/standard/set/all/rich_html/classy.rb
card-1.96.2 mod/standard/set/all/rich_html/classy.rb
card-1.96.1 mod/standard/set/all/rich_html/classy.rb
card-1.96.0 mod/standard/set/all/rich_html/classy.rb
card-1.95.3 mod/standard/set/all/rich_html/classy.rb
card-1.95.2 mod/standard/set/all/rich_html/classy.rb
card-1.95.1 mod/standard/set/all/rich_html/classy.rb
card-1.95.0 mod/standard/set/all/rich_html/classy.rb
card-1.94.1 mod/standard/set/all/rich_html/classy.rb
card-1.94.0 mod/standard/set/all/rich_html/classy.rb
card-1.93.13 mod/standard/set/all/rich_html/classy.rb
card-1.93.12 mod/standard/set/all/rich_html/classy.rb
card-1.93.11 mod/standard/set/all/rich_html/classy.rb
card-1.93.10 mod/standard/set/all/rich_html/classy.rb
card-1.93.9 mod/standard/set/all/rich_html/classy.rb