Sha256: 18d68d8409876714fcb8c0d7ef4dcf589197bc8acc554e167b67d00f0556336b

Contents?: true

Size: 1017 Bytes

Versions: 5

Compression:

Stored size: 1017 Bytes

Contents

module VueCK
    class SFC
        attr_accessor :xml, :script, :style, :template, :name

        def initialize(component_file)
            @path = component_file
            @xml  = component_xml
            @name = @xml.attribute(ATTRIBUTES[:name]).value
        end

        def render_component
            reduce_whitespace "var #{@name} = Vue.component('#{@name}',{template:'#{render(:template)}', #{render(:script)}});"
        end

        def render_style
            style = Element.new(@xml, :style)
            return "" if style.empty?
            CSSminify.compress reduce_whitespace(style.render)
        end

        private

        def reduce_whitespace(text)
            text.gsub(/\s+/, " ")
        end

        def load
            Oga.parse_xml File.open @path
        end

        def component_xml
            load.css(ELEMENTS[:component]).first
        end

        def render(type)
            Element.new(@xml, type).render
        end

    end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vueck-1.0.4 lib/sfc.rb
vueck-1.0.3 lib/sfc.rb
vueck-1.0.2 lib/sfc.rb
vueck-1.0.1 lib/sfc.rb
vueck-1.0.0 lib/sfc.rb