runeblog 0.0.82 → 0.0.83

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2691b40f636554604986a978b477b1696171cf2
4
- data.tar.gz: 2cef5f6ebc60afc93e125453b6614589e3f6a420
3
+ metadata.gz: 91e43d12b26a11fa3a918c8770f677a5f22f744e
4
+ data.tar.gz: ed5d4b517cb59294fc4a632d686f5c8e71a0d06f
5
5
  SHA512:
6
- metadata.gz: 6e2850ad2ae3f999e155214e9bfd76ad83d5dd814f23cbb711a5aafb5d08524453da8bdacba4f0d747f6a1a35249f57c5467633a89351dcee47fd6381eeaf58e
7
- data.tar.gz: 50fc4ef26de135a92fa08f860be97fb04999fe2bbe15ef21ba44683a4de9fa853fa6bfb54c4410cfc04b6483acca62748e9bfb4804d8babd04057464c666e89d
6
+ metadata.gz: 6ad7d9bb119e863f66c786a3e06152c9eb2b64725670d7d2f90e27b8ce3a3a86301e0e4020903ac24fd2124241234f49044db1003b062ef4dd41cc10657bfb63
7
+ data.tar.gz: e517a33878737d6ae901423a9869f5b5cbd13089e01d2f7c313aeb16c9f2e35174376e1eb5780429b7893f3af969c0fecf1529b3e6494516f236c98b5f6974e8
data/lib/helpers-blog.rb CHANGED
@@ -1,42 +1,94 @@
1
- def create_dir(dir) # FIXME move later
2
- cmd = "mkdir -p #{dir} >/dev/null 2>&1"
3
- result = system(cmd)
4
- raise "Can't create #{dir}" unless result
5
- end
6
-
7
- def interpolate(str)
8
- wrap = "<<-EOS\n#{str}\nEOS"
9
- eval wrap
10
- end
1
+ module RuneBlog::Helpers
11
2
 
12
- def error(err) # FIXME - this is duplicated
13
- str = "\n Error: #{err}"
14
- puts str
15
- puts err.backtrace # [0]
16
- end
3
+ def read_config(file, *syms)
4
+ lines = File.readlines(file).map(&:chomp)
5
+ obj = OpenStruct.new
6
+ lines.each do |line|
7
+ key, val = line.split(" ", 2)
8
+ key = key[0..-2] # remove colon
9
+ obj.send(key+"=", val)
10
+ end
11
+ return obj if syms.empty?
12
+ vals = []
13
+ syms.each {|sym| vals << obj.send(sym) }
14
+ return vals
15
+ rescue => err
16
+ puts "Something hit the fan: #{err}"
17
+ puts err.backtrace
18
+ exit
19
+ end
17
20
 
18
- def read_config(file, *syms)
19
- lines = File.readlines(file).map(&:chomp)
20
- obj = OpenStruct.new
21
- lines.each do |line|
22
- key, val = line.split(" ", 2)
23
- key = key[0..-2] # remove colon
24
- obj.send(key+"=", val)
25
- end
26
- @deployer = RuneBlog::Deployment.new(obj)
27
- obj
28
- rescue => err
29
- puts "Something hit the fan: #{err}"
30
- puts err.backtrace
31
- exit
32
- end
21
+ def huh_read_config(file, *syms)
22
+ lines = File.readlines(file).map(&:chomp)
23
+ obj = OpenStruct.new
24
+ lines.each do |line|
25
+ key, val = line.split(" ", 2)
26
+ key = key[0..-2] # remove colon
27
+ obj.send(key+"=", val)
28
+ end
29
+ @deployer = RuneBlog::Deployment.new(obj)
30
+ obj
31
+ rescue => err
32
+ puts "Something hit the fan: #{err}"
33
+ puts err.backtrace
34
+ exit
35
+ end
33
36
 
34
- def write_config(obj, file)
35
- hash = obj.to_h
36
- File.open(file, "w") do |f|
37
- hash.each_pair do |key, val|
38
- f.puts "#{key}: #{val}"
37
+ def write_config(obj, file)
38
+ hash = obj.to_h
39
+ File.open(file, "w") do |f|
40
+ hash.each_pair do |key, val|
41
+ f.puts "#{key}: #{val}"
42
+ end
39
43
  end
40
44
  end
41
- end
42
45
 
46
+ def get_views # read from filesystem
47
+ dirs = subdirs("#@root/views/").sort
48
+ dirs.map {|name| RuneBlog::View.new(name) }
49
+ end
50
+
51
+ def new_dotfile(root: "data", current_view: "no_default", editor: "vi")
52
+ x = OpenStruct.new
53
+ x.root, x.current_view, x.editor = root, current_view, editor
54
+ write_config(x, RuneBlog::DotFile)
55
+ end
56
+
57
+ def new_sequence
58
+ File.write("sequence", 0)
59
+ File.write("VERSION", "#{RuneBlog::VERSION}\n" +
60
+ "Blog created: " + Time.now.to_s)
61
+ end
62
+
63
+ def subdirs(dir)
64
+ dirs = Dir.entries(dir) - %w[. ..]
65
+ dirs.reject! {|x| ! File.directory?("#@root/views/#{x}") }
66
+ dirs
67
+ end
68
+
69
+ def find_src_slugs
70
+ files = Dir.entries("#@root/src/").grep /\d{4}.*.lt3$/
71
+ files.map! {|f| File.basename(f) }
72
+ files = files.sort.reverse
73
+ files
74
+ end
75
+
76
+ def create_dir(dir)
77
+ return if File.exist?(dir) && File.directory?(dir)
78
+ cmd = "mkdir -p #{dir} >/dev/null 2>&1"
79
+ result = system(cmd)
80
+ raise "Can't create #{dir}" unless result
81
+ end
82
+
83
+ def interpolate(str)
84
+ wrap = "<<-EOS\n#{str}\nEOS"
85
+ eval wrap
86
+ end
87
+
88
+ def error(err) # Hmm, this is duplicated
89
+ str = "\n Error: #{err}"
90
+ puts str
91
+ puts err.backtrace
92
+ end
93
+
94
+ end
data/lib/post.rb CHANGED
@@ -5,6 +5,8 @@ class RuneBlog::Post
5
5
 
