gidget 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,20 +1,20 @@
1
- Copyright (c) 2010 hasmanytrees
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2010 hasmanytrees
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,83 +1,83 @@
1
- = gidget
2
-
3
- _The smallest taco-loving blog engine in the world!_ (anyone remember 'Yo quiero Taco Bell'?)
4
-
5
- Gidget is a minimalist blog engine designed to run on Heroku with a Git-based workflow. It is built upon Sinatra and uses haml and rdiscount for templating and markup. It was largely inspired by Toto, however Gidget is built on top of a DSL to minimize and simplify the code.
6
-
7
- == Basic Structure
8
-
9
- * Sinatra based server
10
- * A singleton array containing post information (the body of a post is lazily-loaded)
11
- * A class to handle post information
12
-
13
- == Routing
14
-
15
- * / - an index template with access to the full array of posts
16
- * /2010 - an archive template with all access to all posts from the specified year
17
- * /2010/11 - an archive template with access to all posts from the specified year/month
18
- * /2010/11/19 - an archive template with access to all posts from the specified year/month/day
19
- * /2010/11/19/first-post - a post template with access to the full array of posts and the current post index
20
- * /some-special-page - a page template with access to the full array of posts
21
-
22
- == Post Creation
23
-
24
- Posts are simply .txt files located under a folder named posts located off the root of the web app. Text files contain two sections of data. The first is metadata including at least a title and date as such:
25
-
26
- title: My great post title
27
- date: 2010-11-19
28
-
29
- _Hello World!_ This is my first blog post!
30
-
31
- The second section is the body of the post and uses markdown as it's markup language. The two sections should be separated by an empty line.
32
-
33
- File name and structure (other than the .txt extension) don't matter. Gidget will determine request paths based on the date and title metadata and sort them accordingly.
34
-
35
- == Getting Started
36
-
37
- The following comands install the Gidget gem, create a Gidget app, and then start the app:
38
-
39
- gem install gidget
40
- gidget my-gidget-app
41
- cd my-gidget-app
42
- rackup
43
-
44
- At this point you should be able to view your blog by visiting: http://localhost:9292
45
-
46
- == Adding Source Control
47
-
48
- Before you can host yoru app on Heroku, you must be using Git for source control. Run the following from your app directory to create a new git repository and add all your app code to it:
49
-
50
- git init
51
- git add *
52
- git commit -a -m "Initial load"
53
-
54
- == Deploy To Heroku
55
-
56
- In order to deploy an app to Heroku you must have an account with them. Once you have your account, deploying to Heroku is super easy thanks to their gem:
57
-
58
- gem install heroku
59
- heroku create
60
- git push heroku master
61
- heroku open
62
-
63
- Congrats! You now have your own blog running on the internets!
64
-
65
- == TO BE DONE
66
-
67
- * Possibly add a paging route to allow /page/1 type usage. Need to determine best way of handling options/setting such as page_size.
68
-
69
- == Contributing to gidget
70
-
71
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
72
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
73
- * Fork the project
74
- * Start a feature/bugfix branch
75
- * Commit and push until you are happy with your contribution
76
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
77
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
78
-
79
- == Copyright
80
-
81
- Copyright (c) 2010 hasmanytrees. See LICENSE.txt for
82
- further details.
83
-
1
+ = gidget
2
+
3
+ _The smallest taco-loving blog engine in the world!_ (anyone remember 'Yo quiero Taco Bell'?)
4
+
5
+ Gidget is a minimalist blog engine designed to run on Heroku with a Git-based workflow. It is built upon Sinatra and uses haml and rdiscount for templating and markup. It was largely inspired by Toto, however Gidget is built on top of a DSL to minimize and simplify the code.
6
+
7
+ == Basic Structure
8
+
9
+ * Sinatra based server
10
+ * A singleton array containing post information (the body of a post is lazily-loaded)
11
+ * A class to handle post information
12
+
13
+ == Routing
14
+
15
+ * / - an index template with access to the full array of posts
16
+ * /2010 - an archive template with all access to all posts from the specified year
17
+ * /2010/11 - an archive template with access to all posts from the specified year/month
18
+ * /2010/11/19 - an archive template with access to all posts from the specified year/month/day
19
+ * /2010/11/19/first-post - a post template with access to the full array of posts and the current post index
20
+ * /some-special-page - a page template with access to the full array of posts
21
+
22
+ == Post Creation
23
+
24
+ Posts are simply .txt files located under a folder named posts located off the root of the web app. Text files contain two sections of data. The first is metadata including at least a title and date as such:
25
+
26
+ title: My great post title
27
+ date: 2010-11-19
28
+
29
+ _Hello World!_ This is my first blog post!
30
+
31
+ The second section is the body of the post and uses markdown as it's markup language. The two sections should be separated by an empty line.
32
+
33
+ File name and structure (other than the .txt extension) don't matter. Gidget will determine request paths based on the date and title metadata and sort them accordingly.
34
+
35
+ == Getting Started
36
+
37
+ The following comands install the Gidget gem, create a Gidget app, and then start the app:
38
+
39
+ gem install gidget
40
+ gidget my-gidget-app
41
+ cd my-gidget-app
42
+ rackup
43
+
44
+ At this point you should be able to view your blog by visiting: http://localhost:9292
45
+
46
+ == Adding Source Control
47
+
48
+ Before you can host yoru app on Heroku, you must be using Git for source control. Run the following from your app directory to create a new git repository and add all your app code to it:
49
+
50
+ git init
51
+ git add *
52
+ git commit -a -m "Initial load"
53
+
54
+ == Deploy To Heroku
55
+
56
+ In order to deploy an app to Heroku you must have an account with them. Once you have your account, deploying to Heroku is super easy thanks to their gem:
57
+
58
+ gem install heroku
59
+ heroku create
60
+ git push heroku master
61
+ heroku open
62
+
63
+ Congrats! You now have your own blog running on the internets!
64
+
65
+ == TO BE DONE
66
+
67
+ * Possibly add a paging route to allow /page/1 type usage. Need to determine best way of handling options/setting such as page_size.
68
+
69
+ == Contributing to gidget
70
+
71
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
72
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
73
+ * Fork the project
74
+ * Start a feature/bugfix branch
75
+ * Commit and push until you are happy with your contribution
76
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
77
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
78
+
79
+ == Copyright
80
+
81
+ Copyright (c) 2010 hasmanytrees. See LICENSE.txt for
82
+ further details.
83
+
@@ -1,2 +1,2 @@
1
- source "http://rubygems.org"
2
- gem "gidget"
1
+ source "http://rubygems.org"
2
+ gem "gidget"
@@ -1,13 +1,18 @@
1
- require 'rubygems'
2
- require 'bundler'
3
-
4
- Bundler.require
5
-
6
- gidget = Gidget::Server.new do
7
- set :title, "hasmanytrees"
8
- set :author, "Forrest Robertson"
9
- set :summary_size, 100
10
- set :page_size, 10
11
- end
12
-
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.require
5
+
6
+ # The following lines are used for debug during gem development
7
+ # Comment out previous Bundler.require line to avoid conflicts during development
8
+ #$: << File.expand_path("../lib")
9
+ #require 'gidget'
10
+
11
+ gidget = Gidget::Server.new do
12
+ set :title, "My Awesome Blog"
13
+ set :author, "Your Name Goes Here"
14
+ set :summary_size, 100
15
+ set :page_size, 10
16
+ end
17
+
13
18
  run gidget
