striker 0.0.8.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +179 -0
- data/Rakefile +1 -0
- data/bin/striker +58 -0
- data/lib/new_site/config.yml +17 -0
- data/lib/new_site/css/style.css +1 -0
- data/lib/new_site/js/script.js +1 -0
- data/lib/new_site/templates/archive/index.html +1 -0
- data/lib/new_site/templates/default.html +10 -0
- data/lib/new_site/templates/page.html +10 -0
- data/lib/new_site/templates/tags/index.html +1 -0
- data/lib/new_site/templates/tags/tag.html +2 -0
- data/lib/striker.rb +28 -0
- data/lib/striker/archive.rb +72 -0
- data/lib/striker/command/build.rb +34 -0
- data/lib/striker/command/new.rb +42 -0
- data/lib/striker/command/page.rb +67 -0
- data/lib/striker/command/strike.rb +18 -0
- data/lib/striker/command/templates/page.md +8 -0
- data/lib/striker/media/image.rb +78 -0
- data/lib/striker/page.rb +86 -0
- data/lib/striker/settings.rb +22 -0
- data/lib/striker/site.rb +27 -0
- data/lib/striker/tag.rb +77 -0
- data/lib/striker/tags/soundcloud.rb +26 -0
- data/lib/striker/tags/thumbnail.rb +38 -0
- data/lib/striker/tags/tweet.rb +25 -0
- data/lib/striker/tags/vimeo.rb +26 -0
- data/lib/striker/tags/youtube.rb +26 -0
- data/lib/striker/template.rb +33 -0
- data/lib/striker/version.rb +3 -0
- data/striker.gemspec +32 -0
- metadata +219 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
module Striker
|
2
|
+
module Command
|
3
|
+
class Build
|
4
|
+
|
5
|
+
def self.process
|
6
|
+
FileUtils.rm_rf(File.join Settings::PUBLIC_DIR, ".")
|
7
|
+
FileUtils.mkdir_p(Settings::PUBLIC_DIR)
|
8
|
+
FileUtils.mkdir_p(Settings::ASSETS_DIR)
|
9
|
+
Settings::CONFIG['include_assets'].each do |d|
|
10
|
+
FileUtils.cp_r(File.join(Settings::SOURCE_DIR, d), Settings::ASSETS_DIR) if File.exists? d
|
11
|
+
end
|
12
|
+
FileUtils.cp_r(File.join(Settings::SOURCE_DIR, "css"), File.join(Settings::ASSETS_DIR))
|
13
|
+
Dir.glob(Settings::MEDIA_DIR + "/*").each do |d|
|
14
|
+
FileUtils.mkdir_p File.join(Settings::ASSETS_DIR, d.split("/")[-1]) if File.directory? d
|
15
|
+
end
|
16
|
+
|
17
|
+
meta = Site.meta
|
18
|
+
Site.pages(true).each do |p|
|
19
|
+
page = Striker::Page.new(p)
|
20
|
+
t = Template.new(page, meta)
|
21
|
+
t.process
|
22
|
+
end
|
23
|
+
|
24
|
+
# Process Tags
|
25
|
+
Tag.process(meta) if Settings::CONFIG['tagged']
|
26
|
+
|
27
|
+
# Process Archive
|
28
|
+
Archive.process(meta) if Settings::CONFIG['archive']
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Striker
|
2
|
+
module Command
|
3
|
+
class New
|
4
|
+
|
5
|
+
# Generates new site and related directories
|
6
|
+
def self.process(args, options)
|
7
|
+
@site_name = args.join
|
8
|
+
FileUtils.mkdir @site_name
|
9
|
+
FileUtils.cp_r Dir.glob(File.expand_path('../../../new_site', __FILE__) + '/*'), File.join(Dir.pwd, @site_name)
|
10
|
+
FileUtils.mkdir_p File.join(Settings::SOURCE_DIR, @site_name, "media")
|
11
|
+
FileUtils.mkdir_p File.join(Settings::SOURCE_DIR, @site_name, "pages")
|
12
|
+
FileUtils.mkdir_p File.join(Settings::SOURCE_DIR, @site_name, "media/images")
|
13
|
+
FileUtils.mkdir_p File.join(Settings::SOURCE_DIR, @site_name, "media/videos")
|
14
|
+
FileUtils.mkdir_p File.join(Settings::SOURCE_DIR, @site_name, "media/sounds")
|
15
|
+
default_page
|
16
|
+
end
|
17
|
+
|
18
|
+
# TODO: Find an efficient way to handle this.
|
19
|
+
def self.default_page
|
20
|
+
Dir.chdir File.join(Settings::SOURCE_DIR, @site_name)
|
21
|
+
File.open Settings::PAGES_TEMPLATE + '/page.md', 'r' do |file|
|
22
|
+
|
23
|
+
front_matter = {
|
24
|
+
'title' => 'Home Page',
|
25
|
+
'date' => Time.now.strftime("%Y-%m-%d"),
|
26
|
+
'author' => 'Your Name',
|
27
|
+
'template' => 'page'
|
28
|
+
}
|
29
|
+
|
30
|
+
contents = Liquid::Template.parse(file.read).render front_matter
|
31
|
+
File.open(File.join("pages", "index.md"), "w") do |f|
|
32
|
+
f.write contents
|
33
|
+
end
|
34
|
+
end
|
35
|
+
FileUtils.mkdir_p(File.join(Settings::SOURCE_DIR, @site_name, "media/images", "index"))
|
36
|
+
end
|
37
|
+
|
38
|
+
private_class_method :default_page
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Striker
|
2
|
+
module Command
|
3
|
+
class Page
|
4
|
+
|
5
|
+
def self.process(args, options)
|
6
|
+
if options[:new]
|
7
|
+
page_name = options[:new].downcase
|
8
|
+
title = options[:title]
|
9
|
+
new_page page_name, title
|
10
|
+
unless options[:no_media]
|
11
|
+
new_media(options, page_name)
|
12
|
+
end
|
13
|
+
else
|
14
|
+
raise ArgumentError, 'You need to provide a page name'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.new_page(page, title)
|
19
|
+
begin
|
20
|
+
File.open Settings::PAGES_TEMPLATE + '/page.md', 'r' do |file|
|
21
|
+
|
22
|
+
front_matter = {
|
23
|
+
'title' => title,
|
24
|
+
'date' => Time.now.strftime("%Y-%m-%d"),
|
25
|
+
'author' => get_author,
|
26
|
+
'template' => 'page'
|
27
|
+
}
|
28
|
+
|
29
|
+
contents = Liquid::Template.parse(file.read).render front_matter
|
30
|
+
File.open(File.join(Settings::PAGES_DIR, "#{page}.md"), "w") do |f|
|
31
|
+
f.write contents
|
32
|
+
end
|
33
|
+
end
|
34
|
+
rescue Exception => e
|
35
|
+
p e.message
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def self.get_author
|
41
|
+
Dir.chdir
|
42
|
+
if File.exists? '.gitconfig'
|
43
|
+
re = /name\s*=\s*(.*)/
|
44
|
+
File.open('.gitconfig', 'r') do |file|
|
45
|
+
match = file.read.match re
|
46
|
+
if match
|
47
|
+
match[1]
|
48
|
+
else
|
49
|
+
""
|
50
|
+
end
|
51
|
+
end
|
52
|
+
else
|
53
|
+
""
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.new_media(options, page)
|
58
|
+
FileUtils.mkdir(File.join(Settings::MEDIA_DIR, 'images', page)) unless options[:no_image]
|
59
|
+
FileUtils.mkdir(File.join(Settings::MEDIA_DIR, 'sounds', page)) unless options[:no_sound]
|
60
|
+
FileUtils.mkdir(File.join(Settings::MEDIA_DIR, 'videos', page)) unless options[:no_video]
|
61
|
+
end
|
62
|
+
|
63
|
+
private_class_method :get_author, :new_page, :new_media
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'webrick'
|
2
|
+
|
3
|
+
module Striker
|
4
|
+
module Command
|
5
|
+
class Strike
|
6
|
+
|
7
|
+
def self.run(args, options)
|
8
|
+
port = Settings::CONFIG['port']
|
9
|
+
root = Settings::PUBLIC_DIR
|
10
|
+
server = WEBrick::HTTPServer.new(:Port => port, :DocumentRoot => root)
|
11
|
+
|
12
|
+
trap 'INT' do server.shutdown end
|
13
|
+
server.start
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'RMagick'
|
2
|
+
|
3
|
+
module Striker
|
4
|
+
module Media
|
5
|
+
class Image
|
6
|
+
|
7
|
+
include Magick
|
8
|
+
|
9
|
+
attr_reader :page, :image_options
|
10
|
+
attr_accessor :url, :src
|
11
|
+
|
12
|
+
def initialize(page, image_options={})
|
13
|
+
@page = page
|
14
|
+
@dir = File.join(Settings::MEDIA_DIR, "images", page.base_dir) if @page
|
15
|
+
@image_options = image_options
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns all images of a page
|
19
|
+
def all
|
20
|
+
images = []
|
21
|
+
entries.each do |i|
|
22
|
+
if i.match(/\.(jpg|jpeg|bmp|gif|png|svg)$/i) and not i.match(/^thumbnail\.(jpg|jpeg|bmp|gif|png|svg)/i)
|
23
|
+
page_image = ImageList.new(File.join(Settings::MEDIA_DIR, "images", @page.base_dir, i)).first
|
24
|
+
image = {
|
25
|
+
'src' => i,
|
26
|
+
'url' => "/#{Settings::CONFIG['assets']}/images/#{@page.name}-#{i}",
|
27
|
+
'content_type' => mime_type(i)
|
28
|
+
}
|
29
|
+
page_image.write File.join(Settings::ASSETS_DIR, 'images', "#{@page.name}-#{i}")
|
30
|
+
images << image
|
31
|
+
end
|
32
|
+
end
|
33
|
+
images
|
34
|
+
end
|
35
|
+
|
36
|
+
def thumbnail
|
37
|
+
thumbnail = []
|
38
|
+
entries.each do |e|
|
39
|
+
thumbnail << e if e.match(/^thumbnail\.(jpg|jpeg|bmp|gif|png|svg)/i)
|
40
|
+
end
|
41
|
+
if thumbnail.any?
|
42
|
+
full_image = File.join(@dir, thumbnail[0])
|
43
|
+
new_image_name = @page.name + File.extname(full_image)
|
44
|
+
|
45
|
+
{ 'src' => new_image_name, 'content_type' => mime_type(thumbnail[0]), 'url' => File.join('/', Settings::CONFIG['assets'], 'images', new_image_name) }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def thumbnailize
|
50
|
+
base_dir = File.join(Settings::MEDIA_DIR, 'images', @image_options[:context]['base_dir'])
|
51
|
+
src = @image_options[:context]['thumbnail']['src']
|
52
|
+
image = ImageList.new(File.join(base_dir, "thumbnail#{File.extname src}")).first
|
53
|
+
if @image_options[:scale]
|
54
|
+
image.resize!(@image_options[:scale].to_f)
|
55
|
+
elsif @image_options[:width] and @image_options[:height]
|
56
|
+
image.resize!(@image_options[:width].to_i, @image_options[:height].to_i)
|
57
|
+
end
|
58
|
+
image.write File.join(Settings::ASSETS_DIR, 'images', src)
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
def entries
|
63
|
+
entries = []
|
64
|
+
if Dir.exists? @dir
|
65
|
+
Dir.entries(@dir).each do |e|
|
66
|
+
entries << e unless e == '.' or e == '..'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
entries
|
70
|
+
end
|
71
|
+
|
72
|
+
def mime_type(image)
|
73
|
+
MIME::Types.type_for(File.extname(image))[0].content_type
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/striker/page.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'stringex_lite'
|
2
|
+
require 'safe_yaml'
|
3
|
+
|
4
|
+
SafeYAML::OPTIONS[:default_mode] = :safe
|
5
|
+
|
6
|
+
module Striker
|
7
|
+
class Page
|
8
|
+
|
9
|
+
|
10
|
+
attr_reader :meta, :content, :title, :name, :template, :base_dir, :permalink, :filename
|
11
|
+
|
12
|
+
def initialize(page)
|
13
|
+
@filename = page
|
14
|
+
@base_dir = File.basename page, File.extname(page)
|
15
|
+
@page = File.join Settings::PAGES_DIR, page
|
16
|
+
@meta = YAML.load_file(@page)
|
17
|
+
@title = @meta['title']
|
18
|
+
@content = extract_content.post_match
|
19
|
+
@name = @meta['title'].to_url
|
20
|
+
@permalink = permalink_page
|
21
|
+
@template = @meta['template']
|
22
|
+
end
|
23
|
+
|
24
|
+
def page_data
|
25
|
+
data = self.meta
|
26
|
+
data['url'] = page_url
|
27
|
+
data['thumbnail'] = self.image.thumbnail
|
28
|
+
data['name'] = self.name
|
29
|
+
data['filename'] = self.filename
|
30
|
+
data['base_dir'] = self.base_dir
|
31
|
+
data['images'] = self.image.all
|
32
|
+
|
33
|
+
data
|
34
|
+
end
|
35
|
+
|
36
|
+
def image
|
37
|
+
Media::Image.new(self)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.list_full
|
41
|
+
pages = []
|
42
|
+
Dir.chdir(Settings::PAGES_DIR)
|
43
|
+
Dir.glob("*[.md|markdown]").each do |page|
|
44
|
+
pages << Page.new(page).page_data
|
45
|
+
end
|
46
|
+
pages
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def extract_content
|
51
|
+
File.open(@page, 'r').read.match(/^(?<headers>---\s*\n.*?\n?)^(---\s*$\n?)/m)
|
52
|
+
end
|
53
|
+
|
54
|
+
def permalink_page
|
55
|
+
unless Settings::CONFIG['homepage'] == @base_dir
|
56
|
+
filename = case Settings::CONFIG['permalink']['style']
|
57
|
+
when :name
|
58
|
+
@base_dir
|
59
|
+
when :title
|
60
|
+
@name
|
61
|
+
else
|
62
|
+
@name
|
63
|
+
end
|
64
|
+
if Settings::CONFIG['permalink']['pretty']
|
65
|
+
FileUtils.mkdir_p(File.join(Settings::PUBLIC_DIR, filename))
|
66
|
+
filename + "/index.html"
|
67
|
+
else
|
68
|
+
filename + ".html"
|
69
|
+
end
|
70
|
+
else
|
71
|
+
"index.html"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def page_url
|
76
|
+
if @permalink.match(/^index.html/)
|
77
|
+
"/"
|
78
|
+
elsif @permalink.match(/^([\w-]+)\/(index.html)/)
|
79
|
+
"/#{$1}"
|
80
|
+
else
|
81
|
+
"/#{@permalink}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Striker
|
2
|
+
class Settings
|
3
|
+
|
4
|
+
# Default directory paths
|
5
|
+
SOURCE_DIR = Dir.pwd
|
6
|
+
PAGES_DIR = File.join(SOURCE_DIR, 'pages')
|
7
|
+
TEMPLATES_DIR = File.join(SOURCE_DIR, 'templates')
|
8
|
+
MEDIA_DIR = File.join(SOURCE_DIR, 'media')
|
9
|
+
PUBLIC_DIR = File.join(SOURCE_DIR, 'public')
|
10
|
+
|
11
|
+
# Templates path for new page generation
|
12
|
+
PAGES_TEMPLATE = File.expand_path(File.join('../command/templates'), __FILE__)
|
13
|
+
|
14
|
+
# Default configuration from config.yml
|
15
|
+
if File.exists? File.join SOURCE_DIR, 'config.yml'
|
16
|
+
CONFIG = YAML.load_file(File.join(SOURCE_DIR, 'config.yml'))
|
17
|
+
|
18
|
+
ASSETS_DIR = File.join(PUBLIC_DIR, CONFIG['assets'])
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/lib/striker/site.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Striker
|
2
|
+
class Site
|
3
|
+
|
4
|
+
def self.pages(ext=false)
|
5
|
+
pages = []
|
6
|
+
Dir.entries(Settings::PAGES_DIR).each do |page|
|
7
|
+
unless page == '.' or page == '..'
|
8
|
+
if ext
|
9
|
+
pages << page
|
10
|
+
else
|
11
|
+
pages << File.basename(page, File.extname(page))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
pages
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.meta
|
19
|
+
data = Settings::CONFIG
|
20
|
+
data['pages'] = Page.list_full
|
21
|
+
data['tags'] = Tag.list_full
|
22
|
+
data['archive'] = Archive.list_full
|
23
|
+
data
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/lib/striker/tag.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
module Striker
|
2
|
+
class Tag
|
3
|
+
|
4
|
+
attr_reader :tag
|
5
|
+
|
6
|
+
def initialize(tag)
|
7
|
+
@tag = tag
|
8
|
+
end
|
9
|
+
|
10
|
+
def pages
|
11
|
+
pages = []
|
12
|
+
Dir.chdir(Settings::PAGES_DIR)
|
13
|
+
Dir.glob("*[.md|.markdown]").each do |page|
|
14
|
+
page = Page.new(page)
|
15
|
+
pages << page.page_data if page.meta['tags'] and page.meta['tags'].include? tag
|
16
|
+
end
|
17
|
+
pages
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.list
|
21
|
+
tags = []
|
22
|
+
Dir.chdir(Settings::PAGES_DIR)
|
23
|
+
Dir.glob("*[.md|.markdown]").each do |file|
|
24
|
+
page = Page.new(file)
|
25
|
+
tags << page.meta['tags'] if page.meta['tags']
|
26
|
+
end
|
27
|
+
tags.flatten.uniq!
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.list_full
|
31
|
+
tags = []
|
32
|
+
Dir.chdir(Settings::PAGES_DIR)
|
33
|
+
pages = Dir.glob("*[.md|.markdown]").map{ |page| Page.new(page) }
|
34
|
+
self.list.each do |tag|
|
35
|
+
tagged = []
|
36
|
+
pages.each do |page|
|
37
|
+
tagged << page.page_data if page.meta['tags'] and page.meta['tags'].include? tag
|
38
|
+
end
|
39
|
+
tags << { 'name' => tag, 'pages' => tagged }
|
40
|
+
end
|
41
|
+
tags
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.process(site_meta)
|
45
|
+
@@site_meta = site_meta
|
46
|
+
self.list.each do |tag|
|
47
|
+
FileUtils.mkdir_p(File.join(Settings::PUBLIC_DIR, Settings::CONFIG['tagged']['style'], tag))
|
48
|
+
end
|
49
|
+
process_tags
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.process_tags
|
53
|
+
|
54
|
+
# Tag index template for tags
|
55
|
+
index_template = File.open(File.join(Settings::TEMPLATES_DIR, "tags/index.html"), "r").read
|
56
|
+
File.open(File.join(Settings::PUBLIC_DIR, Settings::CONFIG['tagged']['style'], "index.html"), "w") do |f|
|
57
|
+
f.write Liquid::Template.parse(index_template).render(
|
58
|
+
'site' => @@site_meta
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Process each tag
|
63
|
+
template = File.open(File.join(Settings::TEMPLATES_DIR, "tags/tag.html"), "r").read
|
64
|
+
Tag.list.each do |tag|
|
65
|
+
File.open(File.join(Settings::PUBLIC_DIR, Settings::CONFIG['tagged']['style'], tag, "index.html"), "w") do |f|
|
66
|
+
f.write Liquid::Template.parse(template).render(
|
67
|
+
'site' => @@site_meta,
|
68
|
+
'pages' => Tag.new(tag).pages
|
69
|
+
)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private_class_method :process_tags
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|