Sha256: b8cae079fba1a684c8772c78d56f72c80dc8b16808a73e4e2367306963311140

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

module PageflowScrolled
  # @api private
  module ThemesHelper
    def scrolled_theme_asset_path(theme, path)
      asset_pack_path("media/pageflow-scrolled/themes/#{theme.name}/#{path}")
    end

    def scrolled_theme_stylesheet_pack_tags(theme)
      safe_join(theme.options.fetch(:stylesheet_packs, []).map do |pack|
        stylesheet_pack_tag(pack, media: 'all')
      end)
    end

    def scrolled_theme_properties_style_tag(theme)
      declarations = [
        scrolled_theme_deep_declarations(theme.options.fetch(:font_family, {}), 'font_family'),
        scrolled_theme_deep_declarations(theme.options.fetch(:colors, {}), 'color')
      ].flatten

      content_tag('style', raw(":root {\n#{declarations.join("\n")}\n}\n"))
    end

    private

    def scrolled_theme_deep_declarations(hash, suffix, prefix = [])
      hash.flat_map do |key, value|
        if value.is_a?(Hash)
          scrolled_theme_deep_declarations(value, suffix, [*prefix, key])
        else
          name = [*prefix, key, suffix].join('_')
          "--theme-#{name.dasherize}: #{value};"
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pageflow-15.6.1 entry_types/scrolled/app/helpers/pageflow_scrolled/themes_helper.rb
pageflow-15.6.0 entry_types/scrolled/app/helpers/pageflow_scrolled/themes_helper.rb
pageflow-15.5.0 entry_types/scrolled/app/helpers/pageflow_scrolled/themes_helper.rb