Sha256: 766bae2ec1b17d5f76e1b76ad32d795aeb252192ca9b9ca332c75f541a6facaa

Contents?: true

Size: 1.51 KB

Versions: 3

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

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

    def get_raw_code(sample, type)
      if type == "rails"
        ext = "html.erb"
      elsif type == "react"
        ext = "jsx"
      end

      read_source_file "app/views/playbook/samples", sample, "index.#{ext}"
    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 get_samples(kit)
      sample_yaml = YAML.load_file("#{Playbook::Engine.root}/app/pb_kits/playbook/data/samples.yml")
      all_samples = []

      sample_yaml.each do |_category, sample|
        all_samples.push(sample)
      end

      output = ""
      samples_using_kit = []
      all_samples[0].each do |sample|
        filepath = "#{Playbook::Engine.root}/app/views/playbook/samples/#{sample}/index.html.erb"
        output = `grep -l 'pb_rails(\"#{kit}' #{filepath}`
        samples_using_kit.push(sample) if output.chomp == filepath
      end
      samples_using_kit
    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

3 entries across 3 versions & 1 rubygems

Version Path
playbook_ui-7.11.1 app/helpers/playbook/pb_sample_helper.rb
playbook_ui-7.11.0 app/helpers/playbook/pb_sample_helper.rb
playbook_ui-7.11.0.pre.alpha1 app/helpers/playbook/pb_sample_helper.rb