require 'yaml'
require 'jekyll/minibundle/asset_file_registry'

module Jekyll::Minibundle
  class MiniBundleBlock < Liquid::Block
    def initialize(tag_name, type, _tokens)
      super
      @type = type.strip.to_sym
    end

    def render(context)
      site = context.registers.fetch(:site)
      config = get_current_config(YAML.load(super), site)
      file = AssetFileRegistry.bundle_file(site, config)
      file.add_as_static_file_to(site)
      file.destination_path_for_markup
    end

    def self.default_config
      {
        'source_dir'        => '_assets',
        'destination_path'  => 'assets/site',
        'assets'            => [],
        'attributes'        => {}
      }
    end

    private

    def get_current_config(user_config, site)
      MiniBundleBlock.default_config.
        merge(user_config).
        merge('type' => @type)
    end
  end
end

Liquid::Template.register_tag('minibundle', Jekyll::Minibundle::MiniBundleBlock)

require 'safe_yaml/load'
require 'jekyll/minibundle/asset_file_registry'

module Jekyll::Minibundle
  class MiniBundleBlock < Liquid::Block
    def initialize(tag_name, type, _tokens)
      super
      @type = type.strip.to_sym
    end

    def render(context)
      site = context.registers.fetch(:site)
      config = get_current_config(SafeYAML.load(super), site)
      file = AssetFileRegistry.bundle_file(site, config)
      file.add_as_static_file_to(site)
      file.destination_path_for_markup
    end

    def self.default_config
      {
        'source_dir'        => '_assets',
        'destination_path'  => 'assets/site',
        'assets'            => [],
        'attributes'        => {}
      }
    end

    private

    def get_current_config(user_config, site)
      MiniBundleBlock.default_config.
        merge(user_config).
        merge('type' => @type)
    end
  end
end

Liquid::Template.register_tag('minibundle', Jekyll::Minibundle::MiniBundleBlock)

Use safe_yaml to load user input from minibundle block
Use safe_yaml to load user input from minibundle block

This is what Jekyll uses internally to load YAML input. It's good idea
to use it here as well for consistency and safety.
