Class: Markbridge::AST::Upload

Inherits:
Node
  • Object
show all
Defined in:
lib/markbridge/ast/upload.rb

Overview

Represents a Discourse upload reference (image or file attachment). Uses the upload:// URL scheme.

Examples:

Image upload

upload = AST::Upload.new(
  sha1: "RBhXLF6381Te3mneJQNnnyNNt5",
  filename: "image.png",
  type: :image,
  alt: "My image",
  dimensions: "64x64"
)

File attachment

upload = AST::Upload.new(
  sha1: "ppJp89TTiLOo6Vl4mAmo21MV28w",
  filename: "document.pdf",
  type: :attachment,
  size: "502.1 KB"
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sha1:, filename: nil, type: :image, alt: nil, dimensions: nil, size: nil, raw: nil) ⇒ Upload

Create a new Upload node.

Parameters:

  • sha1 (String)

    the base62 SHA1 identifier

  • filename (String, nil) (defaults to: nil)

    original filename

  • type (Symbol) (defaults to: :image)

    type of upload (:image or :attachment)

  • alt (String, nil) (defaults to: nil)

    alt text

  • dimensions (String, nil) (defaults to: nil)

    dimensions string

  • size (String, nil) (defaults to: nil)

    file size string

  • raw (String, nil) (defaults to: nil)

    the original raw Markdown



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/markbridge/ast/upload.rb', line 55

def initialize(
  sha1:,
  filename: nil,
  type: :image,
  alt: nil,
  dimensions: nil,
  size: nil,
  raw: nil
)
  @sha1 = sha1
  @filename = filename
  @type = type
  @alt = alt
  @dimensions = dimensions
  @size = size
  @raw = raw
end

Instance Attribute Details

#altString? (readonly)

Returns alt text (for images).

Returns:

  • (String, nil)

    alt text (for images)



35
36
37
# File 'lib/markbridge/ast/upload.rb', line 35

def alt
  @alt
end

#dimensionsString? (readonly)

Returns dimensions string like “64x64” (for images).

Returns:

  • (String, nil)

    dimensions string like “64x64” (for images)



38
39
40
# File 'lib/markbridge/ast/upload.rb', line 38

def dimensions
  @dimensions
end

#filenameString? (readonly)

Returns original filename.

Returns:

  • (String, nil)

    original filename



29
30
31
# File 'lib/markbridge/ast/upload.rb', line 29

def filename
  @filename
end

#rawString? (readonly)

Returns the original raw Markdown.

Returns:

  • (String, nil)

    the original raw Markdown



44
45
46
# File 'lib/markbridge/ast/upload.rb', line 44

def raw
  @raw
end

#sha1String (readonly)

Returns the base62 SHA1 identifier from upload:// URL.

Returns:

  • (String)

    the base62 SHA1 identifier from upload:// URL



26
27
28
# File 'lib/markbridge/ast/upload.rb', line 26

def sha1
  @sha1
end

#sizeString? (readonly)

Returns file size string like “502.1 KB” (for attachments).

Returns:

  • (String, nil)

    file size string like “502.1 KB” (for attachments)



41
42
43
# File 'lib/markbridge/ast/upload.rb', line 41

def size
  @size
end

#typeSymbol (readonly)

Returns type of upload (:image or :attachment).

Returns:

  • (Symbol)

    type of upload (:image or :attachment)



32
33
34
# File 'lib/markbridge/ast/upload.rb', line 32

def type
  @type
end