musako 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +1 -0
- data/bin/musako +45 -0
- data/lib/musako/cli/builder.rb +60 -0
- data/lib/musako/cli/generator.rb +30 -0
- data/lib/musako/cli/server.rb +76 -0
- data/lib/musako/configuration.rb +47 -0
- data/lib/musako/mime.types +85 -0
- data/lib/musako/renderer.rb +33 -0
- data/lib/musako/renderers/feed.rb +30 -0
- data/lib/musako/renderers/index.rb +34 -0
- data/lib/musako/renderers/post.rb +64 -0
- data/lib/musako/renderers/scss.rb +24 -0
- data/lib/musako/version.rb +3 -0
- data/lib/musako.rb +61 -0
- data/lib/templates/Gemfile +3 -0
- data/lib/templates/assets/.scrawl +0 -0
- data/lib/templates/assets/images/.keep +0 -0
- data/lib/templates/assets/javascripts/main.js +0 -0
- data/lib/templates/assets/scss/main.scss +20 -0
- data/lib/templates/config.yml +5 -0
- data/lib/templates/posts/hello.md +15 -0
- data/lib/templates/views/feed.builder +21 -0
- data/lib/templates/views/index.slim +11 -0
- data/lib/templates/views/layouts/application.slim +12 -0
- data/lib/templates/views/post.slim +2 -0
- data/musako.gemspec +28 -0
- metadata +173 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b1e89edcaf30d27f7c24cabb5433aae5aea9fac8
|
4
|
+
data.tar.gz: 31f40c23fa7113b07bc565b2e209340de0e8ea8f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d665cad8a4f331e0b6bb28224ca903b991e1e0baf1032ab4289d1f0fd8cbefaa954ee7dcf922f5fec4c0e2458b94398254e35d9bfb645fc3ed5efff27f13aa1a
|
7
|
+
data.tar.gz: 2f0ead83e68e98d014c37f4cd3d6e53be93dd26d2f6c9b8cf928d0a373fd8c867490137bab86a66e4040a6c71da724297322013ffed37b6e0d5fde5a6b2a0806
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 yo_waka
|
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,44 @@
|
|
1
|
+
# musako
|
2
|
+
|
3
|
+
Simple generator of static site.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'musako'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install musako
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
First, please see help.
|
22
|
+
|
23
|
+
$ musako -h
|
24
|
+
|
25
|
+
Create directories from template (only once).
|
26
|
+
|
27
|
+
$ musako generate
|
28
|
+
|
29
|
+
Write your post, and build
|
30
|
+
|
31
|
+
$ touch posts/blurblur.md
|
32
|
+
$ musako build
|
33
|
+
|
34
|
+
Up local httpd.
|
35
|
+
|
36
|
+
$ musako server -P 3000
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/musako
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'commander/import'
|
4
|
+
require 'musako'
|
5
|
+
|
6
|
+
program :name, 'musako'
|
7
|
+
program :version, Musako::VERSION
|
8
|
+
program :description, 'Musako is a static site generator'
|
9
|
+
|
10
|
+
default_command :help
|
11
|
+
|
12
|
+
command :generate do |c|
|
13
|
+
c.syntax = 'musako generate PATH'
|
14
|
+
c.description = 'Creates a new scaffold in PATH'
|
15
|
+
|
16
|
+
c.action do |args, options|
|
17
|
+
Musako::Cli::Generator.process(args)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
alias_command :g, :generate
|
21
|
+
|
22
|
+
command :build do |c|
|
23
|
+
c.syntax = 'musako build'
|
24
|
+
c.description = 'Build your site'
|
25
|
+
|
26
|
+
c.action do |args, options|
|
27
|
+
options = Musako.configuration(options.__hash__)
|
28
|
+
Musako::Cli::Builder.process(options)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
alias_command :b, :build
|
32
|
+
|
33
|
+
command :serve do |c|
|
34
|
+
c.syntax = 'musako server [options]'
|
35
|
+
c.description = 'Serve your site locally'
|
36
|
+
|
37
|
+
c.option '-D', '--detach', 'Run the server in the background (detach)'
|
38
|
+
c.option '-P', '--port [PORT]', 'Port to listen on'
|
39
|
+
|
40
|
+
c.action do |args, options|
|
41
|
+
options = Musako.configuration(options.__hash__)
|
42
|
+
Musako::Cli::Server.process(options)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
alias_command :s, :serve
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Musako
|
2
|
+
module Cli
|
3
|
+
class Builder
|
4
|
+
def self.process(options)
|
5
|
+
initialize_target_dir
|
6
|
+
begin
|
7
|
+
build_static_files
|
8
|
+
build_page_files
|
9
|
+
rescue => e
|
10
|
+
delete_target_dir
|
11
|
+
raise e
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.build_static_files
|
16
|
+
# scss to css
|
17
|
+
scss_files = File.join(Musako.assets_path, "scss", "**", "*.scss")
|
18
|
+
Dir.glob(scss_files).each do |file|
|
19
|
+
css = Musako::Renderers::Scss.new(file)
|
20
|
+
css.render
|
21
|
+
end
|
22
|
+
|
23
|
+
# copy all static files to target directory
|
24
|
+
FileUtils.cp_r Musako.assets_path, Musako.destination_path
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.build_page_files
|
28
|
+
posts = []
|
29
|
+
|
30
|
+
# posts to html
|
31
|
+
post_files = File.join(Musako.source_path, "posts", "**", "*.md")
|
32
|
+
Dir.glob(post_files).each do |file|
|
33
|
+
post = Musako::Renderers::Post.new(file)
|
34
|
+
post.render
|
35
|
+
|
36
|
+
posts << post
|
37
|
+
end
|
38
|
+
|
39
|
+
views_dir = Musako.views_path
|
40
|
+
|
41
|
+
index_file = File.join(views_dir, "index.slim")
|
42
|
+
Musako::Renderers::Index.new(index_file, posts).render
|
43
|
+
|
44
|
+
feed_file = File.join(views_dir, "feed.builder")
|
45
|
+
Musako::Renderers::Feed.new(feed_file, posts).render
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.initialize_target_dir
|
49
|
+
dest_dir = Musako.destination_path
|
50
|
+
|
51
|
+
FileUtils.remove_entry_secure dest_dir if File.exists? dest_dir
|
52
|
+
FileUtils.mkdir_p dest_dir
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.delete_target_dir
|
56
|
+
FileUtils.remove_entry_secure Musako.destination_path
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Musako
|
2
|
+
module Cli
|
3
|
+
class Generator
|
4
|
+
def self.process(args)
|
5
|
+
if args.empty?
|
6
|
+
args = ["."]
|
7
|
+
end
|
8
|
+
|
9
|
+
path = File.expand_path(args[0], Dir.pwd)
|
10
|
+
|
11
|
+
if !Dir["#{path}/posts"].empty?
|
12
|
+
raise "Error: musako project exists and is not empty."
|
13
|
+
end
|
14
|
+
|
15
|
+
create_templates path
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def self.create_templates(path)
|
21
|
+
t = template
|
22
|
+
FileUtils.cp_r t + '/.', path
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.template
|
26
|
+
File.expand_path("../../templates", File.dirname(__FILE__))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Musako
|
2
|
+
module Cli
|
3
|
+
class Server
|
4
|
+
def self.process(options)
|
5
|
+
require 'webrick'
|
6
|
+
include WEBrick
|
7
|
+
|
8
|
+
unless File.exists?(options[:destination])
|
9
|
+
p "target dir is not found"
|
10
|
+
return
|
11
|
+
end
|
12
|
+
|
13
|
+
# recreate NondisclosureName under utf-8 circumstance
|
14
|
+
fh_option = WEBrick::Config::FileHandler
|
15
|
+
fh_option[:NondisclosureName] = ['.ht*','~*']
|
16
|
+
|
17
|
+
s = HTTPServer.new(webrick_options(options))
|
18
|
+
s.mount(
|
19
|
+
"/",
|
20
|
+
HTTPServlet::FileHandler,
|
21
|
+
options[:destination],
|
22
|
+
fh_option
|
23
|
+
)
|
24
|
+
|
25
|
+
p "Server address: http://#{s.config[:BindAddress]}:#{s.config[:Port]}"
|
26
|
+
|
27
|
+
if options[:detach]
|
28
|
+
# detach the server
|
29
|
+
pid = Process.fork { s.start }
|
30
|
+
Process.detach(pid)
|
31
|
+
p "Server detatched with pid '#{pid}'.", "Run `kill -9 #{pid}' to stop the server."
|
32
|
+
else
|
33
|
+
# create a new server thread, then join it with current terminal
|
34
|
+
t = Thread.new { s.start }
|
35
|
+
trap("INT") { s.shutdown }
|
36
|
+
t.join()
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.webrick_options(config)
|
41
|
+
opts = {
|
42
|
+
:Port => config[:port],
|
43
|
+
:BindAddress => config[:host],
|
44
|
+
:MimeTypes => self.mime_types,
|
45
|
+
:DoNotReverseLookup => true,
|
46
|
+
:StartCallback => start_callback(config[:detach])
|
47
|
+
}
|
48
|
+
|
49
|
+
if !config[:verbose]
|
50
|
+
opts.merge!({
|
51
|
+
:AccessLog => [],
|
52
|
+
:Logger => Log::new([], Log::WARN)
|
53
|
+
})
|
54
|
+
end
|
55
|
+
|
56
|
+
opts
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.start_callback(detached)
|
60
|
+
unless detached
|
61
|
+
Proc.new {
|
62
|
+
p "Server running..., press ctrl-c to stop."
|
63
|
+
}
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.mime_types
|
68
|
+
mime_types_file = File.expand_path(
|
69
|
+
'../mime.types',
|
70
|
+
File.dirname(__FILE__)
|
71
|
+
)
|
72
|
+
WEBrick::HTTPUtils::load_mime_types(mime_types_file)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Musako
|
4
|
+
class Configuration < Hash
|
5
|
+
|
6
|
+
# Default options.
|
7
|
+
DEFAULTS = {
|
8
|
+
source: Dir.pwd,
|
9
|
+
destination: File.join(Dir.pwd, 'target'),
|
10
|
+
views: 'views',
|
11
|
+
assets: 'assets',
|
12
|
+
posts: 'posts',
|
13
|
+
|
14
|
+
port: '3333',
|
15
|
+
host: '0.0.0.0',
|
16
|
+
verbose: true,
|
17
|
+
detach: false,
|
18
|
+
|
19
|
+
author: 'nobody',
|
20
|
+
title: 'my notes',
|
21
|
+
description: 'my tech notes',
|
22
|
+
timezone: 'UTC',
|
23
|
+
site_url: 'http://pages.github.com'
|
24
|
+
}
|
25
|
+
|
26
|
+
# load YAML file.
|
27
|
+
def read_config_file
|
28
|
+
c = clone
|
29
|
+
|
30
|
+
config = YAML.load_file(File.join(DEFAULTS[:source], "config.yml"))
|
31
|
+
unless config.is_a? Hash
|
32
|
+
raise ArgumentError.new("Configuration file: invalid #{file}")
|
33
|
+
end
|
34
|
+
c.merge(config)
|
35
|
+
rescue SystemCallError
|
36
|
+
raise LoadError, "Configuration file: not found #{file}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def symbolize_keys
|
40
|
+
inject({}) do |options, (key, value)|
|
41
|
+
value = value.symbolize_keys if defined?(value.symbolize_keys)
|
42
|
+
options[(key.to_sym rescue key) || key] = value
|
43
|
+
options
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# These are the same MIME types that GitHub Pages uses as of 17 Mar 2013.
|
2
|
+
|
3
|
+
text/html html htm shtml
|
4
|
+
text/css css
|
5
|
+
text/xml xml rss xsl
|
6
|
+
image/gif gif
|
7
|
+
image/jpeg jpeg jpg
|
8
|
+
application/x-javascript js
|
9
|
+
application/atom+xml atom
|
10
|
+
|
11
|
+
text/mathml mml
|
12
|
+
text/plain txt
|
13
|
+
text/vnd.sun.j2me.app-descriptor jad
|
14
|
+
text/vnd.wap.wml wml
|
15
|
+
text/x-component htc
|
16
|
+
text/cache-manifest manifest appcache
|
17
|
+
text/coffeescript coffee
|
18
|
+
text/plain pde
|
19
|
+
text/plain md markdown
|
20
|
+
|
21
|
+
image/png png
|
22
|
+
image/svg+xml svg
|
23
|
+
image/tiff tif tiff
|
24
|
+
image/vnd.wap.wbmp wbmp
|
25
|
+
image/x-icon ico
|
26
|
+
image/x-jng jng
|
27
|
+
image/x-ms-bmp bmp
|
28
|
+
|
29
|
+
application/json json
|
30
|
+
application/java-archive jar ear
|
31
|
+
application/mac-binhex40 hqx
|
32
|
+
application/msword doc
|
33
|
+
application/pdf pdf
|
34
|
+
application/postscript ps eps ai
|
35
|
+
application/rdf+xml rdf
|
36
|
+
application/rtf rtf
|
37
|
+
text/vcard vcf vcard
|
38
|
+
application/vnd.apple.pkpass pkpass
|
39
|
+
application/vnd.ms-excel xls
|
40
|
+
application/vnd.ms-powerpoint ppt
|
41
|
+
application/vnd.wap.wmlc wmlc
|
42
|
+
application/xhtml+xml xhtml
|
43
|
+
application/x-chrome-extension crx
|
44
|
+
application/x-cocoa cco
|
45
|
+
application/x-font-ttf ttf
|
46
|
+
application/x-java-archive-diff jardiff
|
47
|
+
application/x-java-jnlp-file jnlp
|
48
|
+
application/x-makeself run
|
49
|
+
application/x-ns-proxy-autoconfig pac
|
50
|
+
application/x-perl pl pm
|
51
|
+
application/x-pilot prc pdb
|
52
|
+
application/x-rar-compressed rar
|
53
|
+
application/x-redhat-package-manager rpm
|
54
|
+
application/x-sea sea
|
55
|
+
application/x-shockwave-flash swf
|
56
|
+
application/x-stuffit sit
|
57
|
+
application/x-tcl tcl tk
|
58
|
+
application/x-web-app-manifest+json webapp
|
59
|
+
application/x-x509-ca-cert der pem crt
|
60
|
+
application/x-xpinstall xpi
|
61
|
+
application/x-zip war
|
62
|
+
application/zip zip
|
63
|
+
|
64
|
+
application/octet-stream bin exe dll
|
65
|
+
application/octet-stream deb
|
66
|
+
application/octet-stream dmg
|
67
|
+
application/octet-stream eot
|
68
|
+
application/octet-stream iso img
|
69
|
+
application/octet-stream msi msp msm
|
70
|
+
|
71
|
+
audio/midi mid midi kar
|
72
|
+
audio/mpeg mp3
|
73
|
+
audio/x-realaudio ra
|
74
|
+
audio/ogg ogg
|
75
|
+
|
76
|
+
video/3gpp 3gpp 3gp
|
77
|
+
video/mpeg mpeg mpg
|
78
|
+
video/quicktime mov
|
79
|
+
video/x-flv flv
|
80
|
+
video/x-mng mng
|
81
|
+
video/x-ms-asf asx asf
|
82
|
+
video/x-ms-wmv wmv
|
83
|
+
video/x-msvideo avi
|
84
|
+
video/ogg ogv
|
85
|
+
video/webm webm
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Musako
|
2
|
+
class Renderer
|
3
|
+
def initialize(file)
|
4
|
+
@original_file = file
|
5
|
+
end
|
6
|
+
|
7
|
+
# write file
|
8
|
+
def render
|
9
|
+
raise NoImplementationError
|
10
|
+
end
|
11
|
+
|
12
|
+
def file_name
|
13
|
+
File.basename(@original_file)
|
14
|
+
.gsub(File.extname(@original_file), self.file_extname)
|
15
|
+
end
|
16
|
+
|
17
|
+
def file_extname
|
18
|
+
@file_extname || ""
|
19
|
+
end
|
20
|
+
|
21
|
+
def file_updated_at
|
22
|
+
File.stat(@original_file).mtime
|
23
|
+
end
|
24
|
+
|
25
|
+
def file_path
|
26
|
+
File.new(@original_file).path
|
27
|
+
end
|
28
|
+
|
29
|
+
def original_file_source
|
30
|
+
File.open(@original_file, 'r').read
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "tilt"
|
2
|
+
require "builder"
|
3
|
+
|
4
|
+
module Musako
|
5
|
+
module Renderers
|
6
|
+
class Feed < Renderer
|
7
|
+
attr_accessor :posts
|
8
|
+
|
9
|
+
def initialize(file, posts)
|
10
|
+
super file
|
11
|
+
@file_extname = ".xml"
|
12
|
+
@posts = posts
|
13
|
+
end
|
14
|
+
|
15
|
+
def render
|
16
|
+
contents = Tilt.new(
|
17
|
+
File.join(Musako.views_path, "feed.builder")
|
18
|
+
).render(self, {posts: @posts, config: Musako.configuration})
|
19
|
+
|
20
|
+
File.open(self.output_path, "w") do |file|
|
21
|
+
file.write contents
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def output_path
|
26
|
+
File.join(Musako.destination_path, self.file_name)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'slim'
|
2
|
+
|
3
|
+
module Musako
|
4
|
+
module Renderers
|
5
|
+
class Index < Renderer
|
6
|
+
attr_accessor :posts
|
7
|
+
|
8
|
+
def initialize(file, posts)
|
9
|
+
super file
|
10
|
+
|
11
|
+
@file_extname = ".html"
|
12
|
+
@posts = posts
|
13
|
+
end
|
14
|
+
|
15
|
+
def render
|
16
|
+
contents = Slim::Template.new(
|
17
|
+
File.join(Musako.views_path, "index.slim")
|
18
|
+
).render(self, {posts: @posts, config: Musako.configuration})
|
19
|
+
|
20
|
+
layout = Slim::Template.new(
|
21
|
+
File.join(Musako.views_path, "layouts", "application.slim")
|
22
|
+
).render(self, {title: Musako.configuration[:title]}) { contents }
|
23
|
+
|
24
|
+
File.open(self.output_path, "w") do |file|
|
25
|
+
file.write layout
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def output_path
|
30
|
+
File.join(Musako.destination_path, self.file_name)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'slim'
|
2
|
+
require 'redcarpet'
|
3
|
+
|
4
|
+
module Musako
|
5
|
+
module Renderers
|
6
|
+
class Post < Renderer
|
7
|
+
attr_reader :html, :title, :date, :iso_date, :url, :path
|
8
|
+
|
9
|
+
def initialize(file)
|
10
|
+
super file
|
11
|
+
@file_extname = ".html"
|
12
|
+
end
|
13
|
+
|
14
|
+
def render
|
15
|
+
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,
|
16
|
+
:autolink => true,
|
17
|
+
:space_after_headers => true,
|
18
|
+
:fenced_code_blocks => true
|
19
|
+
)
|
20
|
+
@html = markdown.render(self.original_file_source)
|
21
|
+
|
22
|
+
# use first header tag as title
|
23
|
+
title = if @html =~ /<h1>(.*?)<\/h1>/
|
24
|
+
$1
|
25
|
+
else
|
26
|
+
"No title"
|
27
|
+
end
|
28
|
+
self.set_meta_data(title)
|
29
|
+
|
30
|
+
post = Slim::Template.new(
|
31
|
+
File.join(Musako.views_path, "post.slim")
|
32
|
+
).render(self, {post: self, config: Musako.configuration})
|
33
|
+
|
34
|
+
layout = Slim::Template.new(
|
35
|
+
File.join(Musako.views_path, "layouts", "application.slim")
|
36
|
+
).render(self, {title: Musako.configuration[:title]}) { post }
|
37
|
+
|
38
|
+
dir = File.dirname(self.output_path)
|
39
|
+
unless File.directory? dir
|
40
|
+
FileUtils.mkdir_p dir
|
41
|
+
end
|
42
|
+
|
43
|
+
File.open(self.output_path, "w") do |file|
|
44
|
+
file.write layout
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# create directory from file's updated_at
|
49
|
+
def output_path
|
50
|
+
File.join(Musako.destination_path, @url)
|
51
|
+
end
|
52
|
+
|
53
|
+
def set_meta_data(title)
|
54
|
+
time = self.file_updated_at
|
55
|
+
|
56
|
+
@title = title
|
57
|
+
@date = time
|
58
|
+
@iso_date = time.strftime("%FT%T%z")
|
59
|
+
@url = File.join("#{time.year}/#{time.month}/#{time.day}", self.file_name)
|
60
|
+
@path = self.file_path
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'sass'
|
2
|
+
|
3
|
+
module Musako
|
4
|
+
module Renderers
|
5
|
+
class Scss < Renderer
|
6
|
+
def initialize(file)
|
7
|
+
super file
|
8
|
+
@file_extname = ".css"
|
9
|
+
end
|
10
|
+
|
11
|
+
def render
|
12
|
+
compiled = Sass::Engine.new(self.original_file_source, syntax: :scss)
|
13
|
+
.render
|
14
|
+
File.open(self.output_path, "w") do |file|
|
15
|
+
file.write compiled
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def output_path
|
20
|
+
File.join(Musako.assets_path, "stylesheets", self.file_name)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/musako.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Require all files in directory.
|
2
|
+
def require_all(path)
|
3
|
+
glob = File.join(File.dirname(__FILE__), path, '*.rb')
|
4
|
+
Dir[glob].each do |f|
|
5
|
+
require f
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
# rubygems
|
10
|
+
require 'rubygems'
|
11
|
+
|
12
|
+
# stdlib
|
13
|
+
require 'fileutils'
|
14
|
+
|
15
|
+
# internal
|
16
|
+
require "musako/version"
|
17
|
+
require "musako/configuration"
|
18
|
+
require "musako/renderer"
|
19
|
+
|
20
|
+
require_all "musako/cli"
|
21
|
+
require_all "musako/renderers"
|
22
|
+
|
23
|
+
# end point
|
24
|
+
module Musako
|
25
|
+
def self.configuration(options = {})
|
26
|
+
return @config if @config
|
27
|
+
|
28
|
+
config = Configuration[Configuration::DEFAULTS]
|
29
|
+
config = config.read_config_file
|
30
|
+
config = config.merge(options).symbolize_keys
|
31
|
+
|
32
|
+
ENV['TZ'] = config[:timezone]
|
33
|
+
@config = config
|
34
|
+
@config
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.source_path
|
38
|
+
config = configuration
|
39
|
+
config[:source]
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.destination_path
|
43
|
+
config = configuration
|
44
|
+
config[:destination]
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.views_path
|
48
|
+
config = configuration
|
49
|
+
File.join(config[:source], config[:views])
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.posts_path
|
53
|
+
config = configuration
|
54
|
+
File.join(config[:source], config[:posts])
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.assets_path
|
58
|
+
config = configuration
|
59
|
+
File.join(config[:source], config[:assets])
|
60
|
+
end
|
61
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -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.subtitle config[:description]
|
5
|
+
xml.id config[:site_url]
|
6
|
+
xml.link "href" => config[:site_url]
|
7
|
+
xml.updated posts.first.iso_date unless posts.empty?
|
8
|
+
xml.author { xml.name config[:author] }
|
9
|
+
|
10
|
+
posts[0..5].each do |post|
|
11
|
+
xml.entry do
|
12
|
+
xml.title post.title
|
13
|
+
xml.link "rel" => "alternate", "href" => URI.join(config[:site_url], post.url)
|
14
|
+
xml.id URI.join(config[:site_url], post.url)
|
15
|
+
xml.published post.iso_date
|
16
|
+
xml.updated File.mtime(post.path)
|
17
|
+
xml.author { xml.name config[:author] }
|
18
|
+
xml.content post.html, "type" => "html"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
doctype html
|
2
|
+
html
|
3
|
+
head
|
4
|
+
meta charset="utf-8"
|
5
|
+
meta http-equiv="X-UA-Compatible" content="IE=edge;chrome=1"
|
6
|
+
title = title
|
7
|
+
link rel="alternate" type="application/atom+xml" title="Atom Feed" href="/feed.xml"
|
8
|
+
link rel="stylesheet" type="text/css" href="/assets/stylesheets/main.css"
|
9
|
+
link rel="icon" type="image/png" href="/assets/images/favicon.png"
|
10
|
+
body
|
11
|
+
div class="container"
|
12
|
+
== yield
|
data/musako.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'musako/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "musako"
|
8
|
+
spec.version = Musako::VERSION
|
9
|
+
spec.authors = ["yo_waka"]
|
10
|
+
spec.email = ["y.wakahara@gmail.com"]
|
11
|
+
spec.summary = %q{A simple static site generator}
|
12
|
+
spec.homepage = "https://github.com/waka/musako"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_runtime_dependency "slim"
|
21
|
+
spec.add_runtime_dependency "redcarpet"
|
22
|
+
spec.add_runtime_dependency "builder"
|
23
|
+
spec.add_runtime_dependency "sass"
|
24
|
+
spec.add_runtime_dependency "commander"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: musako
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- yo_waka
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: slim
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: redcarpet
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: builder
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sass
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: commander
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- y.wakahara@gmail.com
|
114
|
+
executables:
|
115
|
+
- musako
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- .gitignore
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- bin/musako
|
125
|
+
- lib/musako.rb
|
126
|
+
- lib/musako/cli/builder.rb
|
127
|
+
- lib/musako/cli/generator.rb
|
128
|
+
- lib/musako/cli/server.rb
|
129
|
+
- lib/musako/configuration.rb
|
130
|
+
- lib/musako/mime.types
|
131
|
+
- lib/musako/renderer.rb
|
132
|
+
- lib/musako/renderers/feed.rb
|
133
|
+
- lib/musako/renderers/index.rb
|
134
|
+
- lib/musako/renderers/post.rb
|
135
|
+
- lib/musako/renderers/scss.rb
|
136
|
+
- lib/musako/version.rb
|
137
|
+
- lib/templates/Gemfile
|
138
|
+
- lib/templates/assets/.scrawl
|
139
|
+
- lib/templates/assets/images/.keep
|
140
|
+
- lib/templates/assets/javascripts/main.js
|
141
|
+
- lib/templates/assets/scss/main.scss
|
142
|
+
- lib/templates/config.yml
|
143
|
+
- lib/templates/posts/hello.md
|
144
|
+
- lib/templates/views/feed.builder
|
145
|
+
- lib/templates/views/index.slim
|
146
|
+
- lib/templates/views/layouts/application.slim
|
147
|
+
- lib/templates/views/post.slim
|
148
|
+
- musako.gemspec
|
149
|
+
homepage: https://github.com/waka/musako
|
150
|
+
licenses:
|
151
|
+
- MIT
|
152
|
+
metadata: {}
|
153
|
+
post_install_message:
|
154
|
+
rdoc_options: []
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - '>='
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
requirements: []
|
168
|
+
rubyforge_project:
|
169
|
+
rubygems_version: 2.0.14
|
170
|
+
signing_key:
|
171
|
+
specification_version: 4
|
172
|
+
summary: A simple static site generator
|
173
|
+
test_files: []
|