Sha256: 5cebf6494838ffdf68654fe839a97e38ef53d14bad0b1f2a044cb0fb2f234c05

Contents?: true

Size: 1.93 KB

Versions: 9

Compression:

Stored size: 1.93 KB

Contents

def commenting?
  comment && action != :delete
end

event :add_comment, :prepare_to_store, on: :save, when: :comment do
  Env.session[:comment_author] = comment_author if Env.session
  return unless comment.present?

  self.content =
    [content, format.comment_with_signature].compact.join "\n<hr\>\n"
  self.comment = nil
end

attr_writer :comment_author

def comment_author
  @comment_author ||=
    Env.session[:comment_author] || Env.params[:comment_author] || "Anonymous"
end

def clean_comment
  comment.split(/\n/).map do |line|
    "<p>#{line.strip.empty? ? '&nbsp;' : line}</p>"
  end * "\n"
end

format do
  def comment_with_signature
    "#{card.clean_comment}\n#{comment_signature}"
  end

  def comment_signature
    wrap_with :div, class: "w-comment-author" do
      "#{comment_author}.....#{Time.zone.now}"
    end
  end

  def comment_author
    if Auth.signed_in?
      "[[#{Auth.current.name}]]"
    else
      "#{card.comment_author} (Not signed in)"
    end
  end

  view :comment_box, denial: :blank, unknown: true, perms: :update do
    wrap_with :div, class: "comment-box nodblclick" do
      action = card.new_card? ? :create : :update
      card_form action do
        [hidden_comment_fields, comment_box, comment_buttons]
      end
    end
  end

  def hidden_comment_fields
    return unless card.new_card?

    hidden_field_tag "card[name]", card.name
    # FIXME: wish we had more generalized solution for names.
    # without this, nonexistent cards will often take left's linkname.
    # (needs test)
  end

  def comment_box
    text_area :comment, rows: 3
  end

  def comment_buttons
    wrap_with :div, class: "comment-buttons" do
      [comment_author_label, comment_submit_button]
    end
  end

  def comment_author_label
    return if Auth.signed_in?

    %(<label>My Name is:</label> #{text_field :comment_author})
  end

  def comment_submit_button
    submit_button text: "Comment", type: :submit, disable_with: "Commenting"
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
card-mod-comment-0.13.4 set/all/comment.rb
card-mod-comment-0.13.3 set/all/comment.rb
card-mod-comment-0.13.2 set/all/comment.rb
card-mod-comment-0.13.1 set/all/comment.rb
card-mod-comment-0.13.0 set/all/comment.rb
card-mod-comment-0.11.7 set/all/comment.rb
card-mod-comment-0.12.0 set/all/comment.rb
card-mod-comment-0.11.6 set/all/comment.rb
card-mod-comment-0.11.5 set/all/comment.rb