hastie 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +9 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/Gemfile +10 -0
- data/LICENSE +21 -0
- data/README.textile +136 -0
- data/Rakefile +1 -0
- data/bin/hastie +64 -0
- data/hastie.gemspec +31 -0
- data/lib/hastie/config_file.rb +42 -0
- data/lib/hastie/config_generator.rb +37 -0
- data/lib/hastie/constants.rb +25 -0
- data/lib/hastie/report_generator.rb +118 -0
- data/lib/hastie/report_publisher.rb +162 -0
- data/lib/hastie/report_updater.rb +40 -0
- data/lib/hastie/report_watcher.rb +65 -0
- data/lib/hastie/server_generator.rb +47 -0
- data/lib/hastie/server_reader.rb +81 -0
- data/lib/hastie/templates/hastie_config.tt +6 -0
- data/lib/hastie/templates/report.markdown.tt +19 -0
- data/lib/hastie/templates/report.textile.tt +19 -0
- data/lib/hastie/templates/report_index.html.tt +8 -0
- data/lib/hastie/templates/server/.gitignore +1 -0
- data/lib/hastie/templates/server/_config.yml +25 -0
- data/lib/hastie/templates/server/_includes/.gitignore +0 -0
- data/lib/hastie/templates/server/_layouts/.gitignore +0 -0
- data/lib/hastie/templates/server/_plugins/.gitignore +0 -0
- data/lib/hastie/templates/server/_posts/.gitignore +0 -0
- data/lib/hastie/templates/server/_reports.yml +0 -0
- data/lib/hastie/templates/server/_server_config.yml +15 -0
- data/lib/hastie/templates/server/css/.gitignore +0 -0
- data/lib/hastie/templates/server/data/.gitignore +0 -0
- data/lib/hastie/templates/server/imgs/.gitignore +0 -0
- data/lib/hastie/templates/server/index.html +0 -0
- data/lib/hastie/templates/server/js/.gitignore +0 -0
- data/lib/hastie/version.rb +3 -0
- data/lib/hastie.rb +15 -0
- data/spec/config_generator_spec.rb +124 -0
- data/spec/fakefs_helper.rb +67 -0
- data/spec/fixtures/config.ru +29 -0
- data/spec/fixtures/hastie_config +2 -0
- data/spec/fixtures/report/2110-12-16-report.textile +19 -0
- data/spec/fixtures/report/_config.yml +9 -0
- data/spec/fixtures/report/data/report/.gitignore +0 -0
- data/spec/fixtures/report/imgs/report/.gitignore +0 -0
- data/spec/fixtures/report/js/.gitignore +0 -0
- data/spec/fixtures/report/report.yml +23 -0
- data/spec/fixtures/server/_config.yml +10 -0
- data/spec/fixtures/server/_posts/2011-11-11-jfv_mak_snp_analysis.textile +0 -0
- data/spec/fixtures/server/_reports.yml +1 -0
- data/spec/fixtures/server/css/style.css +126 -0
- data/spec/fixtures/server/data/jfv_mak_snp_analysis/.gitignore +0 -0
- data/spec/fixtures/server/imgs/favicon.ico +0 -0
- data/spec/fixtures/server/imgs/subset_images/.gitignore +0 -0
- data/spec/fixtures/server/js/.gitignore +0 -0
- data/spec/report_generator_spec.rb +168 -0
- data/spec/report_publisher_spec.rb +148 -0
- data/spec/report_updater_spec.rb +54 -0
- data/spec/report_watcher_spec.rb +99 -0
- data/spec/server_generator_spec.rb +68 -0
- data/spec/server_reader_spec.rb +120 -0
- data/spec/spec_helper.rb +52 -0
- metadata +234 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'hastie/config_file'
|
3
|
+
require 'hastie/constants'
|
4
|
+
require 'hastie/server_reader'
|
5
|
+
|
6
|
+
module Hastie
|
7
|
+
class ReportUpdater < ServerReader
|
8
|
+
def self.banner
|
9
|
+
"hastie update <REPORT_DIR> <OPTIONS>"
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "Updates local files from remote server"
|
13
|
+
argument :name, :type => :string, :default => ".", :desc => "The name report directory"
|
14
|
+
|
15
|
+
def read_report_file
|
16
|
+
self.destination_root = name
|
17
|
+
report_config_file = File.join(self.destination_root, Hastie.report_config_name)
|
18
|
+
if !File.exists? report_config_file
|
19
|
+
say "Cannot locate #{Hastie.report_config_name}."
|
20
|
+
say "Report directory does not contain report"
|
21
|
+
say "#{File.expand_path(self.destination_root)}"
|
22
|
+
exit(1)
|
23
|
+
end
|
24
|
+
# we get the report filename from this config file
|
25
|
+
local_config = ConfigFile.load(report_config_file, :local)
|
26
|
+
self.options = local_config.merge(self.options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def fetch_static_files
|
30
|
+
options[:server]["static"] ||= []
|
31
|
+
options[:server]["static"].each do |static_file|
|
32
|
+
static_path = File.join(options[:server_root], static_file)
|
33
|
+
if File.exists? static_path
|
34
|
+
say_status "copy", "#{static_path} to #{File.basename(destination_root)}"
|
35
|
+
FileUtils.cp_r static_path, self.destination_root
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'hastie/constants'
|
3
|
+
require 'hastie/config_file'
|
4
|
+
require 'thor/group'
|
5
|
+
|
6
|
+
module Hastie
|
7
|
+
class ReportWatcher < Thor::Group
|
8
|
+
include Thor::Actions
|
9
|
+
|
10
|
+
desc "Watches Directory Using Jekyll"
|
11
|
+
argument :path, :type => :string, :default => ".", :desc => "The path to the report directory"
|
12
|
+
|
13
|
+
attr_accessor :report_dir
|
14
|
+
|
15
|
+
# this is done just as a double check that we are in a report directory
|
16
|
+
def check_report_file
|
17
|
+
self.report_dir = File.expand_path(path)
|
18
|
+
report_config_file = File.join(report_dir, Hastie.report_config_name)
|
19
|
+
if !File.exists? report_config_file
|
20
|
+
say_status "error","Cannot locate #{Hastie.report_config_name}.", :red
|
21
|
+
say_status "error","Directory #{self.report_dir} is not a report.", :red
|
22
|
+
exit(1)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_root
|
27
|
+
self.destination_root = self.report_dir
|
28
|
+
end
|
29
|
+
|
30
|
+
def read_config_file
|
31
|
+
config_file = File.join(self.report_dir, Hastie.watch_config_file)
|
32
|
+
if !File.exists? config_file
|
33
|
+
say_status "error", "Cannot find #{config_file}", :red
|
34
|
+
say_status "error","Directory #{self.report_dir} is not a report.", :red
|
35
|
+
exit(1)
|
36
|
+
end
|
37
|
+
local_config = ConfigFile.load(config_file, :local)
|
38
|
+
self.options = local_config.merge(self.options)
|
39
|
+
end
|
40
|
+
|
41
|
+
def start_jekyll
|
42
|
+
port = self.options["local"]["server_port"] || "4000"
|
43
|
+
url = "http://0.0.0.0:#{port}"
|
44
|
+
say_status "open", url
|
45
|
+
|
46
|
+
in_root do
|
47
|
+
if !File.exist?("config.ru")
|
48
|
+
# use built in method
|
49
|
+
exec("jekyll --auto --server")
|
50
|
+
else
|
51
|
+
# use thin method
|
52
|
+
jekyllPid = Process.spawn("jekyll --auto")
|
53
|
+
thinPid = Process.spawn("thin -p #{port} -R config.ru start")
|
54
|
+
trap("INT") {
|
55
|
+
[jekyllPid, thinPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
|
56
|
+
exit 0
|
57
|
+
}
|
58
|
+
|
59
|
+
[jekyllPid, thinPid].each { |pid| Process.wait(pid) }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'hastie/constants'
|
3
|
+
require 'hastie/config_file'
|
4
|
+
require 'thor/group'
|
5
|
+
require 'grit'
|
6
|
+
|
7
|
+
module Hastie
|
8
|
+
class ServerGenerator < Thor::Group
|
9
|
+
include Thor::Actions
|
10
|
+
|
11
|
+
def self.banner
|
12
|
+
"hastie create_server [NAME]"
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Creates framework for new server"
|
16
|
+
argument :name, :type => :string, :desc => "The dir of the new server location. no spaces"
|
17
|
+
|
18
|
+
def self.source_root
|
19
|
+
File.dirname(__FILE__)
|
20
|
+
end
|
21
|
+
|
22
|
+
def set_destination
|
23
|
+
# hack to unfreeze the options hash
|
24
|
+
self.options = Thor::CoreExt::HashWithIndifferentAccess.new(options)
|
25
|
+
|
26
|
+
# want to allow for relative paths
|
27
|
+
options[:server_id] = File.basename(name)
|
28
|
+
self.destination_root = File.join(File.dirname(name), options[:server_id])
|
29
|
+
say_status "note", "root: #{self.destination_root}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_server
|
33
|
+
directory("templates/server", self.destination_root)
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_git_repo
|
37
|
+
in_root do
|
38
|
+
say_status "note", "creating git repository in #{self.destination_root}"
|
39
|
+
repo = Grit::Repo.init(".")
|
40
|
+
all_files = Dir.glob("./**")
|
41
|
+
#all_files.each {|f| say_status "note", "adding #{f}"}
|
42
|
+
repo.add(all_files)
|
43
|
+
repo.commit_all("initial commit of server scaffold. created from hastie")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'thor/group'
|
4
|
+
require 'hastie/config_file'
|
5
|
+
require 'hastie/constants'
|
6
|
+
|
7
|
+
module Hastie
|
8
|
+
class ServerReader < Thor::Group
|
9
|
+
include Thor::Actions
|
10
|
+
class_option :server_root, :aliases => "-s", :desc => "Root directory of the server to read / publish to"
|
11
|
+
class_option :config_file, :aliases => "-c", :desc => "Path to .hastie config file", :default => Hastie.config_file
|
12
|
+
|
13
|
+
no_tasks do
|
14
|
+
def config_file
|
15
|
+
@config_file ||= if options[:config_file]
|
16
|
+
File.expand_path(options[:config_file])
|
17
|
+
else
|
18
|
+
Hastie.config_file
|
19
|
+
end
|
20
|
+
@config_file
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.source_root
|
25
|
+
File.dirname(__FILE__)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Tries to access users config file
|
29
|
+
# loads contents into the options hash
|
30
|
+
def read_config_file
|
31
|
+
say_status "note", "config file: #{self.config_file}"
|
32
|
+
if !File.exists? self.config_file
|
33
|
+
say "No config file found. Please create #{self.config_file}"
|
34
|
+
exit(1)
|
35
|
+
end
|
36
|
+
config = ConfigFile.load(self.config_file)
|
37
|
+
self.options = config.merge(self.options)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Tries to access the servers
|
41
|
+
def get_server_config
|
42
|
+
say_status "note", "server root: #{options[:server_root]}"
|
43
|
+
# First check if the server directory exists
|
44
|
+
if !File.directory? options[:server_root]
|
45
|
+
say_status "error", "Cannot find server directory:", :red
|
46
|
+
say options[:server_root]
|
47
|
+
say "Please modify \'server_root\' to point to server root directory"
|
48
|
+
exit(1)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Check for config file inside server_root
|
52
|
+
server_config_file = File.join(options[:server_root], SERVER_CONFIG_FILE)
|
53
|
+
if !File.exists? server_config_file
|
54
|
+
say_status "error", "Cannot find #{SERVER_CONFIG_FILE} file in server directory:", :red
|
55
|
+
say server_config_file
|
56
|
+
say ""
|
57
|
+
say "Are you sure #{options[:server_root]} is a valid server directory?"
|
58
|
+
exit(1)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Check for reports file inside server_root
|
62
|
+
server_report_file = File.join(options[:server_root], SERVER_REPORTS_FILE)
|
63
|
+
if !File.exists? server_report_file
|
64
|
+
say_status "error", "Cannot find #{SERVER_REPORTS_FILE} file in server directory:", :red
|
65
|
+
say server_report_file
|
66
|
+
say ""
|
67
|
+
say "Are you sure #{options[:server_root]} is a valid server directory?"
|
68
|
+
exit(1)
|
69
|
+
end
|
70
|
+
|
71
|
+
# merge the server config and report file
|
72
|
+
# put them in their own 'namespace' to avoid
|
73
|
+
# collisions with existing configs
|
74
|
+
server_config = ConfigFile.load(server_config_file, :server)
|
75
|
+
self.options = server_config.merge(self.options)
|
76
|
+
|
77
|
+
server_reports = ConfigFile.load(server_report_file, :published_reports)
|
78
|
+
self.options = server_reports.merge(self.options)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
---
|
2
|
+
layout: report
|
3
|
+
title: <%= title %>
|
4
|
+
analyst: <%= options[:analyst] %>
|
5
|
+
researcher: <%= options[:researcher] %>
|
6
|
+
pi: <%= options[:pi] %>
|
7
|
+
data:
|
8
|
+
- <%= options[:data_dir] %>/
|
9
|
+
categories:
|
10
|
+
- open
|
11
|
+
---
|
12
|
+
|
13
|
+
## Objective
|
14
|
+
|
15
|
+
## Data
|
16
|
+
|
17
|
+
## Methods
|
18
|
+
|
19
|
+
## Results
|
@@ -0,0 +1,19 @@
|
|
1
|
+
---
|
2
|
+
layout: report
|
3
|
+
title: <%= title %>
|
4
|
+
analyst: <%= options[:analyst] %>
|
5
|
+
researcher: <%= options[:researcher] %>
|
6
|
+
pi: <%= options[:pi] %>
|
7
|
+
data:
|
8
|
+
- <%= options[:data_dir] %>/
|
9
|
+
categories:
|
10
|
+
- open
|
11
|
+
---
|
12
|
+
|
13
|
+
h2. Objective
|
14
|
+
|
15
|
+
h2. Data
|
16
|
+
|
17
|
+
h2. Methods
|
18
|
+
|
19
|
+
h2. Results
|
@@ -0,0 +1 @@
|
|
1
|
+
_site/*
|
@@ -0,0 +1,25 @@
|
|
1
|
+
source: .
|
2
|
+
destination: ./_site
|
3
|
+
includes: ./_includes
|
4
|
+
|
5
|
+
pygments: true
|
6
|
+
markdown: rdiscount
|
7
|
+
permalink: /:year-:month-:day_:title.html
|
8
|
+
|
9
|
+
baseurl: /
|
10
|
+
|
11
|
+
rdiscount:
|
12
|
+
extensions: []
|
13
|
+
|
14
|
+
exclude: []
|
15
|
+
|
16
|
+
static:
|
17
|
+
- css
|
18
|
+
- js
|
19
|
+
- _layouts
|
20
|
+
- _includes
|
21
|
+
- _plugins
|
22
|
+
- _config.yml
|
23
|
+
|
24
|
+
reports_dir: _posts
|
25
|
+
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/hastie.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
if RUBY_VERSION =~ /1.9/
|
3
|
+
Encoding.default_external = Encoding::UTF_8
|
4
|
+
Encoding.default_internal = Encoding::UTF_8
|
5
|
+
end
|
6
|
+
|
7
|
+
# Most of Hastie functionality is derived from Thor groups.
|
8
|
+
# Each Thor group is maintained in a separate file.
|
9
|
+
|
10
|
+
require 'hastie/report_generator'
|
11
|
+
require 'hastie/report_publisher'
|
12
|
+
require 'hastie/report_updater'
|
13
|
+
require 'hastie/server_generator'
|
14
|
+
require 'hastie/config_generator'
|
15
|
+
require 'hastie/report_watcher'
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/fakefs_helper')
|
3
|
+
require 'hastie/config_generator'
|
4
|
+
|
5
|
+
describe Hastie::ConfigGenerator do
|
6
|
+
def read_file file
|
7
|
+
if File.exists? file
|
8
|
+
File.open(file, 'r').read
|
9
|
+
else
|
10
|
+
""
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
before :each do
|
15
|
+
@server_dir = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "server"))
|
16
|
+
@output_dir = File.expand_path(File.join(File.dirname(__FILE__), "sandbox"))
|
17
|
+
@name = "hastie_config_gen"
|
18
|
+
@config_file = File.join(@output_dir, @name)
|
19
|
+
@input = [@server_dir, "--path", @output_dir, "--name", @name]
|
20
|
+
FileUtils.mkdir_p @output_dir
|
21
|
+
end
|
22
|
+
|
23
|
+
after :each do
|
24
|
+
FileUtils.rm_r @output_dir if File.exists?(@output_dir)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should have server_root" do
|
28
|
+
content = capture(:stdout) do
|
29
|
+
lambda { Hastie::ConfigGenerator.start @input }.should_not raise_error SystemExit
|
30
|
+
end
|
31
|
+
|
32
|
+
content = read_file @config_file
|
33
|
+
content.should match /server_root: #{@server_dir}/
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "config flags" do
|
38
|
+
it "--analyst" do
|
39
|
+
@input << "--analyst" << "dog"
|
40
|
+
content = capture(:stdout) do
|
41
|
+
lambda { Hastie::ConfigGenerator.start @input }.should_not raise_error SystemExit
|
42
|
+
end
|
43
|
+
|
44
|
+
content = read_file @config_file
|
45
|
+
content.should match /analyst: dog/
|
46
|
+
end
|
47
|
+
|
48
|
+
it "--type" do
|
49
|
+
@input << "--type" << "textile"
|
50
|
+
content = capture(:stdout) do
|
51
|
+
lambda { Hastie::ConfigGenerator.start @input }.should_not raise_error SystemExit
|
52
|
+
end
|
53
|
+
|
54
|
+
content = read_file @config_file
|
55
|
+
content.should match /type: textile/
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe Hastie::ConfigGenerator, fakefs: true do
|
61
|
+
before :each do
|
62
|
+
@server_root = "/tmp/server/root"
|
63
|
+
@input = [@server_root]
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "invalid server_root" do
|
67
|
+
it "should error if server_root does not exist" do
|
68
|
+
content = capture(:stdout) do
|
69
|
+
lambda { Hastie::ConfigGenerator.start @input }.should raise_error SystemExit
|
70
|
+
end
|
71
|
+
content.should match /not a directory/
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "valid server_root" do
|
76
|
+
before :each do
|
77
|
+
FileUtils.mkdir_p @server_root
|
78
|
+
#
|
79
|
+
# CLONE: copies files from real fs to fakefs.
|
80
|
+
# TODO: use clone in other specs to copy the templates directory
|
81
|
+
#
|
82
|
+
FakeFS::FileSystem.clone(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "hastie", "templates")))
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should not error if server_root does not exist" do
|
86
|
+
content = capture(:stdout) do
|
87
|
+
lambda { Hastie::ConfigGenerator.start @input }.should_not raise_error SystemExit
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should create hastie config file" do
|
92
|
+
content = capture(:stdout) do
|
93
|
+
lambda { Hastie::ConfigGenerator.start @input }.should_not raise_error SystemExit
|
94
|
+
end
|
95
|
+
File.exists?(File.expand_path("~/.hastie")).should == true
|
96
|
+
end
|
97
|
+
|
98
|
+
it "--path" do
|
99
|
+
path = "/alt/file/location"
|
100
|
+
@input << "--path" << path
|
101
|
+
# Hastie::ConfigGenerator.start @input
|
102
|
+
content = capture(:stdout) do
|
103
|
+
lambda { Hastie::ConfigGenerator.start @input }.should_not raise_error SystemExit
|
104
|
+
end
|
105
|
+
|
106
|
+
File.exists?("#{path}/.hastie").should == true
|
107
|
+
end
|
108
|
+
|
109
|
+
it "--name" do
|
110
|
+
path = "/alt/file/location"
|
111
|
+
name = "hastier"
|
112
|
+
@input << "--path" << path << "--name" << name
|
113
|
+
# Hastie::ConfigGenerator.start @input
|
114
|
+
content = capture(:stdout) do
|
115
|
+
lambda { Hastie::ConfigGenerator.start @input }.should_not raise_error SystemExit
|
116
|
+
end
|
117
|
+
|
118
|
+
File.exists?("#{path}/#{name}").should == true
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
end
|
124
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
class FakeFsHelper
|
2
|
+
CONFIG_FILE = "/tmp/.hastie"
|
3
|
+
SERVER_DIR = "/sites/test_server"
|
4
|
+
REPORTS_FILE = "_reports.yml"
|
5
|
+
SERVER_CONFIG_FILE = "_config.yml"
|
6
|
+
|
7
|
+
def self.read_file file
|
8
|
+
if File.exists? file
|
9
|
+
File.open(file, 'r').read
|
10
|
+
else
|
11
|
+
""
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.stub_config_file config_file = CONFIG_FILE, server_dir = SERVER_DIR
|
16
|
+
FileUtils.mkdir(File.dirname(config_file))
|
17
|
+
File.open(config_file, 'w') do |file|
|
18
|
+
file.puts "server_root: #{server_dir}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.stub_server_dir dir = SERVER_DIR
|
23
|
+
FileUtils.mkdir_p dir
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.stub_server_config dir = SERVER_DIR
|
27
|
+
stub_server_dir dir
|
28
|
+
File.open(File.join(dir, SERVER_CONFIG_FILE), 'a') do |file|
|
29
|
+
file.puts ""
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.add_reports_dir dir = SERVER_DIR
|
34
|
+
stub_server_config dir
|
35
|
+
File.open(File.join(dir, SERVER_CONFIG_FILE), 'a') do |file|
|
36
|
+
file.puts "reports_dir: _posts"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.add_static_files dir = SERVER_DIR
|
41
|
+
stub_server_config dir
|
42
|
+
static_dirs = ["css", "js", "_layouts", "_includes", "_plugins"]
|
43
|
+
static_files = ["_config.yml"]
|
44
|
+
File.open(File.join(dir, SERVER_CONFIG_FILE), 'a') do |file|
|
45
|
+
file.puts "static:"
|
46
|
+
static_dirs.each {|sdir| file.puts "- #{sdir}"}
|
47
|
+
static_files.each {|f| file.puts "- #{f}"}
|
48
|
+
end
|
49
|
+
|
50
|
+
static_dirs.each {|sdir| FileUtils.mkdir File.join(dir, sdir)}
|
51
|
+
static_files.each {|sfile| FileUtils.touch File.join(dir, sfile)}
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.stub_reports_file dir = SERVER_DIR
|
55
|
+
stub_server_dir dir
|
56
|
+
File.open(File.join(dir, REPORTS_FILE), 'a') do |file|
|
57
|
+
file.puts ""
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.add_published_report report_id, dir = SERVER_DIR
|
62
|
+
stub_reports_file dir
|
63
|
+
File.open(File.join(dir, REPORTS_FILE), 'a') do |file|
|
64
|
+
file.puts "- #{report_id}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'sinatra/base'
|
3
|
+
|
4
|
+
# The project root directory
|
5
|
+
$root = ::File.dirname(__FILE__)
|
6
|
+
|
7
|
+
BUILD_DIR = '_site'
|
8
|
+
|
9
|
+
class SinatraStaticServer < Sinatra::Base
|
10
|
+
|
11
|
+
|
12
|
+
get(/.+/) do
|
13
|
+
send_sinatra_file(request.path) {404}
|
14
|
+
end
|
15
|
+
|
16
|
+
not_found do
|
17
|
+
send_sinatra_file('404.html') {"Sorry, I cannot find #{request.path}"}
|
18
|
+
end
|
19
|
+
|
20
|
+
def send_sinatra_file(path, &missing_file_block)
|
21
|
+
file_path = File.join(File.dirname(__FILE__), BUILD_DIR, path)
|
22
|
+
file_path = File.join(file_path, 'index.html') unless file_path =~ /\.[a-z]+$/i
|
23
|
+
File.exist?(file_path) ? send_file(file_path) : missing_file_block.call
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
run SinatraStaticServer
|
29
|
+
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
---
|
2
|
+
published_reports:
|
3
|
+
- jfv_mak_snp_analysis
|
4
|
+
server:
|
5
|
+
static:
|
6
|
+
- css
|
7
|
+
- js
|
8
|
+
- _layouts
|
9
|
+
- _includes
|
10
|
+
- _plugins
|
11
|
+
- _config.yml
|
12
|
+
reports_dir: _posts
|
13
|
+
server_root: spec/fixtures/server/
|
14
|
+
analyst: jfv
|
15
|
+
type: textile
|
16
|
+
config_file: /Users/jfv/.hastie
|
17
|
+
name: report
|
18
|
+
title: Spec/fixtures/report
|
19
|
+
report_id: report
|
20
|
+
researcher: unknown
|
21
|
+
pi: unknown
|
22
|
+
data_dir: data/report
|
23
|
+
report_file: 2110-12-16-report.textile
|