who-needs-wp 0.3.0 → 0.4.0

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.
@@ -0,0 +1,119 @@
1
+ # who-needs-wp
2
+ _Who needs Wordpress?_
3
+
4
+ The majority of web sites are consumed. Visitors will stumble upon the site, read a few pages (if you're lucky) and then disappear. Normally for every visitor to the site each webpage is generated dynamically. Each visitor has their own version of the web page for that particular moment of time. Is this really necessary? How often does the content on the web site you are visiting change?
5
+
6
+ Take blogs for example. I have a blog written using the excellent Wordpress software. I'm able to write posts within Wordpress and see them appear on the web site without leaving my web browser. My posts are held in a database, when a user requests to view my blog multiple requests are made to the database to build a dynamic page on which contents rarely changes. I create a new blog post every 3 weeks, it seems a bit unnecessary to generate a web page when the content hasn't changed.
7
+
8
+ There is another option. Instead of generating the web site dynamically when the page is requested I can generate the web page whenever the content changes. So whenever I create a new post - I regenerate the site.
9
+
10
+ This has the advantage of serving web pages faster; I use less hosting space; and I cut any unnecessary features which Wordpress provides.
11
+
12
+ The main disadvantage is that user's aren't able to comment on my posts - but this don't matter too much - nobody ever did! ;-)
13
+
14
+ ## Getting Started
15
+
16
+ `who-needs-wp` is a small Ruby program which helps generate static web sites. To start using `who-needs-wp` you need to install Ruby. On Ubuntu enter the following into a command prompt:
17
+
18
+ sudo apt-get install ruby ruby-dev rubygems
19
+
20
+ You then need to install `who-needs-wp` by running the following:
21
+
22
+ sudo gem install who-needs-wp
23
+
24
+ Ensure that Ruby gems is in your `PATH` variable by opening `~/.bashrc` and entering:
25
+
26
+ export PATH=/var/lib/gems/1.8/bin:$PATH
27
+
28
+ You'll need to re-load the `.bashrc` file by using the following command:
29
+
30
+ . ~/.bashrc
31
+
32
+ Now create a folder which will host your web site
33
+
34
+ mkdir /var/www/website/
35
+
36
+ `who-needs-wp` stores posts in the `posts/` folder followed by a folder representing the date of the post. i.e. `posts/year/month/day`.
37
+
38
+ Create an example post by creating a folder and creating a Markdown file.
39
+
40
+ mkdir /var/www/website/posts/2010/03/15/ --parents
41
+ gedit /var/www/website/posts/2010/03/15/An_example_post.markdown
42
+
43
+ The filename will be used as the title for the page - all the underscores will be replaced with spaces.
44
+
45
+ Along with [Markdown Syntax][MarkdownSyntax] you can also specify the author of the blog post within the file:
46
+
47
+ Author: Your Name
48
+
49
+ Before it can generate the site `who-needs-wp` needs to be configured. Copy the following into `/var/www/website/.who-needs-wp.yaml`
50
+
51
+ ---
52
+ :url: /website/test
53
+ :title: An example blog
54
+ :author: Your Name
55
+
56
+ These are the properties which are used to generate the website:
57
+
58
+ * `url` - The base URL of the website
59
+ * `title` - A title for the index of your site
60
+ * `author` - When a author is not specified within the post this author is displayed
61
+
62
+ Now you can generate your site:
63
+
64
+ who-needs-wp .
65
+
66
+ And view the blog at the following URL:
67
+
68
+ http://localhost/website/
69
+
70
+ ## Overriding Templates
71
+
72
+ You will probably find that the templates used by `who-needs-wp` don't quite match your requirements. You can override any of the templates by creating a `templates` folder. You can copy the existing templates from the gem as a starting point. The templates are stored within the `/var/lib/gems/1.8/gems/who-needs-wp-0.1.0/lib/who-needs-wp/templates/`.
73
+
74
+ ## Applying alternative styles
75
+
76
+ You can specify an additional stylesheet by using the `-s` or `--stylesheet` option to the `who-needs-wp` command.
77
+
78
+ ## Twitter
79
+
80
+ `who-needs-wp` can place a [Twitter][Twitter] stream in the side bar. This can either be a search or an individual user's feed.
81
+
82
+ Modifying `.who-needs-wp.yaml` and add:
83
+
84
+ :twitter:
85
+ :user: <your twitter user>
86
+ :search: <your twitter search>
87
+
88
+ ## Delicious
89
+
90
+ `who-needs-wp` can also display a list of bookmarks from [Delicious][Delicious]. Modify `.who-needs-wp.yaml` and add:
91
+
92
+ :delicious:
93
+ :user: <your delicious username>
94
+
95
+ ## Google Analytics
96
+
97
+ To enable Google Analytics you need to specify your web property ID in `.who-needs-wp.yaml`. For example:
98
+
99
+ :google_analytics: UA-XXXXXXXX
100
+
101
+
102
+ ## Syntax Highlighting
103
+
104
+ `who-needs-wp` will syntax highlight your code snippets using [Makers-Mark][MakersMark] and [Pygments][Pygments]
105
+
106
+ ## Migration from Wordpress
107
+
108
+ A simple script is in development which will convert a MySQL database to seperate Markdown pages.
109
+
110
+ ### Copyright
111
+
112
+ Copyright (c) 2010 Owen Griffin. See LICENSE for details.
113
+
114
+ [Markdown]: http://daringfireball.net/projects/markdown/
115
+ [MarkdownSyntax]: http://daringfireball.net/projects/markdown/syntax
116
+ [Delicious]: http://del.icio.us/
117
+ [Twitter]: http://twitter.com/
118
+ [MakersMark]: http://github.com/nakajima/makers-mark
119
+ [Pygments]: http://pygments.org/
@@ -25,6 +25,7 @@ module WhoNeedsWP
25
25
  # Logger
26
26
  @logger = Logger.new(STDOUT)
27
27
 
28
+ # Generate the site with the specified options
28
29
  def self.generate(options)
29
30
  @options = options
30
31
  self.load_templates
@@ -37,20 +38,24 @@ module WhoNeedsWP
37
38
  self.generate_posts
38
39
  self.generate_pages
39
40
  self.index
41
+ self.all_posts
40
42
  self.css
41
43
  end
44
+
45
+ # Generate the index page for the blog
42
46
  def self.index
43
- File.open("index.html", "w") do |file|
44
- contents = ""
45
- @POSTS[0..3].each do |post|
46
- contents << post[:html]
47
- end
48
- file.puts @template['layout'].render(Object.new, {
49
- :content => contents,
50
- :options => @options,
51
- :sidebar => @sidebar.join,
52
- :layout_name => "index"
53
- })
47
+ contents = ""
48
+ @POSTS[0..3].each do |post|
49
+ contents << post[:html]
54
50
  end
51
+ self.render_html("index.html", "index", contents)
52
+ end
53
+
54
+ # Generate a page containing a list of all posts
55
+ def self.all_posts
56
+ self.render_html("posts/all.html", "post_index", @template['all_posts'].render(Object.new, {
57
+ :posts => @POSTS,
58
+ :options => @options
59
+ }), "All Posts")
55
60
  end
56
61
  end
@@ -25,30 +25,27 @@ module WhoNeedsWP
25
25
 
26
26
  def self.generate_pages
27
27
  @pages.each do |page|
28
- File.open(page[:filename][:generated], "w") do |file|
29
- markdown = File.read(page[:filename][:original])
30
- page[:author] = @options[:author]
31
- match = markdown.match(/^[aA]uthor: (.*)$/o)
32
- if match
33
- page[:author] = match[1]
34
- # Remove the author from the post text
35
- markdown.gsub! /^[aA]uthor: .*$/, ''
36
- end
37
- # post[:markdown] = RDiscount.new(markdown, :smart, :generate_toc).to_html
38
- page[:markdown] = MakersMark.generate(markdown)
39
- page[:html] = @template['page'].render(Object.new, {
40
- :page => page,
41
- :title => page[:title],
42
- :options => @options
43
- })
44
- file.puts @template['layout'].render(Object.new, {
45
- :content => page[:html],
46
- :options => @options,
47
- :title => page[:title],
48
- :sidebar => @sidebar.join,
49
- :layout_name => "page"
50
- })
28
+
29
+ markdown = File.read(page[:filename][:original])
30
+
31
+ page[:author] = @options[:author]
32
+
33
+ match = markdown.match(/^[aA]uthor: (.*)$/o)
34
+ if match
35
+ page[:author] = match[1]
36
+ # Remove the author from the post text
37
+ markdown.gsub! /^[aA]uthor: .*$/, ''
51
38
  end
39
+
40
+ # post[:markdown] = RDiscount.new(markdown, :smart, :generate_toc).to_html
41
+ page[:markdown] = MakersMark.generate(markdown)
42
+ page[:html] = @template['page'].render(Object.new, {
43
+ :page => page,
44
+ :title => page[:title],
45
+ :options => @options
46
+ })
47
+ # Render the page as HTML
48
+ self.render_html(page[:filename][:generated], "page", page[:html], page[:title])
52
49
  end
53
50
  end
54
51
  end
@@ -29,35 +29,36 @@ module WhoNeedsWP
29
29
 
30
30
  def self.generate_posts
31
31
  @POSTS.each_index do |index|
32
+ # Calculate the previous and next posts
32
33
  post = @POSTS[index]
33
34
  previous_post = @POSTS[index + 1] if index + 1 < @POSTS.length
34
35
  next_post = @POSTS[index - 1] if index > 1
35
- File.open(post[:filename][:generated], "w") do |file|
36
- markdown = File.read(post[:filename][:original])
37
- post[:author] = @options[:author]
38
- match = markdown.match(/^[aA]uthor: (.*)$/o)
39
- if match
40
- post[:author] = match[1]
41
- # Remove the author from the post text
42
- markdown.gsub! /^[aA]uthor: .*$/, ''
43
- end
44
- # post[:markdown] = RDiscount.new(markdown, :smart, :generate_toc).to_html
45
- post[:markdown] = MakersMark.generate(markdown)
46
- post[:html] = @template['post'].render(Object.new, {
47
- :post => post,
48
- :title => post[:title],
49
- :options => @options,
50
- :next_post => next_post,
51
- :previous_post => previous_post
52
- })
53
- file.puts @template['layout'].render(Object.new, {
54
- :content => post[:html],
55
- :options => @options,
56
- :title => post[:title],
57
- :sidebar => @sidebar.join,
58
- :layout_name => "post"
59
- })
36
+
37
+ # Read the contents of the file
38
+ markdown = File.read(post[:filename][:original])
39
+
40
+ # Specify the default author
41
+ post[:author] = @options[:author]
42
+
43
+ # Check to see if the author of the document is specified with "Author:"
44
+ match = markdown.match(/^[aA]uthor: (.*)$/o)
45
+ if match
46
+ post[:author] = match[1]
47
+ # Remove the author from the post text
48
+ markdown.gsub! /^[aA]uthor: .*$/, ''
60
49
  end
50
+
51
+ # post[:markdown] = RDiscount.new(markdown, :smart, :generate_toc).to_html
52
+ post[:markdown] = MakersMark.generate(markdown)
53
+ post[:html] = @template['post'].render(Object.new, {
54
+ :post => post,
55
+ :title => post[:title],
56
+ :options => @options,
57
+ :next_post => next_post,
58
+ :previous_post => previous_post
59
+ })
60
+ # Render the post as HTML
61
+ self.render_html(post[:filename][:generated], "post", post[:html], post[:title])
61
62
  end
62
63
  end
63
64
  end
@@ -1,6 +1,24 @@
1
1
 
2
2
 
3
3
  module WhoNeedsWP
4
+
5
+ # Render the specified HTML contents within the layout template
6
+ def self.render_html(filename, type, contents, title = "")
7
+ File.open(filename, "w") do |file|
8
+ body = @template['body'].render(Object.new, {
9
+ :content => contents,
10
+ :options => @options,
11
+ :sidebar => @sidebar.join,
12
+ :layout_name => type
13
+ })
14
+ file.puts @template['layout'].render(Object.new, {
15
+ :content => body,
16
+ :options => @options,
17
+ :title => title
18
+ })
19
+ end
20
+ end
21
+
4
22
  def self.load_templates
5
23
  template_folder = File.expand_path(File.join(File.dirname(__FILE__), "templates"))
6
24
  @template = Hash.new
@@ -0,0 +1,6 @@
1
+ %h1 All Posts
2
+ %ul
3
+ - posts.each do |post|
4
+ %li
5
+ %span.date= post[:created_at].strftime('%Y-%m-%d')
6
+ %a.title{:href => "#{options[:url]}/#{post[:filename][:generated]}", :title => post[:title]}= post[:title]
@@ -0,0 +1,17 @@
1
+ #doc4.yui-t2
2
+ #hd
3
+ %h1
4
+ %a{:href => "#{options[:url]}/index.html"}= options[:title]
5
+ #bd
6
+ #yui-main
7
+ .yui-b
8
+ .yui-gc
9
+ .yui-u.first
10
+ #content{:class => "#{layout_name}"}= content
11
+ .yui-u
12
+ =sidebar
13
+ .yui-b
14
+
15
+ #ft
16
+ Generated using who-needs-wp
17
+
@@ -4,28 +4,22 @@
4
4
  %link{:rel => "stylesheet", :type => "text/css", :href => "#{options[:url]}/style.css"}/
5
5
  %title
6
6
  = options[:title]
7
- - if defined? title
7
+ - if defined? title and title != nil and not title.empty?
8
8
  \-
9
9
  = title
10
10
  - if defined? options[:stylesheet]
11
11
  %link{:rel => "stylesheet", :type => "text/css", :href => "#{options[:url]}/#{options[:stylesheet]}"}/
12
12
  %meta{:"http-equiv" => "Content-Type", :content => "text/html; charset=utf-8"}/
13
13
  %body
14
- #doc4.yui-t2
15
- #hd
16
- %h1
17
- %a{:href => "#{options[:url]}/index.html"}= options[:title]
18
- #bd
19
- #yui-main
20
- .yui-b
21
- .yui-gc
22
- .yui-u.first
23
- #content{:class => "#{layout_name}"}= content
24
- .yui-u
25
- =sidebar
26
- .yui-b
27
-
28
- #ft
29
- Generated using who-needs-wp
30
-
31
-
14
+ = content
15
+
16
+ - if options[:google_analytics] != nil and not options[:google_analytics].empty?
17
+ %script{:src => 'http://www.google-analytics.com/ga.js', :type => 'text/javascript'}/
18
+ :javascript
19
+ try {
20
+ var pageTracker = _gat._getTracker("#{options[:google_analytics]}_");
21
+ pageTracker._trackPageview();
22
+ } catch(err) {}
23
+
24
+
25
+
@@ -4,3 +4,5 @@
4
4
  %li
5
5
  %span.date= post[:created_at].strftime('%Y-%m-%d')
6
6
  %a.title{:href => "#{options[:url]}/#{post[:filename][:generated]}", :title => post[:title]}= post[:title]
7
+ %li
8
+ %a{:href => "#{options[:url]}/posts/all.html", :title => "All posts"} more
@@ -7,4 +7,4 @@
7
7
  - tweets.each do |tweet|
8
8
  %li
9
9
  %span.date= Date.parse(tweet[:created_at]).strftime('%Y-%m-%d')
10
- %span= tweet[:text]
10
+ %span= WhoNeedsWP::parse_tweet tweet[:text]
@@ -1,16 +1,23 @@
1
1
 
2
2
  module WhoNeedsWP
3
+
4
+ def self.parse_tweet(text)
5
+ text = text.gsub(/(http:\/\/[^ ]+)/, '<a href="\1">\1</a>')
6
+ text = text.gsub(/(@([^ :]+))/, '<a href="http://twitter.com/\2">\1</a>')
7
+ return text.gsub(/(#([^ :]+))/, '<a href="http://twitter.com/#search?q=%23\2">\1</a>')
8
+ end
9
+
3
10
  def self.twitter
4
- @logger.debug @options[:twitter]
5
- if @options[:twitter][:user]
11
+ if @options[:twitter][:user] != nil and not @options[:twitter][:user].empty?
6
12
  @logger.debug "Reading Tweets for user #{@options[:twitter][:user]}"
13
+ tweets = Twitter::Search.new.from(@options[:twitter][:user]).per_page(5).fetch().results
7
14
  @sidebar << @template['twitter'].render(Object.new, {
8
- :tweets => Twitter::Search.new.from(@options[:twitter][:user]).per_page(5).fetch().results,
15
+ :tweets => tweets,
9
16
  :feed_title => "@#{@options[:twitter][:user]}",
10
17
  :options => @options
11
18
  })
12
19
  end
13
- if @options[:twitter][:search]
20
+ if @options[:twitter][:search] != nil and not @options[:twitter][:search].empty?
14
21
  @logger.debug "Searching Twitter for #{@options[:twitter][:search]}"
15
22
  @sidebar << @template['twitter'].render(Object.new, {
16
23
  :tweets => Twitter::Search.new(@options[:twitter][:search]).per_page(5).fetch().results,
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
7
+ - 4
8
8
  - 0
9
- version: 0.3.0
9
+ version: 0.4.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Owen Griffin
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-17 00:00:00 +00:00
17
+ date: 2010-03-19 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -110,7 +110,7 @@ extensions: []
110
110
 
111
111
  extra_rdoc_files:
112
112
  - LICENSE
113
- - README.rdoc
113
+ - README.md
114
114
  files:
115
115
  - lib/who-needs-wp.rb
116
116
  - lib/who-needs-wp/css.rb
@@ -122,6 +122,8 @@ files:
122
122
  - lib/who-needs-wp/stylesheets/reset-fonts-grids.sass
123
123
  - lib/who-needs-wp/stylesheets/style.sass
124
124
  - lib/who-needs-wp/templates.rb
125
+ - lib/who-needs-wp/templates/all_posts.haml
126
+ - lib/who-needs-wp/templates/body.haml
125
127
  - lib/who-needs-wp/templates/delicious.haml
126
128
  - lib/who-needs-wp/templates/layout.haml
127
129
  - lib/who-needs-wp/templates/page.haml
@@ -131,7 +133,7 @@ files:
131
133
  - lib/who-needs-wp/templates/twitter.haml
132
134
  - lib/who-needs-wp/twitter.rb
133
135
  - LICENSE
134
- - README.rdoc
136
+ - README.md
135
137
  has_rdoc: true
136
138
  homepage: http://github.com/owengriffin/who-needs-wp
137
139
  licenses: []
@@ -1,17 +0,0 @@
1
- = who-needs-wp
2
-
3
- Description goes here.
4
-
5
- == Note on Patches/Pull Requests
6
-
7
- * Fork the project.
8
- * Make your feature addition or bug fix.
9
- * Add tests for it. This is important so I don't break it in a
10
- future version unintentionally.
11
- * Commit, do not mess with rakefile, version, or history.
12
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
- * Send me a pull request. Bonus points for topic branches.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2010 Owen Griffin. See LICENSE for details.