module Repost class Senpai < Action DEFAULT_SUBMIT_BUTTON_TEXT = 'Continue' DEFAULT_CHARSET = 'UTF-8' def initialize(url, params: {}, options: {}) @url = url @params = params @options = options @method = options.fetch(:method, :post) @authenticity_token = options.fetch(:authenticity_token, nil) @charset = options.fetch(:charset, DEFAULT_CHARSET) @form_id = options.fetch(:form_id, generated_form_id) @autosubmit = options.fetch(:autosubmit, true) @section_classes = nil#options.dig(:decor, :section, :classes) @section_html = nil#options.dig(:decor, :section, :html) @submit_classes = nil#options.dig(:decor, :submit, :classes) @submit_text = DEFAULT_SUBMIT_BUTTON_TEXT#options.dig(:decor, :submit, :text) || DEFAULT_SUBMIT_BUTTON_TEXT end def perform compiled_body = if autosubmit form_body << auto_submit_script << no_script else form_body << submit_section end form_head << compiled_body << form_footer end private attr_reader :url, :params, :options, :method, :form_id, :autosubmit, :section_classes, :section_html, :submit_classes, :submit_text, :authenticity_token, :charset def form_head "
" end def form_body inputs = params.map do |key, value| "" end inputs.unshift(csrf_token) if authenticity_token inputs.join end def form_footer "
" end def csrf_token "" end def no_script "" end def submit_section "
#{section_html}
" end def generated_form_id "repost-#{Time.now.to_i}" end def auto_submit_script "" end end end