Class: Writetheman::Article::Base

Inherits:
Object
  • Object
show all
Includes:
Access, Content, File, Utils, Path
Defined in:
lib/writetheman/article/base.rb

Constant Summary

Constants included from Utils

Utils::REPLACE_CHARACTER

Instance Attribute Summary

Attributes included from File

#extension, #filename

Attributes included from Content

#all_content, #body, #header, #header_params, #tags

Attributes included from Access

#date, #str_date, #title

Attributes included from Path

#path_application

Instance Method Summary collapse

Methods included from Utils

encoding_from_windows, format_content_from_file, format_readable_html, regex_body_from_content, regex_header_from_content, special_encoding

Methods included from Content

#check_header_params_valid, #remove_content!

Methods included from Access

#filemane_without_extension, #filename_from_title, #init_filename, #init_from_params, #remove_access!

Constructor Details

#initialize(path_application) ⇒ Base

Returns a new instance of Base.



11
12
13
14
# File 'lib/writetheman/article/base.rb', line 11

def initialize(path_application)
  @path_application = path_application
  @extension = ".html.markdown"
end

Instance Method Details

#createObject



16
17
18
19
20
21
# File 'lib/writetheman/article/base.rb', line 16

def create
  init_header_from_params if @header.nil? || @header.empty?
  init_content_from_header_body
  init_filename if @filename.nil? || @filename.empty?
  create_file
end

#create_from_params(params = {}) ⇒ Object



23
24
25
26
27
# File 'lib/writetheman/article/base.rb', line 23

def create_from_params(params={})
  remove_access!
  init_from_params(params) if !params.empty?
  create
end

#load_from_file(filename) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/writetheman/article/base.rb', line 37

def load_from_file(filename)
  remove_access!
  @filename = filename
  read
  #@title = @header_params['title']
  #@date = Date.parse(@header_params['date'])
  init_header_params
end

#load_from_title(title, date) ⇒ Object



46
47
48
49
50
51
# File 'lib/writetheman/article/base.rb', line 46

def load_from_title(title, date)
  remove_access!
  @title = title
  @date = date
  read
end

#readObject



29
30
31
32
33
34
35
# File 'lib/writetheman/article/base.rb', line 29

def read
  remove_content!
  init_filename
  read_file
  init_header_body_from_content
  @all_content
end

#remove_all!Object



64
65
66
67
# File 'lib/writetheman/article/base.rb', line 64

def remove_all!
  remove_access!
  remove_content!
end

#update(oldfilename) ⇒ Object



53
54
55
56
# File 'lib/writetheman/article/base.rb', line 53

def update(oldfilename)
  delete_file(oldfilename)
  create
end

#update_from_params(oldfilename, params = {}) ⇒ Object



58
59
60
61
62
# File 'lib/writetheman/article/base.rb', line 58

def update_from_params(oldfilename, params={})
  remove_access!
  init_from_params(params) if !params.empty?
  update(oldfilename)
end