Sha256: dad25aaf3769433b64f3a52166cd77fce4f174faed57ed5f32eef75a1bb86504

Contents?: true

Size: 916 Bytes

Versions: 1

Compression:

Stored size: 916 Bytes

Contents

# frozen_string_literal: true

class Atome
  def html(obj = nil)
    if obj
      @html = obj
    else
      @html
    end
  end

  def to_px(particle)
    ruby_wasm_code = <<-JS
  var div = document.getElementById("#{@id}");
  var style = window.getComputedStyle(div);
  var original_value = style.getPropertyValue("#{particle}");
  var parsed_value = parseInt(original_value);
  return parsed_value;
    JS
    JS.eval(ruby_wasm_code).to_f
  end

  def to_percent(property)
    parent = grab(attach)
    parent_width = parent.to_px(:width)
    parent_height = parent.to_px(:height)
    property_needed_px = to_px(property)
    case property
    when :width, :left
      "#{(property_needed_px / parent_width.to_f) * 100}%"
    when :height, :top
      "#{(property_needed_px / parent_height.to_f) * 100}%"
    else
      raise ArgumentError # unsupported property use left , top, width an height
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
atome-0.5.7.4.3 lib/renderers/html/atome_html.rb