6
6
  attr_reader :id, :title, :date, :views, :num, :slug
7
7
 
8
+ include RuneBlog::Helpers
9
+
8
10
  def self.files(num, root)
9
11
  files = Find.find(root).to_a
10
12
  result = files.grep(/#{tag(num)}-/)
data/lib/runeblog.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'pp'
2
-
3
1
  require 'find'
4
2
  require 'yaml' # get rid of YAML later
5
3
  require 'livetext'
@@ -14,36 +12,38 @@ require 'version'
14
12
  ###
15
13
 
16
14
  class RuneBlog
15
+
16
+ DotFile = ".blog"
17
17
 
18
18
  class << self
19
19
  attr_accessor :blog
20
+ include Helpers
20
21
  end
21
22
 
22
23
  attr_reader :root, :views, :sequence
23
24
  attr_accessor :view # overridden
24
25
 
26
+ include Helpers
27
+
25
28
  def self.create_new_blog(dir = "data")
26
- x = OpenStruct.new
27
- x.root, x.current_view, x.editor = dir, "no_default", "vi"
28
- write_config(x, ".blog")
29
+ new_dotfile(root: dir)
29
30
  create_dir(dir)
30
31
  Dir.chdir(dir) do
31
32
  create_dir("views")
32
33
  create_dir("assets")
33
34
  create_dir("src")
34
- File.write("sequence", 0)
35
- File.write("VERSION", "#{RuneBlog::VERSION}\nBlog created: " + Time.now.to_s )
35
+ new_sequence
36
36
  end
37
37
  end
38
38
 
39
- def initialize(cfg_file = ".blog") # assumes existing blog
40
- # Crude - FIXME later - What views are there? Deployment, etc.
39
+ def initialize # assumes existing blog
40
+ # Crude - FIXME later -
41
+ # What views are there? Deployment, etc.
41
42
  self.class.blog = self # Weird. Like a singleton - dumbass circular dependency?
42
- obj = read_config(cfg_file)
43
- vals = obj.to_h.values_at(:root, :current_view, :editor)
44
- @root, view_name, @editor = *vals
45
- @views = subdirs("#@root/views/").sort.map {|name| RuneBlog::View.new(name) }
46
- @view = str2view(view_name)
43
+ @root, @view_name, @editor =
44
+ read_config(DotFile, :root, :current_view, :editor)
45
+ @views = get_views
46
+ @view = str2view(@view_name)
47
47
  @sequence = get_sequence
48
48
  end
49
49
 
@@ -89,7 +89,7 @@ class RuneBlog
89
89
  end
90
90
 
91
91
  def self.exist?
92
- File.exist?(".blog")
92
+ File.exist?(DotFile)
93
93
  end
94
94
 
95
95
  def create_view(arg)
@@ -172,7 +172,7 @@ class RuneBlog
172
172
  def change_view(view)
173
173
  x = OpenStruct.new
174
174
  x.root, x.current_view, x.editor = @root, view, @editor # dumb - FIXME later
175
- write_config(x, ".blog")
175
+ write_config(x, DotFile)
176
176
  self.view = view # error checking?
177
177
  end
178
178
 
@@ -295,39 +295,5 @@ class RuneBlog
295
295
 
296
296
  private
297
297
 
298
- def subdirs(dir)
299
- raise Exception.new("hell") if dir == "/views/"
300
- dirs = Dir.entries(dir) - %w[. ..]
301
- dirs.reject! {|x| ! File.directory?("#@root/views/#{x}") }
302
- dirs
303
- rescue => err
304
- p err
305
- end
306
-
307
- def find_src_slugs
308
- files = Dir.entries("#@root/src/").grep /\d{4}.*.lt3$/
309
- files.map! {|f| File.basename(f) }
310
- files = files.sort.reverse
311
- files
312
- end
313
-
314
- def create_dir(dir)
315
- return if File.exist?(dir) && File.directory?(dir)
316
- cmd = "mkdir -p #{dir} >/dev/null 2>&1"
317
- result = system(cmd)
318
- raise "Can't create #{dir}" unless result
319
- end
320
-
321
- def interpolate(str)
322
- wrap = "<<-EOS\n#{str}\nEOS"
323
- eval wrap
324
- end
325
-
326
- def error(err) # Hmm, this is duplicated
327
- str = "\n Error: #{err}"
328
- puts str
329
- puts err.backtrace
330
- end
331
-
332
298
  end
333
299
 
data/lib/skeleton.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  # skeleton
2
2
 
3
3
  class RuneBlog
4
+ module Helpers
5
+ end
6
+
4
7
  class Default
5
8
  end
6
9
 
data/lib/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  class RuneBlog
3
- VERSION = "0.0.82"
3
+ VERSION = "0.0.83"
4
4
 
5
5
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
6
6
  end
data/lib/view.rb CHANGED
@@ -5,6 +5,8 @@ class RuneBlog::View
5
5
  attr_reader :name, :state
6
6
  attr_accessor :deployer
7
7
 
8
+ include RuneBlog::Helpers
9
+
8
10
  def initialize(name)
9
11
  raise "RuneBlog.blog is not set!" if RuneBlog.blog.nil?
10
12
  @blog = RuneBlog.blog
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runeblog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.82
4
+ version: 0.0.83
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton