Class: PagecordCLI::ImageUploads

Inherits:
Object
  • Object
show all
Defined in:
lib/pagecord_cli/image_uploads.rb

Constant Summary collapse

MARKDOWN_IMAGE =
/!\[([^\]]*)\]\(([^)]+)\)/
OBSIDIAN_IMAGE =
/!\[\[([^\]]+)\]\]/
IMAGE_EXTENSIONS =
/\.(jpe?g|png|gif|webp)\z/i

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, file_path:, metadata:, blog:, client:) ⇒ ImageUploads

Returns a new instance of ImageUploads.



13
14
15
16
17
18
19
# File 'lib/pagecord_cli/image_uploads.rb', line 13

def initialize(content, file_path:, metadata:, blog:, client:)
  @content = content
  @file_path = file_path
  @metadata = 
  @blog = blog
  @client = client
end

Instance Attribute Details

#blogObject (readonly)

Returns the value of attribute blog.



11
12
13
# File 'lib/pagecord_cli/image_uploads.rb', line 11

def blog
  @blog
end

#clientObject (readonly)

Returns the value of attribute client.



11
12
13
# File 'lib/pagecord_cli/image_uploads.rb', line 11

def client
  @client
end

#contentObject (readonly)

Returns the value of attribute content.



11
12
13
# File 'lib/pagecord_cli/image_uploads.rb', line 11

def content
  @content
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



11
12
13
# File 'lib/pagecord_cli/image_uploads.rb', line 11

def file_path
  @file_path
end

#metadataObject (readonly)

Returns the value of attribute metadata.



11
12
13
# File 'lib/pagecord_cli/image_uploads.rb', line 11

def 
  @metadata
end

Instance Method Details

#processObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pagecord_cli/image_uploads.rb', line 21

def process
  with_markdown_images = content.gsub(MARKDOWN_IMAGE) do |match|
    path = Regexp.last_match(2)
    local_path?(path) ? attachment_tag_for(path) : match
  end

  with_markdown_images.gsub(OBSIDIAN_IMAGE) do |match|
    path = Regexp.last_match(1)
    local_path?(path) ? attachment_tag_for(path) : match
  end
end