Sha256: 1d4654026eb9d4dc0c59dcf66ff9078f97b7591f1821c415c32f4aacfb93f41d

Contents?: true

Size: 1.48 KB

Versions: 2

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

module Playbook
  module PbSampleHelper
    def has_sample_type?(sample, type)
      type ||= "rails"
      if type == "rails"
        Dir["../../views/playbook/samples/#{sample}/*.html.erb"].empty?
      elsif type == "react"
        Dir["../../views/playbook/samples/#{sample}/*.jsx"].empty?
      end
    end

    def kits_used(sample)
      code = get_raw_code(sample, "rails")
      kits_array = code.scan(/pb_rails\("(\w+)(?:"|\/)/)
      kits_array.uniq
    end

    def pb_sample(sample: "", type: "rails")
      @type = type
      @sample = sample
    end

    def read_file(filename)
      if File.file?(filename)
        File.read(filename)
      else
        ""
      end
    end

    def get_raw_code(sample, type)
      if type == "rails"
        ext = "html.erb"
      elsif type == "react"
        ext = "jsx"
      end
      filename = "#{Playbook::Engine.root}/app/views/playbook/samples/#{sample}/index.#{ext}"
      contents = read_file(filename)
      contents
    end

    def get_sample_code_content(sample, type)
      if type == "rails"
        rouge_type = "erb"
      elsif type == "react"
        rouge_type = "react"
      end
      code = get_raw_code(sample, type)
      raw rouge(code, rouge_type)
    end

    def render_sample_ui(sample, type)
      if type == "rails"
        render template: "playbook/samples/#{sample}/index.html.erb"
      elsif type == "react"
        react_component(sample.titleize.delete(" ").to_s)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
playbook_ui-7.10.0 app/helpers/playbook/pb_sample_helper.rb
playbook_ui-7.9.0 app/helpers/playbook/pb_sample_helper.rb