@@ -1,4 +1,4 @@
1
- title: This is the awesome title to a post
2
- date: 2010-11-15
3
-
1
+ title: This is the awesome title to a post
2
+ date: 2010-11-15
3
+
4
4
  Hello world!
@@ -1,9 +1,9 @@
1
- !!! 5
2
- %html
3
- %head
4
- %title My Awesome Site
5
- %body
6
- %header
7
- %h1 About
8
- %article
1
+ !!! 5
2
+ %html
3
+ %head
4
+ %title= settings.title
5
+ %body
6
+ %header
7
+ %h1 About
8
+ %article
9
9
  %p This blog is run by Gidget.
@@ -1,9 +1,9 @@
1
- !!! 5
2
- %html
3
- %head
4
- %title My Awesome Site
5
- %body
6
- %header
7
- %h1 My Blog
8
- %article
1
+ !!! 5
2
+ %html
3
+ %head
4
+ %title= settings.title
5
+ %body
6
+ %header
7
+ %h1 My Blog
8
+ %article
9
9
  %h1= "I found #{posts.size} posts!"
@@ -1,10 +1,10 @@
1
- !!! 5
2
- %html
3
- %head
4
- %title My Awesome Site
5
- %body
6
- %header
7
- %h1 My Blog
8
- %article
9
- %h1= posts[0][:title]
10
- = markdown(posts[0][:body])
1
+ !!! 5
2
+ %html
3
+ %head
4
+ %title= settings.title
5
+ %body
6
+ %header
7
+ %h1 My Blog
8
+ %article
9
+ %h1= posts[0].title
10
+ = posts[0].body
@@ -1,10 +1,10 @@
1
- !!! 5
2
- %html
3
- %head
4
- %title My Awesome Site
5
- %body
6
- %header
7
- %h1 My Blog
8
- %article
9
- %h1= posts[index][:title]
10
- = markdown(posts[index][:body])
1
+ !!! 5
2
+ %html
3
+ %head
4
+ %title= settings.title
5
+ %body
6
+ %header
7
+ %h1 My Blog
8
+ %article
9
+ %h1= posts[index].title
10
+ = posts[index].body
data/bin/gidget CHANGED
@@ -1,35 +1,35 @@
1
- #!/usr/bin/env ruby
2
- require 'FileUtils'
3
-
4
-
5
- class App
6
- def initialize(arguments, stdin)
7
- @arguments = arguments
8
- end
9
-
10
-
11
- def run
12
- source = File.expand_path(File.join(File.dirname(__FILE__), '../_stub_'))
13
- destination = File.expand_path(File.join(Dir.pwd, @arguments[0]))
14
-
15
- puts "Creating gidget app stub in destination '#{destination}'"
16
-
17
- if (!File.directory? destination)
18
- print " Creating destination ... "
19
- FileUtils.mkdir_p(destination)
20
- puts "done."
21
- else
22
- puts " Destination exists."
23
- end
24
-
25
- print " Copying stub ... "
26
- FileUtils.cp_r(source + "/.", destination)
27
- puts "done."
28
-
29
- puts "Done."
30
- end
31
- end
32
-
33
-
34
- app = App.new(ARGV, STDIN)
1
+ #!/usr/bin/env ruby
2
+ require 'FileUtils'
3
+
4
+
5
+ class App
6
+ def initialize(arguments, stdin)
7
+ @arguments = arguments
8
+ end
9
+
10
+
11
+ def run
12
+ source = File.expand_path(File.join(File.dirname(__FILE__), '../_stub_'))
13
+ destination = File.expand_path(File.join(Dir.pwd, @arguments[0]))
14
+
15
+ puts "Creating gidget app stub in destination '#{destination}'"
16
+
17
+ if (!File.directory? destination)
18
+ print " Creating destination ... "
19
+ FileUtils.mkdir_p(destination)
20
+ puts "done."
21
+ else
22
+ puts " Destination exists."
23
+ end
24
+
25
+ print " Copying stub ... "
26
+ FileUtils.cp_r(source + "/.", destination)
27
+ puts "done."
28
+
29
+ puts "Done."
30
+ end
31
+ end
32
+
33
+
34
+ app = App.new(ARGV, STDIN)
35
35
  app.run
