<commit_before>class SubmitTag < Liquid::Tag
  Syntax = /("[\w\.\s]+"|[\w\.]+)/
  def initialize(tag_name, markup, tokens)
    if markup =~ Syntax
      @input_label = $1
      @attributes = {}
      markup.scan(Liquid::TagAttributes) do |key, value|
        @attributes[key] = value
      end
    else
      raise Liquid::SyntaxError.new("Syntax Error in 'submit_tag' - Valid syntax: submit_tag [\"label\"]")
    end

    super(tag_name, markup, tokens)
  end

  def render(context)
    html_attributes = success_url = ""
    input_type = "submit"

    asset_name = @attributes.delete('asset_name')
    if asset_name && @attributes['src'].empty_or_nil? && ['true', '"true"'].include?(@attributes['image'])
      @attributes['src'] = "/assets/#{Site.current_site_id || 'admin'}/original/#{parse_attribute(asset_name)}"
    end

    @attributes.each do |key, value|
      case key
      when 'value' # skip
      when 'success_url'
        success_url = HiddenFieldTag.new("hidden_field_tag", "success_url #{render_success_url("value", value, context)}", nil).render(context)
      when 'image'
        input_type = "image" if ['true', '"true"'].include?(value)
      else
        html_attributes += render_attribute(key, value, context)
      end
    end
    
    rvalue = success_url
    value = render_attribute("value", @input_label, context)
    rvalue += "<input type=\"#{input_type}\" #{value}#{html_attributes}>"
    rvalue
  end

  private
  
  def render_success_url(key, value, context)
    rvalue = render_attribute(key, value, context)
    rvalue.gsub("=", ":")
  end

  def render_attribute(key, value, context)
    " #{key}=\"#{parse_attribute(value)}\""
  end

  def parse_attribute(value)
    if value =~ Bionic::QuotedAttribute
      $1
    else
      context_value(value)
    end
  end
<commit_msg>make context and instance variable<commit_after>class SubmitTag < Liquid::Tag
  Syntax = /("[\w\.\s]+"|[\w\.]+)/
  def initialize(tag_name, markup, tokens)
    if markup =~ Syntax
      @input_label = $1
      @attributes = {}
      markup.scan(Liquid::TagAttributes) do |key, value|
        @attributes[key] = value
      end
    else
      raise Liquid::SyntaxError.new("Syntax Error in 'submit_tag' - Valid syntax: submit_tag [\"label\"]")
    end

    super(tag_name, markup, tokens)
  end

  def render(context)
    @context = context
    html_attributes = success_url = ""
    input_type = "submit"

    asset_name = @attributes.delete('asset_name')
    if asset_name && @attributes['src'].empty_or_nil? && ['true', '"true"'].include?(@attributes['image'])
      @attributes['src'] = "/assets/#{Site.current_site_id || 'admin'}/original/#{parse_attribute(asset_name)}"
    end

    @attributes.each do |key, value|
      case key
      when 'value' # skip
      when 'success_url'
        success_url = HiddenFieldTag.new("hidden_field_tag", "success_url #{render_success_url("value", value)}", nil).render(@context)
      when 'image'
        input_type = "image" if ['true', '"true"'].include?(value)
      else
        html_attributes += render_attribute(key, value)
      end
    end
    
    rvalue = success_url
    value = render_attribute("value", @input_label)
    rvalue += "<input type=\"#{input_type}\" #{value}#{html_attributes}>"
    rvalue
  end

  private
  
  def render_success_url(key, value)
    rvalue = render_attribute(key, value)
    rvalue.gsub("=", ":")
  end

  def render_attribute(key, value)
    " #{key}=\"#{parse_attribute(value)}\""
  end

  def parse_attribute(value)
    if value =~ Bionic::QuotedAttribute
      $1
    else
      context_value(value)
    end
  end

{'fraction_non_alphanumeric': 0.15097985095224953, 'fraction_numerical': 0.0011040574109853713, 'mean_word_length': 3.2535211267605635, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 5, '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': '2608967', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1160, 'n_words': 250}