Module: Playbook::PbSampleHelper

Defined in:
app/helpers/playbook/pb_sample_helper.rb

Instance Method Summary collapse

Instance Method Details

#get_raw_code(sample, type) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'app/helpers/playbook/pb_sample_helper.rb', line 27

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

#get_sample_code_content(sample, type) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'app/helpers/playbook/pb_sample_helper.rb', line 38

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

#has_sample_type?(sample, type) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
10
11
12
# File 'app/helpers/playbook/pb_sample_helper.rb', line 5

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

#pb_sample(sample: "", type: "rails") ⇒ Object



14
15
16
17
# File 'app/helpers/playbook/pb_sample_helper.rb', line 14

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

#read_file(filename) ⇒ Object



19
20
21
22
23
24
25
# File 'app/helpers/playbook/pb_sample_helper.rb', line 19

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

#render_sample_ui(sample, type) ⇒ Object



48
49
50
51
52
53
54
# File 'app/helpers/playbook/pb_sample_helper.rb', line 48

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