rack-blogengine 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c4c77afa0dea08adb6a4132ab7fb0558236f726
4
- data.tar.gz: ecea1dcb841499269f9fc4001ef1bf26c4089813
3
+ metadata.gz: 7aa9f7345a6ce8fe4d9db0a916d6fd8532717ea3
4
+ data.tar.gz: caba5a9583c222feae1ac9353afcd2795a9e0740
5
5
  SHA512:
6
- metadata.gz: 1fe14fb5518c1474c4029e6b64876c7f98264b65609b608e0613480a7de4e85f7331be316849ccdcbb604199821abf49f84b31c9c7847eb46e11366946c82f90
7
- data.tar.gz: f2089d8343898c35f138e02736f07b7adf378fcd46431e29ac9442f1f2b88b16f795ee996d754e85ba17a5b1eb736c37dfb3e2596c2bb2903c4fa0ab7820cb55
6
+ metadata.gz: fcd1c84cb6d85a0f915d01db281f7229e435fea47c77dacc0c2ca1da4a169918909c4f567d9ac4e02578ac77c7073232d964bd579cd5184a1b00d4e62cdc627c
7
+ data.tar.gz: 654e2452901577730a41e5901ac18d58fcaecf31e2ab47f249b7c2bd1a35f5d6a5d621500686bbb946c571033af5a324c776cbb1d5513ef40da0960db8cd111a
data/bin/rack-blogengine CHANGED
@@ -2,15 +2,15 @@
2
2
  require 'rack/blogengine/command_line_interface'
3
3
 
4
4
  if ARGV[0]
5
- command = ARGV[0].to_sym
5
+ command = ARGV[0].to_sym
6
6
  else
7
- command = "".to_sym
7
+ command = "".to_sym
8
8
  end
9
9
 
10
10
  target = ARGV[1]
11
11
  target = "" if !ARGV[1]
12
12
 
13
- cli = Rack::Blogengine::CommandLineInterface.new
13
+ cli = Rack::Blogengine::CommandLineInterface.new
14
14
 
15
15
  if target != ""
16
16
  cli.send(command, target)
@@ -15,8 +15,6 @@ module Rack
15
15
 
16
16
 
17
17
  # Iterate through available docs, if nothing matched return nil
18
- # TODO: Dont iterate through every doc, get requested doc from DocParser
19
- # Operators should have access to ALL available docs (title, path, html etc)
20
18
  documents.each do |doc|
21
19
  if doc[:path] == path
