statikaj 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Duke
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # Statikaj <a href='https://gemnasium.com/dukex/statikaj'><img src="https://gemnasium.com/dukex/statikaj.png" alt="Dependency Status" /></a>
2
+
3
+ Static blog
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'statikaj'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install statikaj
18
+
19
+ ## Usage
20
+
21
+ $ statikaj new myblog
22
+ $ cd myblog
23
+ $ statikaj build
24
+ $ rackup -p 3000
25
+
26
+ Your static blog is running on http://localhost:3000
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/statikaj ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'statikaj/cli'
5
+
6
+ Statikaj::CLI.start(ARGV)
data/lib/ext/ext.rb ADDED
@@ -0,0 +1,60 @@
1
+ # encoding: utf-8
2
+ #
3
+ class Object
4
+ def meta_def name, &blk
5
+ (class << self; self; end).instance_eval do
6
+ define_method(name, &blk)
7
+ end
8
+ end
9
+ end
10
+
11
+ class String
12
+ def slugize
13
+ self.transliterate.downcase.gsub(/&/, 'and').gsub(/\s+/, '-').gsub(/[^a-z0-9-]/, '')
14
+ end
15
+
16
+ def humanize
17
+ self.capitalize.gsub(/[-_]+/, ' ')
18
+ end
19
+
20
+ if RUBY_VERSION < "1.9"
21
+ def bytesize
22
+ size
23
+ end
24
+ end
25
+
26
+ def transliterate
27
+ self.tr(
28
+ "ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž",
29
+ "AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz")
30
+ end
31
+ end
32
+
33
+ class Fixnum
34
+ def ordinal
35
+ # 1 => 1st
36
+ # 2 => 2nd
37
+ # 3 => 3rd
38
+ # ...
39
+ case self % 100
40
+ when 11..13; "#{self}th"
41
+ else
42
+ case self % 10
43
+ when 1; "#{self}st"
44
+ when 2; "#{self}nd"
45
+ when 3; "#{self}rd"
46
+ else "#{self}th"
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ class Date
53
+ # This check is for people running Toto with ActiveSupport, avoid a collision
54
+ unless respond_to? :iso8601
55
+ # Return the date as a String formatted according to ISO 8601.
56
+ def iso8601
57
+ ::Time.utc(year, month, day, 0, 0, 0, 0).iso8601
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,89 @@
1
+ require 'yaml'
2
+ require 'statikaj/template'
3
+ require 'kramdown'
4
+
5
+ module Statikaj
6
+ class Article < Hash
7
+ def initialize obj, config = {}
8
+ @obj, @config = obj, config
9
+ self.load #if obj.is_a? Hash
10
+ end
11
+
12
+ def render(source)
13
+ ERB.new(File.read(source.join("templates/pages/article.rhtml"))).result(binding)
14
+ end
15
+
16
+ def markdown(text)
17
+ Kramdown::Document.new(text).to_html
18
+ end
19
+
20
+ def load
21
+ data = if @obj.is_a? String
22
+ meta, self[:body] = File.read(@obj).split(/\n\n/, 2)
23
+ # use the date from the filename, or else toto won't find the article
24
+ @obj =~ /\/(\d{4}-\d{2}-\d{2})[^\/]*$/
25
+ ($1 ? {:date => $1} : {}).merge(YAML.load(meta))
26
+ elsif @obj.is_a? Hash
27
+ @obj
28
+ end.inject({}) {|h, (k,v)| h.merge(k.to_sym => v) }
29
+
30
+ self.taint
31
+ self.update data
32
+ self[:date] = Date.parse(self[:date].gsub('/', '-')) rescue Date.today
33
+ self
34
+ end
35
+
36
+ def [] key
37
+ self.load unless self.tainted?
38
+ super
39
+ end
40
+
41
+ def slug
42
+ self[:slug] || self[:title].slugize
43
+ end
44
+
45
+ def summary length = nil
46
+ # config = @config[:summary]
47
+ # sum = if self[:body] =~ config[:delim]
48
+ # self[:body].split(config[:delim]).first
49
+ # else
50
+ # self[:body].match(/(.{1,#{length || config[:length] || config[:max]}}.*?)(\n|\Z)/m).to_s
51
+ # end
52
+ # markdown(sum.length == self[:body].length ? sum : sum.strip.sub(/\.\Z/, '&hellip;'))
53
+ end
54
+
55
+ def url
56
+ # "http://#{(@config[:url].sub("http://", '') + self.path).squeeze('/')}"
57
+ end
58
+ #alias :permalink url
59
+
60
+ def body
61
+ markdown self[:body]
62
+ end
63
+
64
+ def path
65
+ # TODO: custom domain
66
+ # "/#{@config[:prefix]}#{self[:date].strftime("/%Y/%m/%d/#{slug}/")}".squeeze('/')
67
+ slug
68
+ end
69
+
70
+ def title()
71
+ self[:title] || "an article"
72
+ end
73
+
74
+ def date()
75
+ # TODO: costum
76
+ # @config[:date].call(self[:date])
77
+ self[:date].strftime("%B #{self[:date].day.ordinal} %Y")
78
+ end
79
+
80
+ def author()
81
+ self[:author]
82
+ end
83
+
84
+ def to_html()
85
+ self.load; super(:article, @config)
86
+ end
87
+ #alias :to_s to_html
88
+ end
89
+ end
@@ -0,0 +1,60 @@
1
+ require 'thor'
2
+ require 'erb'
3
+ require 'statikaj/article'
4
+ require 'statikaj/render'
5
+ require 'ext/ext'
6
+
7
+ module Statikaj
8
+ class CLI < Thor
9
+ include Thor::Actions
10
+
11
+ def self.source_root
12
+ File.expand_path('../../..', __FILE__)
13
+ end
14
+
15
+ desc 'new', 'Create a new project'
16
+ def new(name)
17
+ directory('templates', name)
18
+ end
19
+
20
+ desc "build [SOURCE] [DESTINATION]", "build the blog from source to destination folder"
21
+ long_desc <<-LONGDESC
22
+ The SOURCE folder should have `articles` folders
23
+ DESTINATION default is ./public
24
+
25
+ > $ statikaj build
26
+ > $ statikaj build ./source ~/myblog/public
27
+ LONGDESC
28
+ def build(source = "./src", destination = "./public")
29
+ source = Pathname.new source
30
+ destination = Pathname.new destination
31
+
32
+ articles_files = Dir[source.join('articles/*.md')].sort_by {|entry| File.basename(entry) }
33
+ articles = articles_files.map{|f| Article.new(f) }
34
+
35
+ articles.each do |article|
36
+ puts "Saving: #{article.slug}"
37
+ article_file = destination.join("#{article.slug}").to_s
38
+
39
+ render = Render.new(source, article: article)
40
+ content = render.article do |page|
41
+ page.title = article.title
42
+ page.description = article.summary
43
+ end
44
+
45
+ #unless File.exists?(article_file)
46
+ file = File.new(article_file, "w+")
47
+ file.puts content
48
+ file.close
49
+ #end
50
+ end
51
+
52
+ puts "Creating index.html"
53
+ render = Render.new(source, page: 'index', articles: articles.reverse)
54
+ content = render.page {}
55
+ file = File.new(destination.join("index.html"), "w+")
56
+ file.puts content
57
+ file.close
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,39 @@
1
+ module Statikaj
2
+ class Render
3
+ attr_accessor :title, :articles, :description
4
+
5
+ def initialize(source, options)
6
+ @source = source
7
+ @article = options.delete(:article) if options[:article]
8
+ @articles = options.delete(:articles) if options[:articles]
9
+ if options[:page]
10
+ render_page(options.delete(:page))
11
+ end
12
+ end
13
+
14
+ def article(&blk)
15
+ yield self
16
+ to_html do
17
+ @article.render(@source)
18
+ end
19
+ end
20
+
21
+ def page(&blk)
22
+ yield self
23
+ to_html do
24
+ @page
25
+ end
26
+ end
27
+
28
+ private
29
+ def to_html(&blk)
30
+ layout = File.read(@source.join('templates/layout.rhtml'))
31
+ ERB.new(layout).result(binding)
32
+ end
33
+
34
+ def render_page(page_name)
35
+ page = File.read(@source.join("templates/pages/#{page_name}.rhtml"))
36
+ @page = ERB.new(page).result(binding)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,4 @@
1
+ module Statikaj
2
+ class Template
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Statikaj
2
+ VERSION = "0.0.1"
3
+ end
data/lib/statikaj.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "statikaj/version"
2
+
3
+ module Statikaj
4
+ end
data/statikaj.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'statikaj/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "statikaj"
8
+ spec.version = Statikaj::VERSION
9
+ spec.authors = ["Duke"]
10
+ spec.email = ["duke@riseup.net"]
11
+ spec.description = %q{Statikaj is simple tool to create statikaj blogs.}
12
+ spec.summary = %q{Statikaj is simple tool to create statikaj blogs.}
13
+ spec.homepage = "https://github.com/dukex/statikaj"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "pry"
24
+ spec.add_dependency "kramdown"
25
+ spec.add_dependency "thor"
26
+ spec.add_dependency "rack"
27
+ end
@@ -0,0 +1,19 @@
1
+ require 'rack'
2
+
3
+ use Rack::Static, :urls => [""], :root => 'public', :index =>'index.html',
4
+ :header_rules => [
5
+ [:all, {'Cache-Control' => 'public, max-age=864000'}],
6
+ [%r{^(?!.*\.).*\w}, {'Content-Type' => 'text/html'}]
7
+ ]
8
+
9
+ run lambda { |env|
10
+ [
11
+ 200,
12
+ {
13
+ 'Content-Type' => 'text/html',
14
+ 'Cache-Control' => 'public, max-age=864000'
15
+ },
16
+ File.open('public/index.html', File::RDONLY)
17
+ ]
18
+ }
19
+
File without changes
@@ -0,0 +1,12 @@
1
+ ---
2
+ title: The first post!
3
+ date: 02/06/1992
4
+ author: Duke
5
+
6
+
7
+ Pitchfork viral kale chips Neutra. Irony Echo Park ennui asymmetrical. Literally Intelligentsia asymmetrical PBR, hashtag actually photo booth hella shabby chic. Mustache narwhal tattooed Terry Richardson Marfa chia Vice ugh. Food truck fanny pack try-hard Echo Park. Fingerstache banh mi aesthetic deep v, iPhone squid Banksy locavore. Fingerstache pour-over forage chillwave, pork belly shabby chic put a bird on it fashion axe before they sold out irony.
8
+
9
+ Beard keffiyeh food truck, skateboard messenger bag put a bird on it wolf hoodie gluten-free Godard Portland. Freegan Bushwick Schlitz, distillery vegan keytar sustainable 90's stumptown fixie cardigan Terry Richardson squid chillwave kogi. Kogi shabby chic salvia Brooklyn. PBR&B quinoa meggings, gluten-free +1 disrupt salvia Blue Bottle next level Tumblr mumblecore kale chips hoodie YOLO. Helvetica scenester Neutra PBR, Banksy readymade pug drinking vinegar slow-carb semiotics kale chips Truffaut swag pop-up. Odd Future polaroid wayfarers, scenester ethnic Helvetica pug street art Etsy Carles four loko stumptown synth post-ironic. American Apparel forage kitsch, try-hard you probably haven't heard of them cornhole Brooklyn.
10
+
11
+
12
+ ***- Duke***
@@ -0,0 +1,21 @@
1
+ xml.instruct!
2
+ xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
3
+ xml.title @config[:title]
4
+ xml.id @config[:url]
5
+ xml.updated articles.first[:date].iso8601 unless articles.empty?
6
+ xml.author { xml.name @config[:author] }
7
+
8
+ articles.reverse[0...10].each do |article|
9
+ xml.entry do
10
+ xml.title article.title
11
+ xml.link "rel" => "alternate", "href" => article.url
12
+ xml.id article.url
13
+ xml.published article[:date].iso8601
14
+ xml.updated article[:date].iso8601
15
+ xml.author { xml.name article[:author] }
16
+ xml.summary article.summary, "type" => "html"
17
+ xml.content article.body, "type" => "html"
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,22 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <link rel="alternate" type="application/atom+xml" title="<%= title %> - feed" href="/index.xml" />
6
+ <title><%= title %></title>
7
+ <meta name="description" content="<%= description %>" />
8
+ <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
9
+ </head>
10
+ <body>
11
+ <h1> <a href="/">My Blog</a></h1>
12
+ <div id='content'>
13
+ <%= yield %>
14
+ </div>
15
+ </div>
16
+ <footer>
17
+ <div class='container'>
18
+ <p>&copy; My Blog</p>
19
+ </div>
20
+ </footer>
21
+ </body>
22
+ </html>
@@ -0,0 +1,7 @@
1
+ <article>
2
+ <header>
3
+ <span class="author"><%= author %></span> - <time class="date"><%= date %></time>
4
+ <h2><%= title %></h2>
5
+ </header>
6
+ <%= body %>
7
+ </article>
@@ -0,0 +1,9 @@
1
+ <ul id="posts">
2
+ <% articles.select {|a| a[:date] <= Date.today}[0...10].each do |article| %>
3
+ <li class="post">
4
+ <h2><a href="<%= article.path %>"><%= article.title %></a></h2>
5
+ <span class="author"><%= article.author %></span> -
6
+ <time class="date"><%= article.date %></time>
7
+ </li>
8
+ <% end %>
9
+ </ul>
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: statikaj
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Duke
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: pry
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: kramdown
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: thor
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rack
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Statikaj is simple tool to create statikaj blogs.
111
+ email:
112
+ - duke@riseup.net
113
+ executables:
114
+ - statikaj
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - bin/statikaj
124
+ - lib/ext/ext.rb
125
+ - lib/statikaj.rb
126
+ - lib/statikaj/article.rb
127
+ - lib/statikaj/cli.rb
128
+ - lib/statikaj/render.rb
129
+ - lib/statikaj/template.rb
130
+ - lib/statikaj/version.rb
131
+ - statikaj.gemspec
132
+ - templates/config.ru
133
+ - templates/public/.gitkeep
134
+ - templates/src/articles/1992-06-02-the-first-post.md
135
+ - templates/src/templates/index.builder
136
+ - templates/src/templates/layout.rhtml
137
+ - templates/src/templates/pages/article.rhtml
138
+ - templates/src/templates/pages/index.rhtml
139
+ homepage: https://github.com/dukex/statikaj
140
+ licenses:
141
+ - MIT
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ! '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ segments:
153
+ - 0
154
+ hash: -4500895543411871736
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ none: false
157
+ requirements:
158
+ - - ! '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ segments:
162
+ - 0
163
+ hash: -4500895543411871736
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 1.8.23
167
+ signing_key:
168
+ specification_version: 3
169
+ summary: Statikaj is simple tool to create statikaj blogs.
170
+ test_files: []