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


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 
    meta = @blog.
    @title = meta.title
    @date  = meta.pubdate
  end
rescue => err
  STDERR.puts "--- #{err}"
  STDERR.puts "    #{err.backtrace.join("\n  ")}" if err.respond_to?(:backtrace)
end

Instance Attribute Details

#aslugObject

Returns the value of attribute aslug.



86
87
88
# File 'lib/post.rb', line 86

def aslug
  @aslug
end

#blogObject

Returns the value of attribute blog.



86
87
88
# File 'lib/post.rb', line 86

def blog
  @blog
end

#dateObject

Returns the value of attribute date.



87
88
89
# File 'lib/post.rb', line 87

def date
  @date
end

#nslugObject

Returns the value of attribute nslug.



86
87
88
# File 'lib/post.rb', line 86

def nslug
  @nslug
end

#numObject

Returns the value of attribute num.



86
87
88
# File 'lib/post.rb', line 86

def num
  @num
end

#pathObject

Returns the value of attribute path.



87
88
89
# File 'lib/post.rb', line 87

def path
  @path
end

#teaser_textObject

Returns the value of attribute teaser_text.



87
88
89
# File 'lib/post.rb', line 87

def teaser_text
  @teaser_text
end

#titleObject

Returns the value of attribute title.



87
88
89
# File 'lib/post.rb', line 87

def title
  @title
end

#viewObject

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_dirsObject



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