Class: RuneBlog::Post
- Inherits:
-
Object
- Object
- RuneBlog::Post
- Includes:
- Helpers
- Defined in:
- lib/global.rb,
lib/post.rb
Instance Attribute Summary collapse
-
#blog ⇒ Object
Returns the value of attribute blog.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#draft ⇒ Object
Returns the value of attribute draft.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#num ⇒ Object
readonly
Returns the value of attribute num.
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#views ⇒ Object
readonly
Returns the value of attribute views.
Class Method Summary collapse
- .create(title:, teaser:, body:, pubdate: Time.now.strftime("%Y-%m-%d"), other_views: []) ⇒ Object
- .files(num, root) ⇒ Object
- .load(post) ⇒ Object
Instance Method Summary collapse
- #build ⇒ Object
- #edit ⇒ Object
-
#initialize ⇒ Post
constructor
A new instance of Post.
-
#write_metadata(meta) ⇒ Object
FIXME ???.
Methods included from Helpers
#copy, #copy!, #create_dirs, #dump, #error, #find_draft_slugs, #get_root, #get_views, #interpolate, #livetext, #new_dotfile, #new_sequence, #put_config, #read_config, #subdirs, #try_read_config, #write_config
Constructor Details
Instance Attribute Details
#blog ⇒ Object
Returns the value of attribute blog.
9 10 11 |
# File 'lib/post.rb', line 9 def blog @blog end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
7 8 9 |
# File 'lib/post.rb', line 7 def date @date end |
#draft ⇒ Object
Returns the value of attribute draft.
9 10 11 |
# File 'lib/post.rb', line 9 def draft @draft end |
#meta ⇒ Object
Returns the value of attribute meta.
9 10 11 |
# File 'lib/post.rb', line 9 def @meta end |
#num ⇒ Object (readonly)
Returns the value of attribute num.
7 8 9 |
# File 'lib/post.rb', line 7 def num @num end |
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
7 8 9 |
# File 'lib/post.rb', line 7 def slug @slug end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
7 8 9 |
# File 'lib/post.rb', line 7 def title @title end |
#views ⇒ Object (readonly)
Returns the value of attribute views.
7 8 9 |
# File 'lib/post.rb', line 7 def views @views end |
Class Method Details
.create(title:, teaser:, body:, pubdate: Time.now.strftime("%Y-%m-%d"), other_views: []) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/post.rb', line 70 def self.create(title:, teaser:, body:, pubdate: Time.now.strftime("%Y-%m-%d"), other_views:[]) post = self.new # ONLY place next_sequence is called! num = post..num = post.blog.next_sequence # new_metadata post..title, post.., post..body, post..pubdate = title, , body, pubdate post..views = [post.blog.view.to_s] + other_views post.. = [] post.blog.make_slug(post.) # adds to meta # create_draft viewhome = post.blog.view.publisher.url = post. text = RuneBlog.post_template(num: .num, title: .title, date: .pubdate, view: .view, teaser: ., body: .body, views: .views, tags: ., home: viewhome) srcdir = "#{post.blog.root}/drafts/" vpdir = "#{post.blog.root}/drafts/" verify(Dir.exist?(srcdir) => "#{srcdir} not found", .slug.is_a?(String) => "slug #{.slug.inspect} is invalid") fname = .slug + ".lt3" post.draft = srcdir + fname dump(text, post.draft) return post end |
.files(num, root) ⇒ Object
13 14 15 16 17 |
# File 'lib/post.rb', line 13 def self.files(num, root) files = Find.find(root).to_a result = files.grep(/#{prefix(num)}-/) result end |
.load(post) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/post.rb', line 19 def self.load(post) raise "Doesn't work right now" raise NoBlogAccessor if RuneBlog.blog.nil? # "post" is a slug pdir = RuneBlog.blog.view.dir + "/" + post verify(Dir.exist?(pdir) => "Directory #{pdir} not found") = nil Dir.chdir(pdir) do verify(File.exist?("metadata.txt") => "metadata.txt not found", File.exist?("teaser.txt") => "teaser.txt not found") # File.exist?("body.txt") => "body.txt not found") = read_config("metadata.txt") verify(.date => "meta.date is nil", .views => "meta.views is nil", . => "meta.tags is nil") .date = Date.parse(.date) .views = .views.split . = ..split . = File.read("teaser.txt") # meta.body = File.read("body.txt") end end |
Instance Method Details
#build ⇒ Object
108 109 110 111 112 113 |
# File 'lib/post.rb', line 108 def build post = self views = post..views text = File.read(@draft) @blog.generate_post(@draft) end |
#edit ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/post.rb', line 99 def edit verify(File.exist?(@draft) => "File #{@draft} not found") result = system("vi #@draft +8") # TODO improve this raise EditorProblem(draft) unless result nil rescue => err error(err) end |
#write_metadata(meta) ⇒ Object
FIXME ???
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/post.rb', line 43 def () # FIXME ??? debug "=== write_metadata:" debug "-----\n#{.inspect}\n-----" fname2 = "metadata.txt" hash = .to_h File.write("teaser.txt", hash[:teaser]) # STDERR.puts ">>>> #{__method__}: writing #{@live.body.size} bytes to #{Dir.pwd}/body.txt" # File.write("body.txt", hash[:body]) hash.delete(:teaser) hash.delete(:body) hash[:views] = hash[:views].join(" ") hash[:tags] = hash[:tags].join(" ") fields = [:num, :title, :date, :pubdate, :views, :tags] f2 = File.new(fname2, "w") fields.each {|fld| f2.puts "#{fld}: #{hash[fld]}" } f2.close end |