meta 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +16 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +43 -0
- data/LICENSE +23 -0
- data/README.md +28 -0
- data/Rakefile +39 -0
- data/bin/meta +4 -0
- data/config/config.ru +2 -0
- data/db/migrate/001_init_database.rb +42 -0
- data/db/migrate/002_picture.rb +16 -0
- data/db/migrate/003_remove_templates.rb +31 -0
- data/db/migrate/004_remove_fk.rb +16 -0
- data/db/site.sqlite3 +0 -0
- data/docs/backlog +26 -0
- data/docs/design +39 -0
- data/lib/meta/catalog.rb +168 -0
- data/lib/meta/cli.rb +112 -0
- data/lib/meta/filelib.rb +68 -0
- data/lib/meta/page.rb +129 -0
- data/lib/meta/version.rb +4 -0
- data/lib/meta.rb +40 -0
- data/meta.gemspec +25 -0
- metadata +101 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in meta.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem "colorize"
|
7
|
+
gem "haml"
|
8
|
+
gem "highline"
|
9
|
+
gem "rack"
|
10
|
+
gem "redcarpet"
|
11
|
+
gem "sequel"
|
12
|
+
gem "sqlite3"
|
13
|
+
gem "thin"
|
14
|
+
gem "thor"
|
15
|
+
gem "tilt"
|
16
|
+
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
meta (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
colorize (0.6.0)
|
10
|
+
daemons (1.1.9)
|
11
|
+
eventmachine (1.0.3)
|
12
|
+
haml (4.0.4)
|
13
|
+
tilt
|
14
|
+
highline (1.6.20)
|
15
|
+
rack (1.5.2)
|
16
|
+
rake (10.1.0)
|
17
|
+
redcarpet (3.0.0)
|
18
|
+
sequel (4.5.0)
|
19
|
+
sqlite3 (1.3.8)
|
20
|
+
thin (1.6.1)
|
21
|
+
daemons (>= 1.0.9)
|
22
|
+
eventmachine (>= 1.0.0)
|
23
|
+
rack (>= 1.0.0)
|
24
|
+
thor (0.18.1)
|
25
|
+
tilt (2.0.0)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
bundler (~> 1.3)
|
32
|
+
colorize
|
33
|
+
haml
|
34
|
+
highline
|
35
|
+
meta!
|
36
|
+
rack
|
37
|
+
rake
|
38
|
+
redcarpet
|
39
|
+
sequel
|
40
|
+
sqlite3
|
41
|
+
thin
|
42
|
+
thor
|
43
|
+
tilt
|
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2013 Stephen Hu
|
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.
|
23
|
+
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# meta compiler (meta)
|
2
|
+
|
3
|
+
## introduction
|
4
|
+
meta is an opinionated static site generator used to compile haml templates
|
5
|
+
and markdown pages into html/css/js files. these pages can then be served
|
6
|
+
from github pages or other static site services like bluehost. meta can also
|
7
|
+
be used to test/preview static pages in your development environment without
|
8
|
+
having to deploy into production.
|
9
|
+
|
10
|
+
## requirements
|
11
|
+
* ruby 1.9.2+
|
12
|
+
* bundler
|
13
|
+
* colorize
|
14
|
+
* haml
|
15
|
+
* highline
|
16
|
+
* rack
|
17
|
+
* redcarpet
|
18
|
+
* sequel
|
19
|
+
* sqlite3
|
20
|
+
* thin
|
21
|
+
* thor
|
22
|
+
* tilt
|
23
|
+
|
24
|
+
## installation
|
25
|
+
```gem install meta```
|
26
|
+
|
27
|
+
## faq
|
28
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "sequel"
|
3
|
+
require "sqlite3"
|
4
|
+
|
5
|
+
DB = "db/site.sqlite3".freeze
|
6
|
+
|
7
|
+
Sequel.extension :migration, :core_extensions
|
8
|
+
|
9
|
+
task :default => :help
|
10
|
+
|
11
|
+
namespace :db do
|
12
|
+
|
13
|
+
desc "instantiate database"
|
14
|
+
task :create do
|
15
|
+
|
16
|
+
SQLite3::Database.new(DB)
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "migrate database"
|
21
|
+
task :migrate do
|
22
|
+
|
23
|
+
# sequel -m db/migrate sqlite://site.sqlite3
|
24
|
+
conn = Sequel.sqlite(DB)
|
25
|
+
Sequel::Migrator.run( conn, "db/migrate" )
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "help"
|
32
|
+
task :help do
|
33
|
+
|
34
|
+
puts "rake"
|
35
|
+
puts " db:create"
|
36
|
+
puts " db:migrate"
|
37
|
+
|
38
|
+
end
|
39
|
+
|
data/bin/meta
ADDED
data/config/config.ru
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
Sequel.migration do
|
2
|
+
|
3
|
+
up do
|
4
|
+
|
5
|
+
create_table(:templates) do
|
6
|
+
primary_key :id
|
7
|
+
String :path, :null => false
|
8
|
+
String :hash, :unique => true
|
9
|
+
Time :created_at, :default => Time.now
|
10
|
+
Time :updated_at, :default => Time.now
|
11
|
+
end
|
12
|
+
|
13
|
+
create_table(:contents) do
|
14
|
+
primary_key :id
|
15
|
+
String :path, :null => false
|
16
|
+
String :hash, :unique => true
|
17
|
+
String :title, :null => false
|
18
|
+
Time :created_at, :default => Time.now
|
19
|
+
Time :updated_at, :default => Time.now
|
20
|
+
foreign_key :template_id, :templates
|
21
|
+
end
|
22
|
+
|
23
|
+
create_table(:revisions) do
|
24
|
+
primary_key :id
|
25
|
+
String :revisionid, :null => false
|
26
|
+
String :previousid, :null => false
|
27
|
+
Time :created_at, :default => Time.now
|
28
|
+
Time :updated_at, :default => Time.now
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
down do
|
34
|
+
|
35
|
+
drop_table(:templates)
|
36
|
+
drop_table(:contents)
|
37
|
+
drop_table(:revisions)
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Sequel.migration do
|
2
|
+
|
3
|
+
up do
|
4
|
+
|
5
|
+
drop_table(:templates)
|
6
|
+
drop_table(:revisions)
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
down do
|
11
|
+
|
12
|
+
create_table(:templates) do
|
13
|
+
primary_key :id
|
14
|
+
String :path, :null => false
|
15
|
+
String :hash, :unique => true
|
16
|
+
Time :created_at, :default => Time.now
|
17
|
+
Time :updated_at, :default => Time.now
|
18
|
+
end
|
19
|
+
|
20
|
+
create_table(:revisions) do
|
21
|
+
primary_key :id
|
22
|
+
String :revisionid, :null => false
|
23
|
+
String :previousid, :null => false
|
24
|
+
Time :created_at, :default => Time.now
|
25
|
+
Time :updated_at, :default => Time.now
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
data/db/site.sqlite3
ADDED
Binary file
|
data/docs/backlog
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
open:
|
2
|
+
+ migrate schema without losing any data
|
3
|
+
+ multiple templates
|
4
|
+
+ syntax highlighting for code
|
5
|
+
+ title modification
|
6
|
+
+ referencing a link and commenting on that
|
7
|
+
|
8
|
+
iced:
|
9
|
+
+ support uppercase file extensions
|
10
|
+
+ detect and compile changes only
|
11
|
+
+ tie static files with source repository
|
12
|
+
+ clone template files
|
13
|
+
+ crop articles
|
14
|
+
+ .haml files all expected to be in current directory along with .md files
|
15
|
+
|
16
|
+
closed:
|
17
|
+
+ create index of articles
|
18
|
+
+ list articles based on date
|
19
|
+
+ support .markdown, .mkd file extensions
|
20
|
+
+ randomize col8a and colb
|
21
|
+
+ -f option to overwrite all files
|
22
|
+
+ destination directory
|
23
|
+
+ check new files into database
|
24
|
+
+ single entry template
|
25
|
+
+ add config.ru file for testing, this should be added during compilation
|
26
|
+
+ google analytics
|
data/docs/design
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
requirements:
|
2
|
+
|
3
|
+
+ support haml, md
|
4
|
+
+ static page preview
|
5
|
+
+ static page indexing
|
6
|
+
|
7
|
+
design:
|
8
|
+
|
9
|
+
directory layout example:
|
10
|
+
|
11
|
+
+ src
|
12
|
+
+-- site.db
|
13
|
+
+-- article1.md
|
14
|
+
+-- article2.md
|
15
|
+
+-- layout.haml
|
16
|
+
+-- navbar.haml
|
17
|
+
+-- footer.haml
|
18
|
+
+-- css
|
19
|
+
+-- images
|
20
|
+
+-- js
|
21
|
+
|
22
|
+
* create a flat hierarchy of html files
|
23
|
+
* js, css, images are found in folders
|
24
|
+
* reference architecture suggests that source files be stored in src folder
|
25
|
+
|
26
|
+
sitemap:
|
27
|
+
|
28
|
+
sqlite database for indexing pages
|
29
|
+
|
30
|
+
articles( id, creation, modification, title, layout, src )
|
31
|
+
|
32
|
+
|
33
|
+
1. crawl src directory for files ending with .haml, .md (.mkd, .markdown)
|
34
|
+
2. hash files, compare with site.sqlite3 file to find revisions
|
35
|
+
3. create main page consisting of default latest 10
|
36
|
+
a. shrink content to less than x words
|
37
|
+
b. organize by latest at the top
|
38
|
+
4. create individual pages
|
39
|
+
|
data/lib/meta/catalog.rb
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
module Meta
|
2
|
+
|
3
|
+
class Catalog
|
4
|
+
|
5
|
+
attr_accessor :db
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
|
9
|
+
self.db = Sequel.sqlite(Meta::DATASTORE)
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
def content_exists?(file)
|
14
|
+
|
15
|
+
rs = self.db[:contents].where(:path => file).all
|
16
|
+
|
17
|
+
if rs.empty?
|
18
|
+
return false
|
19
|
+
else
|
20
|
+
return true
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_content(file)
|
26
|
+
|
27
|
+
rs = self.db[:contents].where(:path => file).first
|
28
|
+
|
29
|
+
return rs
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_recent(count)
|
34
|
+
|
35
|
+
if count < 0
|
36
|
+
rs = self.db[:contents].order(Sequel.desc(:created_at)).all
|
37
|
+
else
|
38
|
+
rs = self.db[:contents].order(Sequel.desc(:created_at)).limit(
|
39
|
+
count).all
|
40
|
+
end
|
41
|
+
|
42
|
+
rs.each do |r|
|
43
|
+
content = Tilt.new(r[:path]).render
|
44
|
+
|
45
|
+
content = "abc" if content.empty?
|
46
|
+
|
47
|
+
r[:summary] = content
|
48
|
+
r[:link] = File.basename( r[:path], File.extname(r[:path]) ) +
|
49
|
+
HTMLEXT
|
50
|
+
r[:picture] = false
|
51
|
+
end
|
52
|
+
|
53
|
+
return rs
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def check_content(content)
|
58
|
+
|
59
|
+
hash = Digest::MD5.hexdigest(content)
|
60
|
+
|
61
|
+
if content_exists?(content)
|
62
|
+
revise_content( content, hash )
|
63
|
+
else
|
64
|
+
title = ask "Please add a Title for #{content}? "
|
65
|
+
add_content( content, title, hash )
|
66
|
+
end
|
67
|
+
|
68
|
+
return self.db[:contents].where(:hash => hash).first()
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
def add_content( file, title, hash )
|
73
|
+
|
74
|
+
self.db[:contents].insert(
|
75
|
+
:title => title,
|
76
|
+
:hash => hash,
|
77
|
+
:path => file,
|
78
|
+
:created_at => File.ctime(file) )
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
def revise_content( file, hash )
|
83
|
+
|
84
|
+
#puts self.db[:contents].where(:path => file).select(:title).first()[:title]
|
85
|
+
self.db[:contents].where(:path => file).update(
|
86
|
+
:hash => hash,
|
87
|
+
#:title => title,
|
88
|
+
:updated_at => Time.now )
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
def update_content_title( file, title )
|
93
|
+
|
94
|
+
self.db[:contents].where(:path => file).update(
|
95
|
+
:title => title, :updated_at => Time.now )
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
def check_templates(templates)
|
100
|
+
|
101
|
+
templates.each do |t|
|
102
|
+
|
103
|
+
hash = Digest::MD5.hexdigest(t)
|
104
|
+
|
105
|
+
if template_exists?(t)
|
106
|
+
|
107
|
+
revise_template( t, hash )
|
108
|
+
|
109
|
+
else
|
110
|
+
|
111
|
+
add_template( t, hash )
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
def add_template( file, hash )
|
120
|
+
|
121
|
+
self.db[:templates].insert(
|
122
|
+
:path => file,
|
123
|
+
:hash => hash )
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
def revise_template( file, hash )
|
128
|
+
|
129
|
+
rs = self.db[:templates].where( :hash => hash, :path => file ).first
|
130
|
+
|
131
|
+
if rs.empty?
|
132
|
+
|
133
|
+
self.db[:templates].insert(
|
134
|
+
:path => file,
|
135
|
+
:hash => hash )
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
def template_exists?(file)
|
142
|
+
|
143
|
+
rs = self.db[:templates].where(:path => file).all
|
144
|
+
|
145
|
+
if rs.empty?
|
146
|
+
return false
|
147
|
+
else
|
148
|
+
return true
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
def template_revised?( path, hash )
|
154
|
+
|
155
|
+
rs = self.db[:templates].where( :hash => hash, :path => path )
|
156
|
+
|
157
|
+
if rs.nil?
|
158
|
+
return true
|
159
|
+
else
|
160
|
+
return false
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
data/lib/meta/cli.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
module Meta
|
2
|
+
|
3
|
+
class CLI < Thor
|
4
|
+
include Thor::Actions
|
5
|
+
|
6
|
+
desc "compile", "compile meta files"
|
7
|
+
method_option :output, :aliases => "-o", :type => :string,
|
8
|
+
:required => false, :desc => "static file output directory"
|
9
|
+
#method_option :exclude, :aliases => "-e", :type => :string,
|
10
|
+
# :required => false, :desc => "comma separated list"
|
11
|
+
method_option :force, :aliases => "-f", :type => :boolean,
|
12
|
+
:required => false, :desc => "don't prompt to overwrite files"
|
13
|
+
def compile
|
14
|
+
|
15
|
+
if options[:output].nil?
|
16
|
+
dest = "."
|
17
|
+
else
|
18
|
+
dest = options[:output]
|
19
|
+
end
|
20
|
+
|
21
|
+
p = Meta::Page.new(dest)
|
22
|
+
|
23
|
+
p.generate(options[:force])
|
24
|
+
p.generate_main(options[:force])
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "init", "initialize static meta project"
|
29
|
+
def init
|
30
|
+
|
31
|
+
f = File.join( File.dirname(__FILE__), "../../db/site.sqlite3" )
|
32
|
+
|
33
|
+
if File.exists?("site.sqlite3")
|
34
|
+
|
35
|
+
puts "Warning: All index data will be lost!".red
|
36
|
+
reply = agree("Database already exists, overwrite?".red) {
|
37
|
+
|q| q.default = "n" }
|
38
|
+
|
39
|
+
if reply
|
40
|
+
FileUtils.cp( f, Dir.pwd )
|
41
|
+
puts "Database re-initialized".green
|
42
|
+
else
|
43
|
+
puts "Database not initialized".red
|
44
|
+
end
|
45
|
+
|
46
|
+
else
|
47
|
+
|
48
|
+
FileUtils.cp( f, Dir.pwd )
|
49
|
+
puts "Database initialized".green
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
desc "stage", "staging environment"
|
56
|
+
def stage
|
57
|
+
|
58
|
+
config = File.join( File.dirname(__FILE__), "../../config/config.ru" )
|
59
|
+
|
60
|
+
if File.exists?("config.ru")
|
61
|
+
puts "Environment has already been staged, no action taken.".yellow
|
62
|
+
else
|
63
|
+
|
64
|
+
FileUtils.cp( config, Dir.pwd )
|
65
|
+
puts "Run 'rackup' to start testing.".green
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
desc "title", "Change Title"
|
72
|
+
def title(file)
|
73
|
+
|
74
|
+
catalog = Meta::Catalog.new
|
75
|
+
|
76
|
+
f = catalog.get_content(file)
|
77
|
+
|
78
|
+
unless f.nil?
|
79
|
+
|
80
|
+
puts "Current Title: #{f[:title]}"
|
81
|
+
reply = ask "New Title? ".yellow
|
82
|
+
|
83
|
+
unless reply.empty?
|
84
|
+
|
85
|
+
response = agree(
|
86
|
+
"Are you certain that you want to make this change? ") {
|
87
|
+
|q| q.default = "n" }
|
88
|
+
|
89
|
+
catalog.update_content_title( file, reply ) if response
|
90
|
+
|
91
|
+
else
|
92
|
+
puts "Title cannot be empty, no action taken.".red
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
desc "test", "testing"
|
100
|
+
def test
|
101
|
+
|
102
|
+
p = Meta::Page.new
|
103
|
+
p.generate_main
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
default_task :compile
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
data/lib/meta/filelib.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
module Meta
|
2
|
+
|
3
|
+
module Filelib
|
4
|
+
|
5
|
+
def self.create_directory(name)
|
6
|
+
|
7
|
+
unless name.nil?
|
8
|
+
|
9
|
+
if File.directory?(name)
|
10
|
+
puts "directory already exists"
|
11
|
+
else
|
12
|
+
FileUtils.mkdir_p(name)
|
13
|
+
puts "directory #{name} created".green
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.create_file( text, filename, dest, overwrite=false )
|
21
|
+
|
22
|
+
filename = File.basename( filename, File.extname(filename) ) + HTMLEXT
|
23
|
+
filename = dest + SLASH + filename
|
24
|
+
|
25
|
+
reply = false
|
26
|
+
write = false
|
27
|
+
|
28
|
+
if File.exists?(filename)
|
29
|
+
|
30
|
+
reply = agree("file #{filename} exists, overwrite?".red) {
|
31
|
+
|q| q.default = "n" } unless overwrite
|
32
|
+
|
33
|
+
else
|
34
|
+
write = true
|
35
|
+
end
|
36
|
+
|
37
|
+
if overwrite or reply or write
|
38
|
+
|
39
|
+
f = File.open( filename, "w" )
|
40
|
+
f.write(text)
|
41
|
+
f.close
|
42
|
+
|
43
|
+
if overwrite or reply
|
44
|
+
puts "file #{filename} overwritten".green
|
45
|
+
else
|
46
|
+
puts "file #{filename} created".green
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.get_templates()
|
54
|
+
|
55
|
+
return Dir.glob( Meta::HAML, File::FNM_CASEFOLD )
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.get_contents()
|
60
|
+
|
61
|
+
return Dir.glob( Meta::MARKDOWN, File::FNM_CASEFOLD )
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
data/lib/meta/page.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
module Meta
|
2
|
+
|
3
|
+
class Page
|
4
|
+
|
5
|
+
attr_reader :layout, :navbar, :catalog
|
6
|
+
|
7
|
+
def initialize(dest=BASEDIR)
|
8
|
+
|
9
|
+
@dest = dest
|
10
|
+
|
11
|
+
@catalog = Meta::Catalog.new
|
12
|
+
|
13
|
+
@layout = Tilt.new("layout.haml")
|
14
|
+
@navbar = Tilt.new("navbar.haml")
|
15
|
+
@col = Tilt.new("col.haml")
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def generate_row(contents)
|
20
|
+
|
21
|
+
length = contents.length
|
22
|
+
|
23
|
+
if length == 1
|
24
|
+
contents[0][:col_classes] = "col-lg-12 box"
|
25
|
+
elsif length == 2
|
26
|
+
|
27
|
+
rng = Random.new(SEED)
|
28
|
+
|
29
|
+
r = rng.rand(1..3)
|
30
|
+
|
31
|
+
if r == 3
|
32
|
+
contents[0][:col_classes] = "col-lg-6 box"
|
33
|
+
contents[1][:col_classes] = "col-lg-6 box"
|
34
|
+
elsif r == 2
|
35
|
+
contents[0][:col_classes] = "col-lg-8 box"
|
36
|
+
contents[1][:col_classes] = "col-lg-4 box"
|
37
|
+
else
|
38
|
+
contents[0][:col_classes] = "col-lg-4 box"
|
39
|
+
contents[1][:col_classes] = "col-lg-8 box"
|
40
|
+
end
|
41
|
+
|
42
|
+
elsif length == 3
|
43
|
+
contents[0][:col_classes] = "col-lg-4 box"
|
44
|
+
contents[1][:col_classes] = "col-lg-4 box"
|
45
|
+
contents[2][:col_classes] = "col-lg-4 box"
|
46
|
+
else
|
47
|
+
contents[0][:col_classes] = "col-lg-3 box"
|
48
|
+
contents[1][:col_classes] = "col-lg-3 box"
|
49
|
+
contents[2][:col_classes] = "col-lg-3 box"
|
50
|
+
contents[3][:col_classes] = "col-lg-3 box"
|
51
|
+
end
|
52
|
+
|
53
|
+
return contents
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def generate_main(overwrite=false)
|
58
|
+
|
59
|
+
c = @catalog.get_recent(-1)
|
60
|
+
|
61
|
+
length = c.length
|
62
|
+
remain = length
|
63
|
+
index = 0
|
64
|
+
|
65
|
+
rows = []
|
66
|
+
|
67
|
+
rng = Random.new(SEED)
|
68
|
+
|
69
|
+
while remain != 0 do
|
70
|
+
|
71
|
+
n = rng.rand(1..remain)
|
72
|
+
|
73
|
+
r = generate_row(c[index..index+n-1])
|
74
|
+
|
75
|
+
remain = remain - n
|
76
|
+
index = index + n
|
77
|
+
|
78
|
+
rows << r
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
doc = @col.render( self, :rows => rows )
|
83
|
+
|
84
|
+
html = @layout.render { doc }
|
85
|
+
|
86
|
+
Meta::Filelib.create_file( html, INDEX, @dest, overwrite )
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
def generate(overwrite=false)
|
91
|
+
|
92
|
+
all = Meta::Filelib.get_contents
|
93
|
+
|
94
|
+
all.each do |c|
|
95
|
+
|
96
|
+
if File.zero?(c)
|
97
|
+
|
98
|
+
puts "skipped file #{c} - empty file".yellow
|
99
|
+
next
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
content = @catalog.check_content(c)
|
104
|
+
|
105
|
+
content[:col_classes] = "col-lg-12 box"
|
106
|
+
content[:summary] = Tilt.new(c).render
|
107
|
+
content[:link] = File.basename( content[:path],
|
108
|
+
File.extname(content[:path]) ) + HTMLEXT
|
109
|
+
|
110
|
+
contents = []
|
111
|
+
contents << content
|
112
|
+
|
113
|
+
rows = []
|
114
|
+
rows << contents
|
115
|
+
|
116
|
+
r = @col.render( self, :rows => rows )
|
117
|
+
|
118
|
+
html = @layout.render { r }
|
119
|
+
|
120
|
+
Meta::Filelib.create_file( html, c, @dest, overwrite )
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
data/lib/meta/version.rb
ADDED
data/lib/meta.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "colorize"
|
4
|
+
require "digest/md5"
|
5
|
+
require "haml"
|
6
|
+
require "highline/import"
|
7
|
+
require "redcarpet"
|
8
|
+
require "sequel"
|
9
|
+
require "sqlite3"
|
10
|
+
require "thor"
|
11
|
+
require "tilt"
|
12
|
+
|
13
|
+
require File.join( File.dirname(__FILE__), "meta", "catalog" )
|
14
|
+
require File.join( File.dirname(__FILE__), "meta", "cli" )
|
15
|
+
require File.join( File.dirname(__FILE__), "meta", "filelib" )
|
16
|
+
require File.join( File.dirname(__FILE__), "meta", "page" )
|
17
|
+
require File.join( File.dirname(__FILE__), "meta", "version" )
|
18
|
+
|
19
|
+
# macro-like used to keep haml compatibility
|
20
|
+
def haml(file)
|
21
|
+
return Tilt.new("#{file}.haml").render
|
22
|
+
end
|
23
|
+
|
24
|
+
module Meta
|
25
|
+
|
26
|
+
BASEDIR = ".".freeze
|
27
|
+
DATASTORE = File.join( Dir.pwd, "site.sqlite3" )
|
28
|
+
EXCLUDES = [ "layout.haml", "navbar.haml", "footer.haml" ]
|
29
|
+
HAML = ["*.haml"]
|
30
|
+
HAMLEXT = ".haml".freeze
|
31
|
+
HTML = ["*.html"]
|
32
|
+
HTMLEXT = ".html".freeze
|
33
|
+
INDEX = "index.html".freeze
|
34
|
+
MARKDOWN = ["*.md", "*.markdown", "*.mkd"]
|
35
|
+
MARKDOWNEXT = ".md".freeze
|
36
|
+
SEED = 1234562
|
37
|
+
SLASH = "/".freeze
|
38
|
+
|
39
|
+
end
|
40
|
+
|
data/meta.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'meta/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "meta"
|
8
|
+
spec.version = Meta::VERSION
|
9
|
+
spec.authors = ["stephenhu"]
|
10
|
+
spec.email = ["epynonymous@outlook.com"]
|
11
|
+
spec.description = %q{meta language compiler for static web pages }
|
12
|
+
spec.summary = %q{meta compiler (meta)}
|
13
|
+
spec.homepage = "http://github.io/stephenhu/meta"
|
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
|
+
spec.bindir = "bin"
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
25
|
+
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: meta
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- stephenhu
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-12-30 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
|
+
description: ! 'meta language compiler for static web pages '
|
47
|
+
email:
|
48
|
+
- epynonymous@outlook.com
|
49
|
+
executables:
|
50
|
+
- meta
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- Gemfile.lock
|
57
|
+
- LICENSE
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- bin/meta
|
61
|
+
- config/config.ru
|
62
|
+
- db/migrate/001_init_database.rb
|
63
|
+
- db/migrate/002_picture.rb
|
64
|
+
- db/migrate/003_remove_templates.rb
|
65
|
+
- db/migrate/004_remove_fk.rb
|
66
|
+
- db/site.sqlite3
|
67
|
+
- docs/backlog
|
68
|
+
- docs/design
|
69
|
+
- lib/meta.rb
|
70
|
+
- lib/meta/catalog.rb
|
71
|
+
- lib/meta/cli.rb
|
72
|
+
- lib/meta/filelib.rb
|
73
|
+
- lib/meta/page.rb
|
74
|
+
- lib/meta/version.rb
|
75
|
+
- meta.gemspec
|
76
|
+
homepage: http://github.io/stephenhu/meta
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.8.23
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: meta compiler (meta)
|
101
|
+
test_files: []
|