Sha256: 0da5ce801efcff8556454a94f003d5f6e019eeb81b9d600d47432f0350237712
Contents?: true
Size: 1.98 KB
Versions: 8
Compression:
Stored size: 1.98 KB
Contents
# frozen_string_literal: true require "ostruct" require "erb" module Decidim module Assets module Tailwind class Instance def write_runtime_configuration evaluated_template = ERB.new(tailwind_configuration_template).result(tailwind_variables.instance_eval { binding }) File.write(File.join(app_path, "tailwind.config.js"), evaluated_template) end private def tailwind_variables # The directories where Tailwind should search for templates are the installed # decidim gems and the current directory (which is the Rails app) decidim_gems = Bundler.load.specs.select { |spec| spec.name =~ /^decidim-/ }.map(&:full_gem_path) content_directories = decidim_gems.push(".") # The variable expected by tailwind is a Javascript array of strings # The directory globbing with the star is done in Ruby because it was causing an infinite loop # when processed by Tailwind content_directories_as_array_of_strings = content_directories.map { |content_directory| "'#{content_directory}'" }.join(",") OpenStruct.new(tailwind_content_directories: content_directories_as_array_of_strings) end def tailwind_configuration_template File.read(configuration_template_path) end def configuration_template_path @configuration_template_path ||= begin original_path = File.expand_path("tailwind.config.js.erb", __dir__) alternate_path = File.expand_path("config/tailwind.config.js.erb", app_path) File.exist?(alternate_path) ? alternate_path : original_path end end def app_path @app_path ||= if defined?(Rails) Rails.application.root else # This is used when Rails is not available from the webpacker binstubs File.expand_path(".", Dir.pwd) end end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems