Class: JekyllBookshop::StyleTag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll-bookshop/tags/style-tag.rb

Instance Method Summary collapse

Instance Method Details

#render(context) ⇒ Object



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
# File 'lib/jekyll-bookshop/tags/style-tag.rb', line 5

def render(context)
  site = context.registers[:site]

  bookshop_scss_files = []
  site.config["bookshop_base_locations"]&.each do |location|
    components_loc = Pathname.new(location + "/").cleanpath.to_s
    scss_files = Dir.glob(components_loc + "/**/*.scss")&.sort&.collect do |scss_file|
      scss_file.sub!(components_loc + "/", "").sub!(".scss", "")
    end
    bookshop_scss_files.push(*scss_files)
  end

  bookshop_scss_files = bookshop_scss_files&.collect do |file|
    "@import \"#{file}\";"
  end

  bookshop_scss_files.sort! do |a, b| 
    a_shared = a.match(%r!"shared\/!)
    b_shared = b.match(%r!"shared\/!)
    case
    when a_shared && !b_shared
      -1
    when !a_shared && b_shared
      1
    else
      a <=> b
    end
  end

  "@media all, bookshop {#{bookshop_scss_files.join("")}}"
end