metc 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in metc.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
+
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ metc (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
+ metc!
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
+
@@ -0,0 +1,17 @@
1
+ # meta compiler (metc)
2
+
3
+ ## introduction
4
+ metc is used to translate templates such as haml or markdown into static web pages. these pages can then be served from github pages or other static site services like bluehost. metc can also be used to test/preview static pages in your development environment without having to deploy into production.
5
+
6
+ ## requirements
7
+ * ruby 1.9.2+
8
+ * bundler
9
+ * haml
10
+ * redcarpet
11
+ * thor
12
+ * tilt
13
+
14
+ ## installation
15
+
16
+ ## faq
17
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require "metc"
3
+ Metc::CLI.start
4
+
@@ -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,15 @@
1
+ open:
2
+ + detect and compile changes only
3
+ + support .markdown, .mkd file extensions
4
+ + support uppercase file extensions
5
+ + create index of articles
6
+ + crop articles
7
+ + list articles based on date
8
+
9
+ iced:
10
+ + tie static files with source repository
11
+ + clone template files
12
+ + add config.ru file for testing, this should be added during compilation
13
+
14
+ closed:
15
+
@@ -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
+
@@ -0,0 +1,39 @@
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__), "metc", "catalog" )
14
+ require File.join( File.dirname(__FILE__), "metc", "cli" )
15
+ require File.join( File.dirname(__FILE__), "metc", "filelib" )
16
+ require File.join( File.dirname(__FILE__), "metc", "page" )
17
+ require File.join( File.dirname(__FILE__), "metc", "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 Metc
25
+
26
+ BASEDIR = ".".freeze
27
+ COLS = [ 1, 2, 2, 3, 4 ]
28
+ DATASTORE = File.join( Dir.pwd, "site.sqlite3" )
29
+ EXCLUDES = [ "layout.haml", "navbar.haml", "footer.haml" ]
30
+ HAML = ["*.haml"]
31
+ HAMLEXT = ".haml".freeze
32
+ HTML = ["*.html"]
33
+ HTMLEXT = ".html".freeze
34
+ MARKDOWN = ["*.md", "*.markdown", "*.mkd"]
35
+ MARKDOWNEXT = ".md".freeze
36
+ SEED = 1234
37
+
38
+ end
39
+
@@ -0,0 +1,156 @@
1
+ module Metc
2
+
3
+ class Catalog
4
+
5
+ attr_accessor :db
6
+
7
+ def initialize
8
+
9
+ self.db = Sequel.sqlite(Metc::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 template_exists?(file)
26
+
27
+ rs = self.db[:templates].where(:path => file).all
28
+
29
+ if rs.empty?
30
+ return false
31
+ else
32
+ return true
33
+ end
34
+
35
+ end
36
+
37
+ def template_revised?( path, hash )
38
+
39
+ rs = self.db[:templates].where( :hash => hash, :path => path )
40
+
41
+ if rs.nil?
42
+ return true
43
+ else
44
+ return false
45
+ end
46
+
47
+ end
48
+
49
+ def get_recent(count)
50
+
51
+ if count < 0
52
+ rs = self.db[:contents].order(:created_at).all
53
+ else
54
+ rs = self.db[:contents].order(:created_at).limit(count).all
55
+ end
56
+
57
+ rs.each do |r|
58
+ content = Tilt.new(r[:path]).render
59
+
60
+ content = "abc" if content.empty?
61
+
62
+ r[:summary] = content
63
+ r[:link] = File.basename( r[:path], File.extname(r[:path]) ) +
64
+ HTMLEXT
65
+ r[:picture] = false
66
+ end
67
+
68
+ return rs
69
+
70
+ end
71
+
72
+ def check_content(content)
73
+
74
+ title = ask "Title? "
75
+ hash = Digest::MD5.hexdigest(content)
76
+
77
+ if content_exists?(content)
78
+ revise_content( content, title, hash )
79
+ else
80
+ add_content( content, title, hash )
81
+ end
82
+
83
+
84
+ end
85
+
86
+ def add_content( file, title, hash )
87
+
88
+ self.db[:contents].insert(
89
+ :title => title,
90
+ :hash => hash,
91
+ :path => file,
92
+ :created_at => File.ctime(file) )
93
+
94
+ end
95
+
96
+ def revise_content( file, title, hash )
97
+
98
+ self.db[:contents].where(:path => file).update(
99
+ :hash => hash,
100
+ :title => title,
101
+ :updated_at => Time.now )
102
+
103
+ end
104
+
105
+ def check_templates(templates)
106
+
107
+ templates.each do |t|
108
+
109
+ hash = Digest::MD5.hexdigest(t)
110
+
111
+ if template_exists?(t)
112
+
113
+ revise_template( t, hash )
114
+
115
+ else
116
+
117
+ add_template( t, hash )
118
+
119
+ end
120
+
121
+ end
122
+
123
+ end
124
+
125
+ def add_template( file, hash )
126
+
127
+ self.db[:templates].insert(
128
+ :path => file,
129
+ :hash => hash )
130
+
131
+ end
132
+
133
+ def revise_template( file, hash )
134
+
135
+ rs = self.db[:templates].where( :hash => hash, :path => file ).first
136
+
137
+ if rs.empty?
138
+
139
+ self.db[:templates].insert(
140
+ :path => file,
141
+ :hash => hash )
142
+
143
+ end
144
+
145
+ end
146
+
147
+ def content_count()
148
+
149
+ return self.db[:contents].count
150
+
151
+ end
152
+
153
+ end
154
+
155
+ end
156
+
@@ -0,0 +1,36 @@
1
+ module Metc
2
+
3
+ class CLI < Thor
4
+ include Thor::Actions
5
+
6
+ desc( "compile", "compile meta files" )
7
+ method_option :output, :type => :string, :required => false,
8
+ :desc => "location of source meta files"
9
+ method_option :exclude, :type => :string, :required => false,
10
+ :desc => "comma separated list"
11
+ def compile
12
+
13
+ p = Metc::Page.new
14
+
15
+ contents = Metc::Filelib.get_contents
16
+
17
+ contents.each do |c|
18
+ p.generate(c)
19
+ end
20
+
21
+ end
22
+
23
+ desc( "test", "testing" )
24
+ def test
25
+
26
+ p = Metc::Page.new
27
+ p.generate_main
28
+
29
+ end
30
+
31
+ default_task :compile
32
+
33
+ end
34
+
35
+ end
36
+
@@ -0,0 +1,57 @@
1
+ module Metc
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 )
21
+
22
+ filename = File.basename( filename, File.extname(filename) ) + HTMLEXT
23
+
24
+ reply = true
25
+
26
+ if File.exists?(filename)
27
+ reply = ask("file #{filename} exists, overwrite?")
28
+ end
29
+
30
+ if reply
31
+
32
+ f = File.open( filename, "w" )
33
+ f.write(text)
34
+ f.close
35
+
36
+ puts "file #{filename} created".green
37
+
38
+ end
39
+
40
+ end
41
+
42
+ def self.get_templates()
43
+
44
+ return Dir.glob( Metc::HAML, File::FNM_CASEFOLD )
45
+
46
+ end
47
+
48
+ def self.get_contents()
49
+
50
+ return Dir.glob( Metc::MARKDOWN, File::FNM_CASEFOLD )
51
+
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+
@@ -0,0 +1,88 @@
1
+ module Metc
2
+
3
+ class Page
4
+
5
+ attr_reader :layout, :navbar, :catalog
6
+
7
+ def initialize()
8
+
9
+ @catalog = Metc::Catalog.new
10
+
11
+ @layout = Tilt.new("layout.haml")
12
+ @navbar = Tilt.new("navbar.haml")
13
+ @col3 = Tilt.new("col3.haml")
14
+ @col4 = Tilt.new("col4.haml")
15
+ @col6 = Tilt.new("col6.haml")
16
+ @col8a = Tilt.new("col8a.haml")
17
+ @col8b = Tilt.new("col8b.haml")
18
+ @col12 = Tilt.new("col12.haml")
19
+
20
+ end
21
+
22
+ def generate_row(contents)
23
+
24
+ length = contents.length
25
+
26
+ if length == 1
27
+ return @col12.render( self, :contents => contents )
28
+ elsif length == 2
29
+ return @col8a.render( self, :contents => contents )
30
+ elsif length == 3
31
+ return @col4.render( self, :contents => contents )
32
+ elsif length == 4
33
+ return @col3.render( self, :contents => contents )
34
+ end
35
+
36
+ end
37
+
38
+ def generate_main()
39
+
40
+ c = @catalog.get_recent(-1)
41
+
42
+ length = c.length
43
+ remain = length
44
+ index = 0
45
+
46
+ doc = ""
47
+
48
+ rng = Random.new(SEED)
49
+
50
+ while remain != 0 do
51
+
52
+ if remain > 4
53
+ n = rng.rand(1..4)
54
+ else
55
+ n = remain
56
+ end
57
+
58
+ r = generate_row(c[index..index+n-1])
59
+
60
+ remain = remain - n
61
+ index = index + n
62
+
63
+ doc = doc + r
64
+
65
+ end
66
+
67
+ html = @layout.render { doc }
68
+
69
+ Metc::Filelib.create_file( html, "index.html" )
70
+
71
+ end
72
+
73
+ def generate(content)
74
+
75
+ return if File.zero?(content)
76
+
77
+ html = @layout.render { Tilt.new(content).render }
78
+
79
+ Metc::Filelib.create_file( html, content )
80
+
81
+ @catalog.check_content(content)
82
+
83
+ end
84
+
85
+ end
86
+
87
+ end
88
+
@@ -0,0 +1,4 @@
1
+ module Metc
2
+ VERSION = "0.0.1"
3
+ end
4
+
@@ -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 'metc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "metc"
8
+ spec.version = Metc::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 compiiler (metc)}
13
+ spec.homepage = "http://github.io/stephenhu/metc"
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
+
@@ -0,0 +1,26 @@
1
+ CREATE TABLE IF NOT EXISTS templates (
2
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
3
+ hash TEXT NOT NULL UNIQUE,
4
+ creation TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
5
+ modification TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
6
+ path TEXT NOT NULL
7
+ );
8
+
9
+ CREATE TABLE IF NOT EXISTS content (
10
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
11
+ hash TEXT NOT NULL UNIQUE,
12
+ title TEXT NOT NULL,
13
+ path TEXT NOT NULL,
14
+ tid INTEGER,
15
+ creation TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
16
+ modification TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
17
+ FOREIGN KEY(tid) REFERENCES templates(id)
18
+ );
19
+
20
+ CREATE TABLE IF NOT EXISTS revisions (
21
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
22
+ revision TEXT NOT NULL,
23
+ previous TEXT NOT NULL,
24
+ creation TIMESTAMP DEFAULT CURRENT_TIMESTAMP
25
+ );
26
+
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: metc
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-23 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
+ - metc
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - Gemfile.lock
57
+ - LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - bin/metc
61
+ - db/migrate/001_init_database.rb
62
+ - docs/backlog
63
+ - docs/design
64
+ - lib/metc.rb
65
+ - lib/metc/catalog.rb
66
+ - lib/metc/cli.rb
67
+ - lib/metc/filelib.rb
68
+ - lib/metc/page.rb
69
+ - lib/metc/version.rb
70
+ - metc.gemspec
71
+ - schema/schema.sql
72
+ homepage: http://github.io/stephenhu/metc
73
+ licenses:
74
+ - MIT
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 1.8.23
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: meta compiiler (metc)
97
+ test_files: []