Class: Jepeto::JekyllPost

Inherits:
Object
  • Object
show all
Includes:
JekyllPostHelper
Defined in:
lib/jepeto/jekyll_post.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from JekyllPostHelper

#slugalize

Constructor Details

#initialize(options) ⇒ JekyllPost

Returns a new instance of JekyllPost.



28
29
30
31
# File 'lib/jepeto/jekyll_post.rb', line 28

def initialize(options)
  define_instance_variables!
  @options = check_options(options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



26
27
28
# File 'lib/jepeto/jekyll_post.rb', line 26

def options
  @options
end

Instance Method Details

#save!Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/jepeto/jekyll_post.rb', line 47

def save!

  Dir.chdir('..') if Dir.getwd.include?(Jepeto::POST_DIRECTORY)
  post_file = File.join(Jepeto::POST_DIRECTORY, self.filename)

  unless File.writable?(Jepeto::POST_DIRECTORY)
    raise "The post directory is not wriatble"
    exit
  end

  if File.exists?(post_file)
    raise NameError, "A post file with the same name already exists"
    exit
  end

  File.open(post_file, 'w') do |file|
    file.puts yaml_front_matter
  end

  File.expand_path(post_file)
end