@@ -1,10 +1,10 @@
1
- class String
2
- def slugize
3
- self.downcase.gsub(/&/, 'and').gsub(/\s+/, '-').gsub(/[^a-z0-9-]/, '')
4
- end
5
-
6
-
7
- def humanize
8
- self.capitalize.gsub(/[-_]+/, ' ')
9
- end
1
+ class String
2
+ def slugize
3
+ self.downcase.gsub(/&/, 'and').gsub(/\s+/, '-').gsub(/[^a-z0-9-]/, '')
4
+ end
5
+
6
+
7
+ def humanize
8
+ self.capitalize.gsub(/[-_]+/, ' ')
9
+ end
10
10
  end
@@ -1,34 +1,52 @@
1
- require 'yaml'
2
- require 'gidget/ext'
3
-
4
-
5
- module Gidget
6
- class Post < Hash
7
- def initialize(file_path)
8
- file = File.open(file_path, "r")
9
-
10
- # read the first paragraph and load it into a Hash with symbols as keys
11
- self.update(YAML.load(file.gets("")).inject({}) { |h, (k,v)| h.merge(k.to_sym => v) })
12
-
13
- file.close()
14
-
15
- self[:file_path] = file_path
16
-
17
- self[:request_path] = self[:date].strftime("/%Y/%m/%d/") + self[:title].slugize
18
-
19
- self[:body] = lambda {
20
- file = File.open(file_path, "r")
21
-
22
- # ignore the first paragraph
23
- file.gets("")
24
-
25
- # capture the rest of the file
26
- body = file.gets(nil)
27
-
28
- file.close()
29
-
30
- return body
31
- }
32
- end
33
- end
1
+ require 'yaml'
2
+ require 'rdiscount'
3
+ require 'gidget/ext'
4
+
5
+
6
+ module Gidget
7
+ class Post
8
+ attr_reader :file_path
9
+ attr_reader :request_path
10
+ attr_reader :meta_data
11
+
12
+
13
+ def initialize(file_path)
14
+ @file_path = file_path
15
+
16
+ begin
17
+ file = File.open(@file_path, "r")
18
+
19
+ # read the first paragraph and load it into a Hash with symbols as keys
20
+ @meta_data = YAML.load(file.gets("")).inject({}) { |h, (k,v)| h.merge(k.to_sym => v) }
21
+ ensure
22
+ file.close()
23
+ end
24
+
25
+ @request_path = @meta_data[:date].strftime("/%Y/%m/%d/") + @meta_data[:title].slugize
26
+ end
27
+
28
+
29
+ def body
30
+ begin
31
+ file = File.open(@file_path, "r")
32
+
33
+ # ignore the first paragraph
34
+ file.gets("")
35
+
36
+ # read the rest of the file and process it's markdown
37
+ RDiscount.new(file.gets(nil)).to_html
38
+ ensure
39
+ file.close()
40
+ end
41
+ end
42
+
43
+
44
+ def method_missing(m, *args, &block)
45
+ if (@meta_data.has_key?(m))
46
+ return @meta_data[m]
47
+ else
48
+ super
49
+ end
50
+ end
51
+ end
34
52
  end
