forked from hopsoft/stimulus_reflex_expo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demos_helper.rb
101 lines (86 loc) · 2.36 KB
/
demos_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# frozen_string_literal: true
module DemosHelper
def demos
%w[
book_search
chat
calendar
geo_selector
gravatar
permalink
reverse_text
tabular
todo
validation
]
end
def render_demo(demo)
render("/demos/demo") { render demo }
end
def render_explanation(&block)
render "/demos/explanation", &block
end
def render_gists(*filepaths)
render "/demos/gists", filepaths: filepaths, grouped_filepaths: filepaths.group_by { |filepath| language filepath }
end
def file_timestamps(filepaths = [])
filepaths.map { |p| File.mtime(p).iso8601 }
end
def file_lines(filepath)
lines = File.open(Rails.root.join(filepath)).readlines
lines.reject! { |line| line.to_s.strip =~ /\A(#|\/|\*|<--)/ }
lines.shift while lines.first.blank?
lines.pop while lines.last.blank?
lines
end
def language(filepath)
case File.extname(filepath)
when ".scss" then "scss"
when ".html" then "html"
when ".erb" then "erb"
when ".js" then "javascript"
when ".rb" then "ruby"
end
end
def language_title(language)
case language
when "scss" then "CSS"
when "html" then "HTML"
when "erb" then "ERB"
when "javascript" then "JavaScript"
when "ruby" then "Ruby"
end
end
def regions
countries = ISO3166::Country.all
countries.map(&:region).uniq.sort.select(&:present?)
end
def subregions(region)
countries = ISO3166::Country.all.select { |c| c.region == region }
countries.map(&:subregion).uniq.sort.select(&:present?)
end
def countries(region, subregion)
countries = ISO3166::Country.all.select { |c| c.region == region && c.subregion == subregion }
countries.uniq.sort.select(&:present?).map(&:name)
end
def active_chat?(color)
session[:chat_color] == color.to_s
end
def chat_css(color)
case color.to_sym
when :red then "bg-danger-light border-danger-light text-danger"
when :yellow then "bg-warning-light border-warning-light text-warning-dark"
when :blue then "bg-primary-light border-primary-light text-primary"
end
end
def chat_border_css(color)
case color.to_sym
when :red then "border-danger-light"
when :yellow then "border-warning-light"
when :blue then "border-primary-light"
end
end
def chat_author?(chat)
chat[:author] == request.remote_ip
end
end