Module: DevelopWithStyle::Helper

Defined in:
lib/develop_with_style/helper.rb

Instance Method Summary collapse

Instance Method Details

#developed_with_styleObject



12
13
14
15
16
17
# File 'lib/develop_with_style/helper.rb', line 12

def developed_with_style
  asset = "#{@virtual_path}#{compute_asset_extname(@virtual_path, type: :stylesheet)}"
  Webpacker.manifest.lookup(asset) && @css_modules.unshift(@virtual_path)

  stylesheet_pack_tag(*@css_modules)
end

#style(name, tag_name: :div, &block) ⇒ Object



2
3
4
5
6
7
8
9
10
# File 'lib/develop_with_style/helper.rb', line 2

def style(name, tag_name: :div, &block)
  @css_modules ||= []
  @css_modules << @virtual_path unless @css_modules.include?(@virtual_path)

  path = "app/javascript/packs/#{@virtual_path}.module.scss"
  class_name = Base64.encode64(path).gsub(/\W/, '')[0, 8] + "__#{name}"

  block_given? ? tag.send(tag_name, class: class_name, &block) : class_name
end