-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponents.rb
More file actions
51 lines (42 loc) · 1.55 KB
/
Copy pathcomponents.rb
File metadata and controls
51 lines (42 loc) · 1.55 KB
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
# frozen_string_literal: true
# components / https://github.com/jasoncomes/Components-Liquid-Tag
# This automatically registers all tags and blocks added to the _html/components directory. If the @styleguide tag is used then it'll build out a page: https://www.bestcolleges.com/styleguide/
module Jekyll
# Custom Blocks Class ~ Extends Jekyll Liquid Blocks
class CustomBlocks < Liquid::Block
include Liquid::StandardFilters
# Initialize
def initialize(tag, markup, tokens)
@template = Liquid::Template.parse(File.read(Dir.glob("_html/components/**/#{tag}.block").first))
@markup = markup
@tag = tag
super
end
# Render Template with Properties
def render(context)
@template.render(get_properties(context, @tag, @markup, super))
end
end
# Custom Tag Class ~ Extends Jekyll Liquid Tags
class CustomTags < Liquid::Tag
include Liquid::StandardFilters
# Initialize
def initialize(tag, markup, tokens)
@template = Liquid::Template.parse(File.read(Dir.glob("_html/components/**/#{tag}.tag").first))
@markup = markup
@tag = tag
super
end
# Render Template with Properties
def render(context)
@template.render(get_properties(context, @tag, @markup))
end
end
end
# Loop Components Directory For Tags/Blocks
Dir.glob('_html/components/**/*') do |file|
ext = File.extname(file)
if ext === '.tag' || ext === '.block'
Liquid::Template.register_tag(File.basename(file, ext), ext === '.tag' ? Jekyll::CustomTags : Jekyll::CustomBlocks)
end
end