Sha256: f84e4c6270c94f182ff2e2138a4f2b88737a970fcd4c768f1d6d29cf751266e1

Contents?: true

Size: 1.57 KB

Versions: 10

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

module Playbook
  module PbSampleHelper
    def kits_used(sample)
      code = get_raw_code(sample, "rails")
      kits_array = code.scan(%r{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_category(sample)
      cat = ""
      SAMPLES.each do |category, samples|
        cat = category if samples.include?(sample)
      end
      cat
    end

    def get_samples(kit)
      all_samples = []

      SAMPLES.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

10 entries across 10 versions & 1 rubygems

Version Path
playbook_ui-8.0.0.pre.alpha1 app/helpers/playbook/pb_sample_helper.rb
playbook_ui-7.16.0.pre.alpha5 app/helpers/playbook/pb_sample_helper.rb
playbook_ui-7.16.0.pre.alpha4 app/helpers/playbook/pb_sample_helper.rb
playbook_ui-7.16.0.pre.alpha3 app/helpers/playbook/pb_sample_helper.rb
playbook_ui-7.16.0.pre.alpha2 app/helpers/playbook/pb_sample_helper.rb
playbook_ui-7.16.0.pre.alpha1 app/helpers/playbook/pb_sample_helper.rb
playbook_ui-7.14.0.pre.alpha1 app/helpers/playbook/pb_sample_helper.rb
playbook_ui-7.16.0 app/helpers/playbook/pb_sample_helper.rb
playbook_ui-7.15.1 app/helpers/playbook/pb_sample_helper.rb
playbook_ui-7.15.0 app/helpers/playbook/pb_sample_helper.rb