@@ -1,22 +1,24 @@
1
- require 'singleton'
2
- require 'gidget/post'
3
-
4
-
5
- module Gidget
6
- class PostIndex < Array
7
- include Singleton
8
-
9
-
10
- def initialize
11
- paths = Dir.glob("posts/**/*.txt")
12
-
13
- paths.each { |file_path|
14
- self << Post.new(file_path)
15
- }
16
-
17
- self.replace self.sort_by { |p| p[:request_path] }.reverse!
18
-
19
- puts "Post Index created, size = " + self.size.to_s
20
- end
21
- end
1
+ require 'singleton'
2
+ require 'gidget/post'
3
+
4
+
5
+ module Gidget
6
+ class PostIndex < Array
7
+ include Singleton
8
+
9
+
10
+ def initialize
11
+ paths = Dir.glob("posts/**/*.txt")
12
+
13
+ # add all the posts to the array
14
+ paths.each { |file_path|
15
+ self << Post.new(file_path)
16
+ }
17
+
18
+ # sort the array by the request path, descending (newest by date will be first)
19
+ self.replace self.sort_by { |p| p.request_path }.reverse!
20
+
21
+ puts "Post Index created, size = " + self.size.to_s
22
+ end
23
+ end
22
24
  end
@@ -1,64 +1,63 @@
1
- require 'sinatra/base'
2
- require 'haml'
3
- require 'rdiscount'
4
- require 'gidget/post_index'
5
-
6
-
7
- module Gidget
8
- class Server < Sinatra::Base
9
- set :haml, :format => :html5
10
-
11
- set :page_size, 5
12
-
13
- def initialize(app=nil, &block)
14
- super(app, &b=nil)
15
- self.class.instance_eval(&block) if block_given?
16
- end
17
-
18
-
19
- get '/' do
20
- render_view(:index, { :posts => PostIndex.instance })
21
- end
22
-
23
-
24
- get %r{^\/\d{4}\/\d{2}\/\d{2}\/\w+} do
25
- index = nil
26
-
27
- PostIndex.instance.each_with_index { |p, i|
28
- if (p[:request_path] == request.path)
29
- index = i
30
- break
31
- end
32
- }
33
-
34
- if (index != nil)
35
- render_view(:post, { :posts => PostIndex.instance, :index => index })
36
- end
37
- end
38
-
39
-
40
- get %r{^\/\d{4}(\/\d{2}(\/\d{2})?)?$} do
41
- posts = PostIndex.instance.select { |p|
42
- p[:request_path] =~ %r{^#{request.path}}
43
- }
44
-
45
- render_view(:archive, { :posts => posts })
46
- end
47
-
48
-
49
- get %r{^\/\w+} do
50
- begin
51
- render_view(request.path.to_sym, { :posts => PostIndex.instance })
52
- rescue
53
- pass
54
- end
55
- end
56
-
57
-
58
- def render_view(view, locals)
59
- expires(86400, :public)
60
-
61
- haml view, :locals => locals
62
- end
63
- end
1
+ require 'sinatra/base'
2
+ require 'haml'
3
+ require 'gidget/post_index'
4
+
5
+
6
+ module Gidget
7
+ class Server < Sinatra::Base
8
+ set :haml, :format => :html5
9
+
10
+ set :page_size, 5
11
+
12
+ def initialize(app=nil, &block)
13
+ super(app, &b=nil)
14
+ self.class.instance_eval(&block) if block_given?
15
+ end
16
+
17
+
18
+ get '/' do
19
+ render_view(:index, { :posts => PostIndex.instance })
20
+ end
21
+
22
+
23
+ get %r{^\/\d{4}\/\d{2}\/\d{2}\/\w+} do
24
+ index = nil
25
+
26
+ PostIndex.instance.each_with_index { |p, i|
27
+ if (p.request_path == request.path)
28
+ index = i
29
+ break
30
+ end
31
+ }
32
+
33
+ if (index != nil)
34
+ render_view(:post, { :posts => PostIndex.instance, :index => index })
35
+ end
36
+ end
37
+
38
+
39
+ get %r{^\/\d{4}(\/\d{2}(\/\d{2})?)?$} do
40
+ posts = PostIndex.instance.select { |p|
41
+ p.request_path =~ %r{^#{request.path}}
42
+ }
43
+
44
+ render_view(:archive, { :posts => posts })
45
+ end
46
+
47
+
48
+ get %r{^\/\w+} do
49
+ begin
50
+ render_view(request.path.to_sym, { :posts => PostIndex.instance })
51
+ rescue
52
+ pass
53
+ end
54
+ end
55
+
56
+
57
+ def render_view(view, locals)
58
+ expires(86400, :public)
59
+
60
+ haml view, :locals => locals
61
+ end
62
+ end
64
63
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gidget
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 11
10
- version: 0.0.11
9
+ - 12
10
+ version: 0.0.12
11
11
  platform: ruby
12
12
  authors:
13
13
  - Forrest Robertson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-27 00:00:00 -07:00
18
+ date: 2010-12-26 00:00:00 -07:00
19
19
  default_executable: gidget
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency