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


178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/post.rb', line 178

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.



108
109
110
# File 'lib/post.rb', line 108

def aslug
  @aslug
end

#blogObject

Returns the value of attribute blog.



108
109
110
# File 'lib/post.rb', line 108

def blog
  @blog
end

#dateObject

Returns the value of attribute date.



109
110
111
# File 'lib/post.rb', line 109

def date
  @date
end

#nslugObject

Returns the value of attribute nslug.



108
109
110
# File 'lib/post.rb', line 108

def nslug
  @nslug
end

#numObject

Returns the value of attribute num.



108
109
110
# File 'lib/post.rb', line 108

def num
  @num
end

#pathObject

Returns the value of attribute path.



109
110
111
# File 'lib/post.rb', line 109

def path
  @path
end

#teaser_textObject

Returns the value of attribute teaser_text.



109
110
111
# File 'lib/post.rb', line 109

def teaser_text
  @teaser_text
end

#titleObject

Returns the value of attribute title.



109
110
111
# File 'lib/post.rb', line 109

def title
  @title
end

#viewObject

Returns the value of attribute view.



108
109
110
# File 'lib/post.rb', line 108

def view
  @view
end

Class Method Details

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



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/post.rb', line 111

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



197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/post.rb', line 197

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



148
149
150
151
152
153
154
155
156
# File 'lib/post.rb', line 148

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



160
161
162
163
164
165
166
167
# File 'lib/post.rb', line 160

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