marti 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +34 -0
- data/app/assets/stylesheets/markdown_articles/markdown_articles.css +4 -0
- data/app/controllers/marti/application_controller.rb +4 -0
- data/app/controllers/marti/marticles_controller.rb +27 -0
- data/app/helpers/marti/application_helper.rb +4 -0
- data/app/helpers/marti/marti_helper.rb +4 -0
- data/app/models/marti/marticle.rb +15 -0
- data/config/routes.rb +4 -0
- data/lib/marti.rb +51 -0
- data/lib/marti/engine.rb +5 -0
- data/lib/marti/errors/errors.rb +7 -0
- data/lib/marti/renderers/html_with_pygments.rb +12 -0
- data/lib/marti/services/marticle_builder.rb +28 -0
- data/lib/marti/services/marticle_parser.rb +116 -0
- data/lib/marti/version.rb +3 -0
- data/lib/tasks/marti_tasks.rake +4 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +29 -0
- data/test/dummy/config/environments/production.rb +80 -0
- data/test/dummy/config/environments/test.rb +36 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +12 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/log/development.log +47 -0
- data/test/dummy/log/test.log +2090 -0
- data/test/dummy/public/404.html +58 -0
- data/test/dummy/public/422.html +58 -0
- data/test/dummy/public/500.html +57 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/fixtures/test.md +6 -0
- data/test/fixtures/test_with_cut.md +9 -0
- data/test/fixtures/test_with_updated_at.md +4 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/marti_test.rb +28 -0
- data/test/models/marticle_test.rb +16 -0
- data/test/services/marticle_builder_test.rb +36 -0
- data/test/services/marticle_parser_test.rb +47 -0
- data/test/test_helper.rb +19 -0
- metadata +200 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 78eed6fa6687cbddb1dd7aaceaad5be78431c381
|
4
|
+
data.tar.gz: c468141578ab9710f6146e59cdc220738d69cfc8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e9d9116d0912053d362e796ca82f095e570091354499a08ef4faa32aa401a46abc32c6572791a4cb5a62662ee732410d5837ecfb70835a8626c37e5e56f06151
|
7
|
+
data.tar.gz: aca1636ade52ffb96c711bfeb8a24a306cb0f0545e63e9766e05f36530f4141799394ad791d1e5935c187659aa7b2928174859f4048cd2c118424b5671166df1
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Marti'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
task default: :test
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Marti
|
2
|
+
class MarticlesController < ApplicationController
|
3
|
+
rescue_from Marti::Errors::ArticleNotFoundError, &Marti.article_not_found_proc
|
4
|
+
layout Marti.layout
|
5
|
+
def index
|
6
|
+
render :index, locals: { marticles: marticles }
|
7
|
+
end
|
8
|
+
|
9
|
+
def show
|
10
|
+
render :show, locals: { marticle: marticle, marticles: marticles }
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def marticle
|
16
|
+
@martcile ||= builder.build
|
17
|
+
end
|
18
|
+
|
19
|
+
def builder
|
20
|
+
@builder ||= Marti::MarticleBuilder.new(params[:path])
|
21
|
+
end
|
22
|
+
|
23
|
+
def marticles
|
24
|
+
@marticles ||= Marticle.articles
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Marti
|
2
|
+
class Marticle
|
3
|
+
attr_reader :content, :path, :last_updated_at, :extract
|
4
|
+
|
5
|
+
def self.articles
|
6
|
+
articles = []
|
7
|
+
Dir[File.join(Marti.article_directory, "*.md")].each do |file|
|
8
|
+
path = file.gsub(/^.*\//, "").gsub(/\.md/, "")
|
9
|
+
articles << Marti::MarticleBuilder.new(path).build
|
10
|
+
end
|
11
|
+
articles.sort_by(&:last_updated_at)
|
12
|
+
articles
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/config/routes.rb
ADDED
data/lib/marti.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'redcarpet'
|
2
|
+
|
3
|
+
module Marti
|
4
|
+
class << self
|
5
|
+
attr_reader :config
|
6
|
+
Config = Struct.new(:article_directory, :cache_store,
|
7
|
+
:expires_in, :layout, :article_not_found_proc)
|
8
|
+
def configure
|
9
|
+
@config ||= Config.new
|
10
|
+
yield(config)
|
11
|
+
end
|
12
|
+
|
13
|
+
def article_directory
|
14
|
+
configured_check!
|
15
|
+
config.article_directory || '.'
|
16
|
+
end
|
17
|
+
|
18
|
+
def article_not_found_proc
|
19
|
+
configured_check!
|
20
|
+
config.article_not_found_proc || proc { raise ActionController::RoutingError.new('Article not found') }
|
21
|
+
end
|
22
|
+
|
23
|
+
def layout
|
24
|
+
configured_check!
|
25
|
+
config.layout || "application"
|
26
|
+
end
|
27
|
+
|
28
|
+
def cache_store
|
29
|
+
configured_check!
|
30
|
+
config.cache_store || ActiveSupport::Cache::NullStore.new
|
31
|
+
end
|
32
|
+
|
33
|
+
def expires_in
|
34
|
+
configured_check!
|
35
|
+
config.expires_in || 1.day
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def configured_check!
|
41
|
+
return unless config.nil?
|
42
|
+
raise Marti::Errors::NotYetConfiguredError.new("Marti has not yet been configured")
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
require "marti/engine"
|
48
|
+
require "marti/services/marticle_builder"
|
49
|
+
require "marti/services/marticle_parser"
|
50
|
+
require "marti/errors/errors"
|
51
|
+
require "marti/renderers/html_with_pygments"
|
data/lib/marti/engine.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'redcarpet'
|
2
|
+
require 'pygments'
|
3
|
+
module Marti
|
4
|
+
module Renderers
|
5
|
+
class HTMLWithPygments < ::Redcarpet::Render::HTML
|
6
|
+
def block_code(code, language)
|
7
|
+
Pygments.highlight(code,
|
8
|
+
:lexer => language).gsub(/<pre>/, "<pre>\n")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Marti
|
2
|
+
class MarticleBuilder
|
3
|
+
attr_reader :path
|
4
|
+
|
5
|
+
def initialize(path)
|
6
|
+
@path = path
|
7
|
+
end
|
8
|
+
|
9
|
+
def build
|
10
|
+
Marti.cache_store.fetch("marticle/"+path,
|
11
|
+
expires_in: Marti.expires_in) do
|
12
|
+
file = file_location(path)
|
13
|
+
unless File.exists?(file)
|
14
|
+
raise ::Marti::Errors::ArticleNotFoundError.new("#{path} not found")
|
15
|
+
end
|
16
|
+
article = Marti::MarticleParser.new(file).parse
|
17
|
+
article.send(:instance_variable_set, "@path".to_sym, path)
|
18
|
+
article
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def file_location(path)
|
25
|
+
File.join(Marti.article_directory, "#{path}.md")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module Marti
|
2
|
+
class MarticleParser
|
3
|
+
attr_reader :file, :article
|
4
|
+
CUT = "--CUT--"
|
5
|
+
def initialize(file)
|
6
|
+
@file = file
|
7
|
+
end
|
8
|
+
|
9
|
+
def parse
|
10
|
+
# clear article
|
11
|
+
@article = Marticle.new
|
12
|
+
set_article_time_from_file!
|
13
|
+
|
14
|
+
content, extract = retrieve_content
|
15
|
+
content = markdown.render(content.join("\n"))
|
16
|
+
extract = markdown.render(extract.join("\n"))
|
17
|
+
|
18
|
+
set('content', content)
|
19
|
+
# Strip last \n from extract
|
20
|
+
set('extract', extract.strip)
|
21
|
+
article
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def retrieve_content
|
27
|
+
content = []
|
28
|
+
extract = []
|
29
|
+
each_line do |type|
|
30
|
+
type.meta do |line|
|
31
|
+
parse_meta_line(line)
|
32
|
+
end
|
33
|
+
|
34
|
+
type.content do |line|
|
35
|
+
line = clean_line(line)
|
36
|
+
extract = content.dup and next if line == CUT
|
37
|
+
content << line
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
extract = content[0..3] if extract.empty?
|
42
|
+
[content, extract]
|
43
|
+
end
|
44
|
+
|
45
|
+
def set(key, value)
|
46
|
+
article.send(:instance_variable_set, "@#{key}", value)
|
47
|
+
article.class.send(:attr_reader, key) unless article.respond_to?(key)
|
48
|
+
end
|
49
|
+
|
50
|
+
def clean_line(line)
|
51
|
+
line.gsub(/[\n\r]/, "")
|
52
|
+
end
|
53
|
+
|
54
|
+
def set_article_time_from_file!
|
55
|
+
set('last_updated_at', File.mtime(file).to_datetime)
|
56
|
+
end
|
57
|
+
|
58
|
+
def parse_meta_line(line)
|
59
|
+
key, *value = line.gsub(/^\$/, "").split(":").map(&:strip)
|
60
|
+
value = value.join(':')
|
61
|
+
value = parse_value(value)
|
62
|
+
# Account for manually setting time
|
63
|
+
value = Time.parse(value) if key == 'last_updated_at'
|
64
|
+
set(key, value)
|
65
|
+
end
|
66
|
+
|
67
|
+
def parse_value(value)
|
68
|
+
case value.strip
|
69
|
+
when /^[0-9]+(\.[0-9]+)?$/
|
70
|
+
value =~ /\./ ? value.to_f : value.to_i
|
71
|
+
when /^(?:t|f|y|n|yes|no|true|false)$/i
|
72
|
+
!!(value =~ /^(?:t|y|yes|true)$/)
|
73
|
+
else
|
74
|
+
value
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class LineResponse < Struct.new(:type, :line)
|
79
|
+
[:meta, :content].each do |t|
|
80
|
+
define_method(t) do |&b|
|
81
|
+
return unless type == t
|
82
|
+
b.yield(line)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def each_line(&block)
|
88
|
+
in_meta = true
|
89
|
+
File.open(file, 'r') do |file|
|
90
|
+
file.each_line do |line|
|
91
|
+
if line =~ /^\$/ && in_meta
|
92
|
+
block.call(LineResponse.new(:meta, line))
|
93
|
+
else
|
94
|
+
in_meta = false
|
95
|
+
block.call(LineResponse.new(:content, line))
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def markdown
|
102
|
+
@markdown ||= ::Redcarpet::Markdown.new(
|
103
|
+
Marti::Renderers::HTMLWithPygments.new(
|
104
|
+
prettify: true,
|
105
|
+
),
|
106
|
+
no_intra_emphasis: true,
|
107
|
+
fenced_code_blocks: true,
|
108
|
+
autolink: true,
|
109
|
+
disable_indented_code_blocks: true,
|
110
|
+
strikethrough: true,
|
111
|
+
footnotes: true,
|
112
|
+
highlight: true,
|
113
|
+
)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/test/dummy/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|