storys 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/app/css/app.css +14 -22
- data/app/css/lib/bootstrap.css +6057 -0
- data/app/css/views.index.css +3 -3
- data/app/css/views.show.css +1 -1
- data/app/fonts/lib/glyphicons-halflings-regular.eot +0 -0
- data/app/fonts/lib/glyphicons-halflings-regular.svg +229 -0
- data/app/fonts/lib/glyphicons-halflings-regular.ttf +0 -0
- data/app/fonts/lib/glyphicons-halflings-regular.woff +0 -0
- data/app/index.html +21 -14
- data/app/js/app.js +0 -5
- data/app/js/controllers.index.js +24 -7
- data/app/js/jquery.twoup.js +45 -20
- data/app/js/lib/bootstrap.js +1992 -0
- data/bin/storys +3 -13
- data/lib/storys/package.rb +69 -0
- data/lib/storys/story.rb +33 -10
- data/lib/storys/update.rb +16 -7
- data/lib/storys/version.rb +1 -1
- data/lib/storys.rb +2 -4
- data/storys.gemspec +0 -1
- metadata +9 -20
- data/lib/storys/storys.rb +0 -18
- data/lib/storys/storys_package.rb +0 -57
- data/lib/storys/template_helper.rb +0 -5
- data/lib/storys/templates/show.html.haml +0 -17
data/bin/storys
CHANGED
@@ -1,18 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "storys"
|
4
|
-
require "highline/import"
|
5
4
|
|
6
|
-
|
7
|
-
root_path = Pathname.new(ARGV[1] || ".").realpath
|
5
|
+
root_path = Pathname.new(ARGV.first || ".").realpath
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
storys = Storys::Storys.new(root_path)
|
12
|
-
storys.install
|
13
|
-
when "update"
|
14
|
-
storys = Storys::Storys.new(root_path)
|
15
|
-
storys.update
|
16
|
-
else
|
17
|
-
puts "Unknown command #{command.inspect}"
|
18
|
-
end
|
7
|
+
storys = Storys::Package.new(root_path)
|
8
|
+
storys.update
|
@@ -0,0 +1,69 @@
|
|
1
|
+
class Storys::Package
|
2
|
+
attr_reader :root_path
|
3
|
+
attr_reader :package_path
|
4
|
+
|
5
|
+
def initialize(root_path)
|
6
|
+
raise "root_path must be an instance of Pathname" unless root_path.is_a?(Pathname)
|
7
|
+
|
8
|
+
@root_path = root_path
|
9
|
+
@package_path = root_path + ".storys/"
|
10
|
+
end
|
11
|
+
|
12
|
+
def pathname_to_url(path, relative_from)
|
13
|
+
URI.escape(path.relative_path_from(relative_from).to_s)
|
14
|
+
end
|
15
|
+
|
16
|
+
def url_to_pathname(url)
|
17
|
+
path = Addressable::URI.unencode_component(url.normalized_path)
|
18
|
+
path.gsub!(/^\//, "") #Make relative, if we allow mounting at a different root URL this will need to remove the root instead of just '/'
|
19
|
+
root_url_path + path
|
20
|
+
end
|
21
|
+
|
22
|
+
def update
|
23
|
+
package_path.mkdir unless File.exists?(package_path)
|
24
|
+
update_app
|
25
|
+
Storys::Update.new(self)
|
26
|
+
end
|
27
|
+
|
28
|
+
def update_app
|
29
|
+
dev = ENV["STORYS_ENV"] == "development"
|
30
|
+
|
31
|
+
app_children_paths.each do |file|
|
32
|
+
storys_file = package_path + file.basename
|
33
|
+
FileUtils.rm_rf(storys_file, :verbose => dev)
|
34
|
+
end
|
35
|
+
|
36
|
+
if dev
|
37
|
+
app_children_paths.each do |file|
|
38
|
+
storys_file = package_path + file.basename
|
39
|
+
FileUtils.ln_sf(file, storys_file, :verbose => dev)
|
40
|
+
end
|
41
|
+
else
|
42
|
+
FileUtils.cp_r(Storys::Package.gem_path + "app/.", package_path, :verbose => dev)
|
43
|
+
end
|
44
|
+
|
45
|
+
FileUtils.chmod_R(0755, package_path, :verbose => dev)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.gem_path
|
49
|
+
Pathname.new(__FILE__).dirname.parent.parent
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.load_json(path)
|
53
|
+
if File.exists?(path)
|
54
|
+
JSON.parse(File.read(path))
|
55
|
+
else
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.save_json(path, data)
|
61
|
+
File.open(path, "w") { |f| f << data.to_json }
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
def app_children_paths
|
66
|
+
app_path = Storys::Package.gem_path + "app/"
|
67
|
+
app_path.children.reject { |f| f.basename.to_s == "img"} #TODO: Deal with this directory properly
|
68
|
+
end
|
69
|
+
end
|
data/lib/storys/story.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
class Storys::Story
|
2
|
-
attr_reader :
|
3
|
-
attr_reader :path
|
2
|
+
attr_reader :package
|
3
|
+
attr_reader :path
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@
|
5
|
+
def initialize(package, path)
|
6
|
+
@package = package
|
7
7
|
@path = path
|
8
|
-
|
8
|
+
end
|
9
|
+
|
10
|
+
#It is assumed that the HTML document is a valid HTML expression of an NSF document
|
11
|
+
def html
|
12
|
+
@html ||= File.read(@path)
|
9
13
|
end
|
10
14
|
|
11
15
|
def path_hash
|
@@ -13,26 +17,45 @@ class Storys::Story
|
|
13
17
|
end
|
14
18
|
|
15
19
|
def url
|
16
|
-
|
20
|
+
package.pathname_to_url(path, package.package_path)
|
17
21
|
end
|
18
22
|
|
19
23
|
def title
|
20
|
-
title =
|
24
|
+
title = title_from_html
|
21
25
|
title = path.basename.to_s.chomp(path.extname.to_s) if title == ""
|
26
|
+
|
27
|
+
directory_path = path.relative_path_from(package.root_path).dirname.to_s
|
28
|
+
|
29
|
+
title = "#{directory_path}/#{title}" unless directory_path == "" || directory_path == "."
|
30
|
+
title = title.gsub("/", " / ")
|
31
|
+
|
22
32
|
title
|
23
33
|
end
|
24
34
|
|
25
|
-
def self.from_hash(
|
26
|
-
Storys::Story.new(
|
35
|
+
def self.from_hash(package, data)
|
36
|
+
Storys::Story.new(package, package.url_to_pathname(Addressable::URI.parse(data["url"])))
|
27
37
|
end
|
28
38
|
|
29
39
|
def to_hash
|
30
40
|
{
|
31
41
|
"url" => url,
|
32
|
-
"wordCount" =>
|
42
|
+
"wordCount" => word_count_from_html,
|
33
43
|
"title" => title,
|
34
44
|
"publishedOn" => path.mtime.to_i,
|
35
45
|
"key" => path_hash
|
36
46
|
}
|
37
47
|
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def title_from_html
|
52
|
+
html =~ /<title>(.*?)<\/title>/m
|
53
|
+
$1 ? CGI::unescapeHTML($1) : ""
|
54
|
+
end
|
55
|
+
|
56
|
+
def word_count_from_html
|
57
|
+
html =~ /<body>(.*?)<\/body>/m
|
58
|
+
body = CGI::unescapeHTML($1.gsub(/<\/?(p|b|i|h[1234567]).*?>/m, " "))
|
59
|
+
(title + " " + (body ? body : "")).split(/\s+/).length
|
60
|
+
end
|
38
61
|
end
|
data/lib/storys/update.rb
CHANGED
@@ -1,26 +1,35 @@
|
|
1
1
|
class Storys::Update
|
2
|
-
attr_reader :
|
2
|
+
attr_reader :package
|
3
3
|
attr_accessor :stories
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@
|
5
|
+
def initialize(package)
|
6
|
+
@package = package
|
7
7
|
|
8
|
-
@files =
|
8
|
+
@files = package.root_path.descendant_files.reject { |p| p.basename.to_s[0..0] == '.' }
|
9
9
|
@stories = []
|
10
10
|
#load_data
|
11
11
|
process
|
12
12
|
save_data
|
13
|
+
puts "\nDone!"
|
13
14
|
end
|
14
15
|
|
15
16
|
def load_data
|
16
|
-
self.stories = (Storys::
|
17
|
+
self.stories = (Storys::Package.load_json(package.package_path + "data.json") || []).map { |b| Storys::Story.from_hash(package, b) }
|
17
18
|
end
|
18
19
|
|
19
20
|
def save_data
|
20
21
|
puts "\nWriting out JSON file"
|
21
|
-
|
22
|
+
stories_hashes = []
|
23
|
+
stories.each_with_index do |s, i|
|
24
|
+
$stdout.write "\rProcessing #{i + 1} of #{stories.length} (#{(((i + 1) / stories.length.to_f) * 100.0).round}%)"
|
25
|
+
$stdout.flush
|
26
|
+
|
27
|
+
stories_hashes << s.to_hash
|
28
|
+
end
|
29
|
+
Storys::Package.save_json(package.package_path + "data.json", stories_hashes)
|
22
30
|
end
|
23
31
|
|
32
|
+
|
24
33
|
def process
|
25
34
|
@files.each_with_index do |f, i|
|
26
35
|
$stdout.write "\rProcessing #{i + 1} of #{@files.length} (#{(((i + 1) / @files.length.to_f) * 100.0).round}%)"
|
@@ -45,7 +54,7 @@ class Storys::Update
|
|
45
54
|
end
|
46
55
|
|
47
56
|
def created(f)
|
48
|
-
story = Storys::Story.new(
|
57
|
+
story = Storys::Story.new(package, f)
|
49
58
|
stories << story
|
50
59
|
end
|
51
60
|
|
data/lib/storys/version.rb
CHANGED
data/lib/storys.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#Ruby stdlib
|
2
2
|
require "pathname"
|
3
3
|
require "fileutils"
|
4
|
+
require "cgi"
|
4
5
|
require "uri"
|
5
6
|
require "json"
|
6
7
|
require "digest"
|
@@ -8,7 +9,6 @@ require "digest"
|
|
8
9
|
#Gems
|
9
10
|
require "addressable/uri"
|
10
11
|
require "naturally"
|
11
|
-
require "nsf"
|
12
12
|
|
13
13
|
#Core Extensions
|
14
14
|
require "storys/core_ext/pathname"
|
@@ -16,8 +16,6 @@ require "storys/core_ext/pathname"
|
|
16
16
|
module Storys
|
17
17
|
end
|
18
18
|
|
19
|
-
require "storys/
|
20
|
-
require "storys/storys_package"
|
19
|
+
require "storys/package"
|
21
20
|
require "storys/update"
|
22
21
|
require "storys/story"
|
23
|
-
require "storys/template_helper"
|
data/storys.gemspec
CHANGED
@@ -17,7 +17,6 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.add_development_dependency "bundler", ">= 1.0.0"
|
18
18
|
s.add_dependency "addressable", ">= 2.3.5"
|
19
19
|
s.add_dependency "naturally", ">= 1.0.3"
|
20
|
-
s.add_dependency "nsf"
|
21
20
|
|
22
21
|
s.files = `git ls-files`.split("\n")
|
23
22
|
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: storys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brenton "B-Train" Fletcher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 1.0.3
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: nsf
|
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
55
|
description: A collection of stories is a directory (the container) containing 1..*
|
70
56
|
HTML files (stories). Storys indexes a collection in this format, and generates
|
71
57
|
a HTML/JS Single Page Application (SPA) that allows you to browse and view stories
|
@@ -84,8 +70,13 @@ files:
|
|
84
70
|
- Rakefile
|
85
71
|
- app/css/app.css
|
86
72
|
- app/css/colorbox.css
|
73
|
+
- app/css/lib/bootstrap.css
|
87
74
|
- app/css/views.index.css
|
88
75
|
- app/css/views.show.css
|
76
|
+
- app/fonts/lib/glyphicons-halflings-regular.eot
|
77
|
+
- app/fonts/lib/glyphicons-halflings-regular.svg
|
78
|
+
- app/fonts/lib/glyphicons-halflings-regular.ttf
|
79
|
+
- app/fonts/lib/glyphicons-halflings-regular.woff
|
89
80
|
- app/img/blank.png
|
90
81
|
- app/img/icons/accept.png
|
91
82
|
- app/img/icons/add.png
|
@@ -1094,6 +1085,7 @@ files:
|
|
1094
1085
|
- app/js/controllers.show.js
|
1095
1086
|
- app/js/framework.js
|
1096
1087
|
- app/js/jquery.twoup.js
|
1088
|
+
- app/js/lib/bootstrap.js
|
1097
1089
|
- app/js/lib/jquery-2.0.3.js
|
1098
1090
|
- app/js/lib/jquery.ba-bbq.js
|
1099
1091
|
- app/js/lib/jquery.browser.js
|
@@ -1102,11 +1094,8 @@ files:
|
|
1102
1094
|
- bin/storys
|
1103
1095
|
- lib/storys.rb
|
1104
1096
|
- lib/storys/core_ext/pathname.rb
|
1097
|
+
- lib/storys/package.rb
|
1105
1098
|
- lib/storys/story.rb
|
1106
|
-
- lib/storys/storys.rb
|
1107
|
-
- lib/storys/storys_package.rb
|
1108
|
-
- lib/storys/template_helper.rb
|
1109
|
-
- lib/storys/templates/show.html.haml
|
1110
1099
|
- lib/storys/update.rb
|
1111
1100
|
- lib/storys/version.rb
|
1112
1101
|
- storys.gemspec
|
data/lib/storys/storys.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
class Storys::Storys
|
2
|
-
attr_reader :root_path
|
3
|
-
attr_reader :storys_path
|
4
|
-
|
5
|
-
def pathname_to_url(path, relative_from)
|
6
|
-
URI.escape(path.relative_path_from(relative_from).to_s)
|
7
|
-
end
|
8
|
-
|
9
|
-
def url_to_pathname(url)
|
10
|
-
path = Addressable::URI.unencode_component(url.normalized_path)
|
11
|
-
path.gsub!(/^\//, "") #Make relative, if we allow mounting at a different root URL this will need to remove the root instead of just '/'
|
12
|
-
root_url_path + path
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.gem_path
|
16
|
-
Pathname.new(__FILE__).dirname.parent.parent
|
17
|
-
end
|
18
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
class Storys::Storys
|
2
|
-
def initialize(root_path)
|
3
|
-
raise "root_path must be an instance of Pathname" unless root_path.is_a?(Pathname)
|
4
|
-
|
5
|
-
@root_path = root_path
|
6
|
-
@storys_path = root_path + ".storys/"
|
7
|
-
end
|
8
|
-
|
9
|
-
def update
|
10
|
-
update_app
|
11
|
-
Storys::Update.new(self)
|
12
|
-
end
|
13
|
-
|
14
|
-
def install
|
15
|
-
storys_path.mkdir unless File.exists?(storys_path)
|
16
|
-
|
17
|
-
update_app
|
18
|
-
end
|
19
|
-
|
20
|
-
def update_app
|
21
|
-
dev = ENV["STORYS_ENV"] == "development"
|
22
|
-
|
23
|
-
app_children_paths.each do |file|
|
24
|
-
storys_file = storys_path + file.basename
|
25
|
-
FileUtils.rm_rf(storys_file, :verbose => dev)
|
26
|
-
end
|
27
|
-
|
28
|
-
if dev
|
29
|
-
app_children_paths.each do |file|
|
30
|
-
storys_file = storys_path + file.basename
|
31
|
-
FileUtils.ln_sf(file, storys_file, :verbose => dev)
|
32
|
-
end
|
33
|
-
else
|
34
|
-
FileUtils.cp_r(Storys::Storys.gem_path + "app/.", storys_path, :verbose => dev)
|
35
|
-
end
|
36
|
-
|
37
|
-
FileUtils.chmod_R(0755, storys_path, :verbose => dev)
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.load_json(path)
|
41
|
-
if File.exists?(path)
|
42
|
-
JSON.parse(File.read(path))
|
43
|
-
else
|
44
|
-
nil
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.save_json(path, data)
|
49
|
-
File.open(path, "w") { |f| f << data.to_json }
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
def app_children_paths
|
54
|
-
app_path = Storys::Storys.gem_path + "app/"
|
55
|
-
app_path.children.reject { |f| f.basename.to_s == "img"} #TODO: Deal with this directory properly
|
56
|
-
end
|
57
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
%html
|
3
|
-
%head
|
4
|
-
%meta{ charset: "utf-8" }
|
5
|
-
%title #{directory.title} - Manga Reader
|
6
|
-
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
|
7
|
-
%script{ type: "text/javascript", src: (assets_url + "js/lib/jquery-1.4.4.js") }
|
8
|
-
%script{ type: "text/javascript", src: (assets_url + "js/lib/jquery.ba-bbq.js") }
|
9
|
-
%script{ type: "text/javascript", src: (assets_url + "js/show.js") }
|
10
|
-
%link{ rel: "stylesheet", type: "text/css", href: (assets_url + "css/style.css") }
|
11
|
-
%link{ rel: "stylesheet", type: "text/css", href: (assets_url + "css/show.css") }
|
12
|
-
<meta name="HandheldFriendly" content="true" />
|
13
|
-
<meta name="viewport" content="width=device-width, height=device-height, user-scalable=no" />
|
14
|
-
:javascript
|
15
|
-
var pages = #{directory.page_urls.to_json};
|
16
|
-
%body
|
17
|
-
%img#image{ src: (assets_url + "img/blank.png") }
|