Class: Agave::Dump::Operation::CreatePost

Inherits:
Object
  • Object
show all
Defined in:
lib/agave/dump/operation/create_post.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, path) ⇒ CreatePost

Returns a new instance of CreatePost.



14
15
16
17
# File 'lib/agave/dump/operation/create_post.rb', line 14

def initialize(context, path)
  @context = context
  @path = path
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



12
13
14
# File 'lib/agave/dump/operation/create_post.rb', line 12

def content
  @content
end

#contextObject (readonly)

Returns the value of attribute context.



9
10
11
# File 'lib/agave/dump/operation/create_post.rb', line 9

def context
  @context
end

#frontmatter_formatObject

Returns the value of attribute frontmatter_format.



11
12
13
# File 'lib/agave/dump/operation/create_post.rb', line 11

def frontmatter_format
  @frontmatter_format
end

#frontmatter_valueObject

Returns the value of attribute frontmatter_value.



11
12
13
# File 'lib/agave/dump/operation/create_post.rb', line 11

def frontmatter_value
  @frontmatter_value
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/agave/dump/operation/create_post.rb', line 9

def path
  @path
end

Instance Method Details

#performObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/agave/dump/operation/create_post.rb', line 19

def perform
  FileUtils.mkdir_p(File.dirname(path))

  File.open(File.join(context.path, path), 'w') do |file|
    file.write Format.frontmatter_dump(
      frontmatter_format,
      frontmatter_value
    )
    file.write "\n\n"
    file.write content
  end
end