Class: RuneBlog::ViewPost

Inherits:
Object
  • Object
show all
Defined in:
lib/post.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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 = "")


193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/post.rb', line 193

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
  # FIXME dumb hacks...
  mdfile = postdir/"metadata.txt"
  lines = File.readlines(mdfile)
  @title = lines.grep(/title:/).first[7..-1].chomp
  @date  = lines.grep(/pubdate:/).first[9..-1].chomp
# print "-- date = #{@date.inspect} "; gets
rescue => err
  STDERR.puts "--- #{err}\n #{err.backtrace.join("\n  ")}"
end

Instance Attribute Details

#aslugObject

Returns the value of attribute aslug.



123
124
125
# File 'lib/post.rb', line 123

def aslug
  @aslug
end

#blogObject

Returns the value of attribute blog.



123
124
125
# File 'lib/post.rb', line 123

def blog
  @blog
end

#dateObject

Returns the value of attribute date.



124
125
126
# File 'lib/post.rb', line 124

def date
  @date
end

#nslugObject

Returns the value of attribute nslug.



123
124
125
# File 'lib/post.rb', line 123

def nslug
  @nslug
end

#numObject

Returns the value of attribute num.



123
124
125
# File 'lib/post.rb', line 123

def num
  @num
end

#pathObject

Returns the value of attribute path.



124
125
126
# File 'lib/post.rb', line 124

def path
  @path
end

#teaser_textObject

Returns the value of attribute teaser_text.



124
125
126
# File 'lib/post.rb', line 124

def teaser_text
  @teaser_text
end

#titleObject

Returns the value of attribute title.



124
125
126
# File 'lib/post.rb', line 124

def title
  @title
end

#viewObject

Returns the value of attribute view.



123
124
125
# File 'lib/post.rb', line 123

def view
  @view
end

Class Method Details

.make(blog:, view:, nslug:) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/post.rb', line 126

def self.make(blog:, view:, nslug:)
  raise "No numeric prefix on #{nslug}" unless nslug =~ /^\d{4}-/
  raise "Not expecting an extension" 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_dirsObject



212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/post.rb', line 212

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



163
164
165
166
167
168
169
170
171
# File 'lib/post.rb', line 163

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



175
176
177
178
179
180
181
182
# File 'lib/post.rb', line 175

def slug(num = true, ext = "")
  ext = ext.to_s
  str = ""
  str << @num << "-" if num
  str << @aslug 
  str << ext
  str
end