Sha256: 5e350e5859d4ad2d5be4170df0378bb28a236a92bf992e0b5d8b9018d8ff2232

Contents?: true

Size: 1.64 KB

Versions: 8

Compression:

Stored size: 1.64 KB

Contents

event :add_comment, :prepare_to_store,
      on: :save, when: proc { |c| c.comment } do
  cleaned_comment =
    comment.split(/\n/).map do |line|
      "<p>#{line.strip.empty? ? '&nbsp;' : line}</p>"
    end * "\n"

  signature =
    if Auth.signed_in?
      "[[#{Auth.current.name}]]"
    else
      Env.session[:comment_author] = comment_author if Env.session
      "#{comment_author} (Not signed in)"
    end

  self.content = %(
    #{content}
    #{'<hr>' unless content.blank?}
    #{cleaned_comment}
    <div class="w-comment-author">--#{signature}.....#{Time.zone.now}</div>
  )
end

format do
  view :comment_box,
       denial: :blank, tags: :unknown_ok,
       perms: ->(r) { r.card.ok? :comment } do |_args|
    <<-HTML
      <div class="comment-box nodblclick">#{comment_form}</div>
    HTML
  end

  def comment_form
    card_form :update do
      %(
        #{hidden_field_tag('card[name]', card.name) if card.new_card?
          # FIXME: wish we had more generalized solution for names.
          # without this, nonexistent cards will often take left's linkname.
          # (needs test)
        }
        #{text_area :comment, rows: 3}
        #{comment_buttons}
      )
    end
  end

  def comment_buttons
    <<-HTML
      <div class="comment-buttons">
        #{unless Auth.signed_in?
            card.comment_author = session[:comment_author] ||
                                  params[:comment_author] || 'Anonymous' # ENGLISH
            %(<label>My Name is:</label> #{text_field :comment_author})
          end}
        #{submit_button text: 'Comment', type: :submit,
                        disable_with: 'Commenting'}
      </div>
    HTML
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
card-1.20.0 mod/standard/set/all/comment.rb
card-1.19.6 mod/standard/set/all/comment.rb
card-1.19.5 mod/standard/set/all/comment.rb
card-1.19.4 mod/standard/set/all/comment.rb
card-1.19.3 mod/standard/set/all/comment.rb
card-1.19.2 mod/standard/set/all/comment.rb
card-1.19.1 mod/standard/set/all/comment.rb
card-1.19.0 mod/standard/set/all/comment.rb