Class: ShopifyThemeBuilder::LiquidProcessor
- Inherits:
-
Object
- Object
- ShopifyThemeBuilder::LiquidProcessor
- Defined in:
- lib/shopify_theme_builder/liquid_processor.rb
Overview
LiquidProcessor is responsible for processing Liquid files by combining various related files (Liquid, schema, CSS, JS, doc, comment) into a single compiled Liquid file suitable for Shopify themes. It supports specific Liquid file types and organizes the output into designated folders based on the file type. Requirements:
- The current folder must contain one Liquid file named: section.liquid, snippet.liquid, or block.liquid.
- Blocks must have a schema.json file.
- Schema file must be named schema.json.
- CSS file must be named style.css.
- JS file must be named index.js.
- Documentation file must be named doc.txt.
- Comment file must be named comment.txt.
Constant Summary collapse
- LIQUID_FILE_TYPES =
%w[section snippet block].freeze
- SUPPORTED_FILES =
{ comment: "comment.txt", doc: "doc.txt", liquid: LIQUID_FILE_TYPES.map { |type| "#{type}.liquid" }, schema: "schema.json", stylesheet: "style.css", javascript: "index.js", stimulus: "controller.js" }.freeze
- SUPPORTED_VALUES =
SUPPORTED_FILES.values.flatten.freeze
Instance Method Summary collapse
-
#initialize(file:, event:) ⇒ LiquidProcessor
constructor
A new instance of LiquidProcessor.
- #process ⇒ Object
Constructor Details
#initialize(file:, event:) ⇒ LiquidProcessor
Returns a new instance of LiquidProcessor.
32 33 34 35 36 37 |
# File 'lib/shopify_theme_builder/liquid_processor.rb', line 32 def initialize(file:, event:) @file = file.gsub("#{Dir.pwd}/", "") @event = event @contents = +"" @logger = Logger.new($stdout) end |
Instance Method Details
#process ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/shopify_theme_builder/liquid_processor.rb', line 39 def process return if component_deleted? return unless processable? compile_content File.write(compiled_filename, @contents.lstrip) compiled_filename end |