<commit_before>module Yoolk
  module Liquid
    class FormTag < ::Liquid::Block
      def initialize(tag_name, markup, tokens)
         super
         @url = markup
      end
      def render(context)
        @token ||= context.registers[:view].form_authenticity_token
        @flash = "<p>#{context.registers[:view].flash[:notice]}<p>"

        "<form accept-charset='UTF-8' method='post' #{@url}>
        <div style='margin:0;padding:0;display:inline'>
        <input name='utf8' type='hidden' value='✓'>
        <input name='authenticity_token' type='hidden' value='#{@token}'>
        </div>" + @flash + super + "</form>"
      end

    end
  end
end

Liquid::Template.register_tag('form', Yoolk::Liquid::FormTag)<commit_msg>add yoolk liquid form tag<commit_after>module Yoolk
  module Liquid
    class FormTag < ::Liquid::Block
      Syntax = /(#{::Liquid::VariableSignature}+)/

      def initialize(tag_name, markup, options)
        super

        if markup =~ Syntax
          @variable_name = $1
          @attributes    = {}
        else
          raise SyntaxError.new("Syntax Error - Valid syntax: {% form contact %}")
        end
      end

      def render(context)
        @csrf_token  = context.registers[:view].form_authenticity_token
        @flash       = context.registers[:view].flash[:notice]
        contact_from = context[@variable_name]
        context.stack do
          context['form'] = {
            'errors' => @flash
          }
          form_builder(contact_from, render_all(@nodelist, context))
        end
      end

      def form_builder(contact_from, input)
        %Q{
          <form accept-charset='UTF-8' method='post' class='contact-form' id='contact-form' action=''>
            <div style='margin:0;padding:0;display:inline'>
              <input name='utf8' type='hidden' value='✓'>
              <input name='authenticity_token' type='hidden' value='#{@csrf_token}'>
            </div>
            #{input}
          </form>
        }
      end

    end
  end
end

Liquid::Template.register_tag('form', Yoolk::Liquid::FormTag)
{'fraction_non_alphanumeric': 0.14175506268081003, 'fraction_numerical': 0.004339440694310511, 'mean_word_length': 2.4525790349417638, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1058647', 'n_tokens_mistral': 644, 'n_tokens_neox': 625, 'n_words': 125}