22
20
  route_response = {
@@ -1,5 +1,4 @@
1
1
  require 'rack'
2
- #require 'rack/attack'
3
2
  require 'rack/blogengine'
4
3
  require 'yaml'
5
4
 
@@ -55,11 +54,57 @@ module Rack
55
54
 
56
55
  # Command to generate the folder skeleton
57
56
  # @param [String] folder
57
+ # TODO: refactor this - similar functions for each set up set => outsource to a method setup()
58
58
  def generate(folder)
59
- puts "Generating folder skeleton"
60
- system("mkdir #{folder} && mkdir #{folder}/assets && mkdir #{folder}/assets/layout && mkdir #{folder}/assets/js && mkdir #{folder}/assets/style && mkdir #{folder}/assets/images")
59
+ puts "\tGenerating folder skeleton\n"
60
+ system("mkdir #{folder}")
61
+ system("mkdir #{folder}/assets")
62
+ system("mkdir #{folder}/assets/layout")
63
+ system("mkdir #{folder}/assets/js")
64
+ system("mkdir #{folder}/assets/style")
65
+ system("mkdir #{folder}/assets/images")
66
+ system("mkdir #{folder}/operator")
67
+
68
+ puts "\n\tSetting up essential Files\n"
69
+
70
+ # SET UP operator.rb
71
+ puts "\tSet up #{folder}/operator/operator.rb\n"
72
+ system("touch #{folder}/operator/operator.rb")
73
+ content = IO.read("#{::File.dirname(__FILE__)}/files/operator.rb")
74
+ ::File.open("#{folder}/operator/operator.rb", 'w') { |file| file.write(content) }
75
+
76
+ # SET UP config.yml
77
+ puts "\tSet up config.yml\n"
78
+ system("touch #{folder}/config.yml")
79
+ content = IO.read("#{::File.dirname(__FILE__)}/files/config.yml")
80
+ ::File.open("#{folder}/config.yml", 'w') { |file| file.write(content) }
81
+
82
+ # SET UP index.content
83
+ puts "\tSet up #{folder}/index.content\n"
84
+ system("touch #{folder}/index.content")
85
+ content = IO.read("#{::File.dirname(__FILE__)}/files/index.content")
86
+ ::File.open("#{folder}/index.content", 'w') { |file| file.write(content) }
87
+
88
+ # SET UP layout.html
89
+ puts "\tSet up #{folder}/assets/layout/layout.html\n"
90
+ system("touch #{folder}/assets/layout/layout.html")
91
+ content = IO.read("#{::File.dirname(__FILE__)}/files/layout.html")
92
+ ::File.open("#{folder}/assets/layout/layout.html", 'w') { |file| file.write(content) }
93
+
94
+ # SET UP style.css
95
+ puts "\tSet up #{folder}/assets/style/style.css\n"
96
+ system("touch #{folder}/assets/style/style.css")
97
+
98
+ # SET UP style.css
99
+ puts "\tSet up #{folder}/assets/js/script.js\n"
100
+ system("touch #{folder}/assets/js/script.js")
101
+
102
+ puts "\n\tSetup finished! Have Fun\n"
103
+ puts "\tTo test it type rack-blogengine run #{folder}"
61
104
  end
62
105
 
106
+ # Display Version
107
+ # return [String] VERSION
63
108
  def version?
64
109
  puts Rack::Blogengine::VERSION
65
110
  end
@@ -22,10 +22,13 @@ module Rack
22
22
  @document.path = @path
23
23
  @document.html = @html
24
24
  @document.title = @title
25
+ @document.date = @date
25
26
 
26
27
  documents << @document
27
28
  end
28
29
 
30
+ sort documents
31
+
29
32
  # Has to exec operator after all docs were read, so documents are available for operators (list all docs, etc...)
30
33
  documents.each do |document|
31
34
  document.exec_content_operator(documents, @target)
@@ -39,7 +42,7 @@ module Rack
39
42
  end
40
43
 
41
44
  # Get File Contents (path, title, content)
42
- # @param file
45
+ # @param [String] file
43
46
  def self.getFileContents(file)
44
47
  content_file = ::File.open("#{@target}/#{file}");
45
48
  content = content_file.read
@@ -48,6 +51,7 @@ module Rack
48
51
  content["/path"] = "/close"
49
52
  content["/title"] = "/close"
50
53
  content["/content"] = "/close"
54
+ content["/date"] = "/close"
51
55
 
52
56
  contentarray = content.split("[/close]")
53
57
 
@@ -59,27 +63,47 @@ module Rack
59
63
 
60
64
  if contentblock.include? "[title]:"
61
65
  contentblock["[title]:"] = ""
62
- @title = contentblock
66
+ @title = contentblock.strip
63
67
  end
64
68
 
65
69
  if contentblock.include? "[content]:"
66
70
  contentblock["[content]:"] = ""
67
- @content = contentblock
71
+ @content = contentblock.strip
72
+ end
73
+
74
+ if contentblock.include? "[date]:"
75
+ contentblock["[date]:"] = ""
76
+ #TODO: Generate Date out of [date] string
77
+ #@date = Date.new(..splitted date string..)
78
+ @date = contentblock.strip
68
79
  end
69
80
  end
70
81
  end
71
82
 
72
83
  # Replace layout placeholder with content from .content file
73
- # @param layout
84
+ # @param [String] layout
74
85
  # return [String] html placeholder replaced with content
75
86
  def self.fillFileContents(layout)
76
87
  html = layout.dup
77
88
 
78
89
  html.gsub! "{title}", @title
79
90
  html["{content}"] = @content
91
+ html.gsub! "{date}", @date
80
92
 
81
93
  return html
82
94
  end
95
+
96
+ # Sort documents array by date of each documenthash
97
+ # @param [Array] documents
98
+ # return [Array] documents (sorted)
99
+ # Should it be sorted in Core or in the operator??
100
+ def self.sort(documents)
101
+ documents.sort! do | a, b |
102
+ a.date.to_time.to_i <=> b.date.to_time.to_i
103
+ end
104
+
105
+ return documents
106
+ end
83
107
  end
84
108
  end
85
109
  end
@@ -1,12 +1,14 @@
1
1
  module Rack
2
2
  module Blogengine
3
3
  class Document
4
- attr_accessor :path, :html, :title
4
+ attr_accessor :path, :html, :title, :date
5
5
 
6
6
  def to_hash
7
7
  hash = {}
8
- instance_variables.each do |var|
9
- hash[var.to_s.delete("@").to_sym] = instance_variable_get(var) unless var.to_s == "@title"
8
+ instance_variables.each do |var|
9
+ unless var.to_s == "@title" || var.to_s == "@date"
10
+ hash[var.to_s.delete("@").to_sym] = instance_variable_get(var)
11
+ end
10
12
  end
11
13
  hash
12
14
  end
@@ -0,0 +1,2 @@
1
+ Port: 3000
2
+ Server: "webrick"
@@ -0,0 +1,6 @@
1
+ [path]:[/path]
2
+ [title]:INDEX[/title]
3
+ [date]:2013,01,01[/date]
4
+ [content]:
5
+ <h2>This is the Index Page</h2>
6
+ [/content]
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>{title}</title>
5
+ </head>
6
+ <body>
7
+ {date}
8
+ {content}
9
+ </body>
10
+ </html>
@@ -0,0 +1,3 @@
1
+ module UserOperator
2
+ #define your operators here
3
+ end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module Blogengine
3
- VERSION = "0.1.6".freeze
3
+ VERSION = "0.1.7".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-blogengine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benny1992
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-09 00:00:00.000000000 Z
11
+ date: 2014-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,6 +86,10 @@ files:
86
86
  - lib/rack/blogengine/command_line_interface.rb
87
87
  - lib/rack/blogengine/doc_parser.rb
88
88
  - lib/rack/blogengine/document.rb
89
+ - lib/rack/blogengine/files/config.yml
90
+ - lib/rack/blogengine/files/index.content
91
+ - lib/rack/blogengine/files/layout.html
92
+ - lib/rack/blogengine/files/operator.rb
89
93
  - lib/rack/blogengine/operator.rb
90
94
  - lib/rack/blogengine/version.rb
91
95
  - rack-blogengine.gemspec