Class: RuneBlog::ViewPost
- Inherits:
-
Object
- Object
- RuneBlog::ViewPost
- Defined in:
- lib/post.rb
Instance Attribute Summary collapse
-
#aslug ⇒ Object
Returns the value of attribute aslug.
-
#blog ⇒ Object
Returns the value of attribute blog.
-
#date ⇒ Object
Returns the value of attribute date.
-
#nslug ⇒ Object
Returns the value of attribute nslug.
-
#num ⇒ Object
Returns the value of attribute num.
-
#path ⇒ Object
Returns the value of attribute path.
-
#teaser_text ⇒ Object
Returns the value of attribute teaser_text.
-
#title ⇒ Object
Returns the value of attribute title.
-
#view ⇒ Object
Returns the value of attribute view.
Class Method Summary collapse
Instance Method Summary collapse
- #get_dirs ⇒ Object
-
#initialize(view, postdir) ⇒ ViewPost
constructor
aslug this-is-a-post aslug_live this-is-a-post.lt3 aslug_html this-is-a-post.lt3 nslug 0001-this-is-a-post.
- #repo(subdir = "") ⇒ Object (also: #root)
- #slug(num = true, ext = "") ⇒ Object
Constructor Details
#initialize(view, postdir) ⇒ ViewPost
aslug this-is-a-post
aslug_live this-is-a-post.lt3
aslug_html this-is-a-post.lt3
nslug 0001-this-is-a-post
slug(:num, ext = "")
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/post.rb', line 156 def initialize(view, postdir) log!(enter: __method__, args: [view, postdir], level: 3) # Assumes already parsed/processed @blog = RuneBlog.blog || raise(NoBlogAccessor) @path = postdir.dup @nslug = @path.split("/").last @aslug = @nslug[5..-1] fname = "#{postdir}/teaser.txt" # ??? @teaser_text = File.read(fname).chomp Dir.chdir(postdir) do = @blog. @title = .title @date = .pubdate end rescue => err STDERR.puts "--- #{err}" STDERR.puts " #{err.backtrace.join("\n ")}" if err.respond_to?(:backtrace) end |
Instance Attribute Details
#aslug ⇒ Object
Returns the value of attribute aslug.
86 87 88 |
# File 'lib/post.rb', line 86 def aslug @aslug end |
#blog ⇒ Object
Returns the value of attribute blog.
86 87 88 |
# File 'lib/post.rb', line 86 def blog @blog end |
#date ⇒ Object
Returns the value of attribute date.
87 88 89 |
# File 'lib/post.rb', line 87 def date @date end |
#nslug ⇒ Object
Returns the value of attribute nslug.
86 87 88 |
# File 'lib/post.rb', line 86 def nslug @nslug end |
#num ⇒ Object
Returns the value of attribute num.
86 87 88 |
# File 'lib/post.rb', line 86 def num @num end |
#path ⇒ Object
Returns the value of attribute path.
87 88 89 |
# File 'lib/post.rb', line 87 def path @path end |
#teaser_text ⇒ Object
Returns the value of attribute teaser_text.
87 88 89 |
# File 'lib/post.rb', line 87 def @teaser_text end |
#title ⇒ Object
Returns the value of attribute title.
87 88 89 |
# File 'lib/post.rb', line 87 def title @title end |
#view ⇒ Object
Returns the value of attribute view.
86 87 88 |
# File 'lib/post.rb', line 86 def view @view end |
Class Method Details
.make(blog:, view:, nslug:) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/post.rb', line 89 def self.make(blog:, view:, nslug:) raise NoNumericPrefix(nslug) unless nslug =~ /^\d{4}-/ raise NoExtensionExpected(nslug) if nslug.end_with?(".lt3") || nslug.end_with?(".html") view = view.to_s view.define_singleton_method :path do |subdir = ""| str = blog.root/:views/view str << "/#{subdir}" unless subdir.empty? str end view.define_singleton_method :standard do |subdir = ""| str = blog.root/:views/view/:themes/:standard str << "/#{subdir}" unless subdir.empty? str end view.define_singleton_method :postdir do |file = ""| file = file.to_s str = blog.root/:views/view/:posts/nslug str = str/file unless file.empty? str end view.define_singleton_method :remote do |dir: "", file: ""| subdir = subdir.to_s file = file.to_s str = blog.root/:views/view/:remote str = str/subdir unless subdir.empty? str = str/file unless file.empty? str end obj = RuneBlog::ViewPost.new(view, nslug) obj.blog = blog obj.view = view obj.nslug = nslug obj.aslug = nslug[5..-1] obj.num = nslug[0..3] obj end |
Instance Method Details
#get_dirs ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/post.rb', line 176 def get_dirs log!(enter: __method__, args: [view, postdir], level: 3) fname = File.basename(draft) noext = fname.sub(/.lt3$/, "") vdir = @root/:views/view dir = vdir/:posts/noext + "/" Dir.mkdir(dir) unless Dir.exist?(dir) system!("cp #{draft} #{dir}") viewdir, slugdir, aslug = vdir, dir, noext[5..-1] theme = viewdir/:themes/:standard [noext, viewdir, slugdir, aslug, theme] end |
#repo(subdir = "") ⇒ Object Also known as: root
126 127 128 129 130 131 132 133 134 |
# File 'lib/post.rb', line 126 def repo(subdir = "") subdir = subdir.to_s unless subdir.empty? raise "Expected 'posts' or 'drafts'" unless %w[posts drafts].include?(subdir) end str = blog.root str = str/subdir unless subdir.empty? str end |
#slug(num = true, ext = "") ⇒ Object
138 139 140 141 142 143 144 145 |
# File 'lib/post.rb', line 138 def slug(num = true, ext = "") ext = ext.to_s str = "" str << @num << "-" if num str << @aslug str << ext str end |