Module: RtlcssWrapper

Defined in:
lib/rtlcss_wrapper.rb,
lib/rtlcss_wrapper/version.rb

Defined Under Namespace

Classes: FlipError

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.flip_css(orig_css) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rtlcss_wrapper.rb', line 9

def self.flip_css(orig_css)
  @context ||=
    begin
      context = MiniRacer::Context.new(timeout: 10_000)
      context.eval(
        File.read(File.expand_path("../dist/main.js", __dir__))
      )
      context.eval(<<~JS)
        function rtlcssWrapper(origCss) {
          return rtlcss.process(origCss);
        }
      JS
      context
    end
  @context.call("rtlcssWrapper", orig_css)
rescue MiniRacer::RuntimeError => e
  raise FlipError.new(cause: e)
end