gast 0.0.10 → 0.0.11
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 +4 -4
- data/Gemfile.lock +4 -4
- data/lib/gast/base.rb +14 -9
- data/lib/gast/helper.rb +6 -1
- data/lib/gast/memo.rb +31 -21
- data/lib/gast/repository.rb +11 -1
- data/lib/gast/templates/form_area.haml +2 -1
- data/lib/gast/templates/languages.haml +2 -2
- data/lib/gast/templates/list.haml +5 -1
- data/lib/gast/templates/title.haml +1 -0
- data/lib/gast/templates/view.haml +6 -2
- data/lib/gast/version.rb +1 -1
- data/spec/controller_spec.rb +16 -0
- data/spec/feature/index_spec.rb +7 -0
- data/spec/repository_spec.rb +6 -0
- data/spec/spec_helper.rb +4 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d28db257ac5b3ca94999e73923159eb1103d44f
|
4
|
+
data.tar.gz: b333fa902740c3fedc0f690f2f4d27d3aa560fb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd83c840284896c541cd0ead58e0ab41b35a7ac517ea1fa4f8c814216187fe5e49a35ab067f593489a5392f284e1a5069b35d6f27ddb475e1710ed675d4fe139
|
7
|
+
data.tar.gz: d45e7f45e793873742db3ef4ac255aebea6abbc619ac14a7dbad0cf3d8e7eda401e190b78cc8c759d20d4f3813b4327e2649cb14b060bc801ebe261b43cb8760
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
gast (0.0.
|
4
|
+
gast (0.0.10)
|
5
5
|
bundler (~> 1.6)
|
6
6
|
git
|
7
7
|
haml
|
@@ -87,7 +87,7 @@ GEM
|
|
87
87
|
pry-remote (0.1.8)
|
88
88
|
pry (~> 0.9)
|
89
89
|
slop (~> 3.0)
|
90
|
-
puma (2.11.
|
90
|
+
puma (2.11.1)
|
91
91
|
rack (>= 1.1, < 2.0)
|
92
92
|
rack (1.6.0)
|
93
93
|
rack-protection (1.5.3)
|
@@ -119,8 +119,8 @@ GEM
|
|
119
119
|
ruby-progressbar (~> 1.4)
|
120
120
|
ruby-progressbar (1.7.1)
|
121
121
|
safe_yaml (1.0.4)
|
122
|
-
sass (3.4.
|
123
|
-
sequel (4.
|
122
|
+
sass (3.4.13)
|
123
|
+
sequel (4.19.0)
|
124
124
|
shellany (0.0.1)
|
125
125
|
sinatra (1.4.5)
|
126
126
|
rack (~> 1.4)
|
data/lib/gast/base.rb
CHANGED
@@ -46,15 +46,16 @@ module Gast
|
|
46
46
|
namespace '/posts' do
|
47
47
|
before %r{/\w+/(\w+)} do |id|
|
48
48
|
unless /[a-zA-Z0-9]{30}/ =~ id.to_s
|
49
|
-
halt haml(:error, locals: {
|
49
|
+
halt haml(:error, locals: {
|
50
50
|
message: 'error is format of id'
|
51
51
|
})
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
before '/new' do
|
56
|
-
@content
|
56
|
+
@content = params[:content].to_s
|
57
57
|
@language = params[:language].to_s
|
58
|
+
@title = params[:title].to_s
|
58
59
|
|
59
60
|
if @content.length == 0
|
60
61
|
halt haml(:error, locals: {
|
@@ -62,7 +63,7 @@ module Gast
|
|
62
63
|
})
|
63
64
|
end
|
64
65
|
|
65
|
-
result = Gast::Memo.create(@content, @language)
|
66
|
+
result = Gast::Memo.create(@content, @language, @title)
|
66
67
|
@content_id = result.content_id
|
67
68
|
end
|
68
69
|
|
@@ -73,14 +74,16 @@ module Gast
|
|
73
74
|
before '/*/:content_id' do
|
74
75
|
if %w[view log edit update].include? request.path_info.split('/')[2]
|
75
76
|
@content_id = params[:content_id].to_s
|
76
|
-
@content
|
77
|
-
@language
|
77
|
+
@content = params[:content].to_s
|
78
|
+
@language = params[:language].to_s
|
79
|
+
@title = params[:title].to_s
|
78
80
|
end
|
79
81
|
end
|
80
82
|
|
81
83
|
before '/view/:content_id' do
|
82
|
-
@item
|
84
|
+
@item = Gast::Memo.item(@content_id)
|
83
85
|
@language = Gast::Memo.language(@content_id)
|
86
|
+
@title = Gast::Memo.title(@content_id)
|
84
87
|
end
|
85
88
|
|
86
89
|
before '/log/:content_id' do
|
@@ -88,12 +91,14 @@ module Gast
|
|
88
91
|
end
|
89
92
|
|
90
93
|
before '/edit/:content_id' do
|
91
|
-
@item
|
94
|
+
@item = Gast::Memo.item(@content_id)
|
95
|
+
@language = Gast::Memo.language(@content_id)
|
96
|
+
@title = Gast::Memo.title(@content_id)
|
92
97
|
end
|
93
98
|
|
94
99
|
before '/update/:content_id' do
|
95
|
-
if Gast::Memo.changed?(@content_id, @content)
|
96
|
-
Gast::Memo.update(@content_id, @content, @language)
|
100
|
+
if Gast::Memo.changed?(@content_id, @content, @language, @title)
|
101
|
+
Gast::Memo.update(@content_id, @content, @language, @title)
|
97
102
|
end
|
98
103
|
end
|
99
104
|
end
|
data/lib/gast/helper.rb
CHANGED
@@ -13,7 +13,7 @@ module Gast
|
|
13
13
|
def get_content(id)
|
14
14
|
File.read(File.expand_path(Gast::PATH + "/#{id}/content"))
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def get_content_dir(id)
|
18
18
|
File.expand_path(Gast::PATH + "/#{id}")
|
19
19
|
end
|
@@ -21,5 +21,10 @@ module Gast
|
|
21
21
|
def get_language(id)
|
22
22
|
File.read(File.expand_path(Gast::PATH + "/#{id}/language"))
|
23
23
|
end
|
24
|
+
|
25
|
+
def get_title(id)
|
26
|
+
path = File.expand_path(Gast::PATH + "/#{id}/title")
|
27
|
+
File.exists?(path) ? File.read(path) : nil
|
28
|
+
end
|
24
29
|
end
|
25
30
|
end
|
data/lib/gast/memo.rb
CHANGED
@@ -5,61 +5,66 @@ module Gast
|
|
5
5
|
extend Helper
|
6
6
|
|
7
7
|
class Response
|
8
|
-
attr_reader :content_id, :language, :content
|
8
|
+
attr_reader :content_id, :language, :content, :title
|
9
9
|
|
10
|
-
def initialize(content_id, language, content)
|
10
|
+
def initialize(content_id, language, content, title)
|
11
11
|
@content_id = content_id
|
12
|
-
@language
|
13
|
-
@content
|
12
|
+
@language = language
|
13
|
+
@content = content
|
14
|
+
@title = title
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
18
|
class Request
|
18
|
-
attr_reader :content_id, :language, :content
|
19
|
+
attr_reader :content_id, :language, :content, :title
|
19
20
|
|
20
|
-
def initialize(content_id, language, content)
|
21
|
+
def initialize(content_id, language, content, title)
|
21
22
|
@content_id = content_id
|
22
|
-
@language
|
23
|
-
@content
|
23
|
+
@language = language
|
24
|
+
@content = content
|
25
|
+
@title = title
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
27
|
-
def response(content_id, language, content)
|
28
|
-
Response.new(content_id, language, content)
|
29
|
+
def response(content_id, language, content, title)
|
30
|
+
Response.new(content_id, language, content, title)
|
29
31
|
end
|
30
32
|
module_function :response
|
31
33
|
|
32
|
-
def request(content_id, language, content)
|
33
|
-
Request.new(content_id, language, content)
|
34
|
+
def request(content_id, language, content, title)
|
35
|
+
Request.new(content_id, language, content, title)
|
34
36
|
end
|
35
37
|
module_function :request
|
36
38
|
|
37
|
-
def repository(content, language, content_id = nil)
|
39
|
+
def repository(content, language, content_id = nil, title)
|
38
40
|
repo = Repository.new
|
39
41
|
repo.dir_name = content_id
|
40
42
|
repo.create
|
41
43
|
repo.content = unescape_html { content }
|
42
44
|
repo.language = unescape_html { language }
|
45
|
+
repo.title = unescape_html { title }
|
43
46
|
repo.write
|
44
47
|
repo.commit!
|
45
48
|
|
46
49
|
repo.dir_name
|
47
50
|
end
|
48
51
|
|
49
|
-
def create(content, language = DEFAULT_HIGHLIGHT)
|
50
|
-
content_id = repository(content, language)
|
51
|
-
response(content_id, language, content)
|
52
|
+
def create(content, language = DEFAULT_HIGHLIGHT, title = nil)
|
53
|
+
content_id = repository(content, language, nil, title)
|
54
|
+
response(content_id, language, content, title)
|
52
55
|
end
|
53
56
|
module_function :create
|
54
57
|
|
55
|
-
def update(content_id, content, language = DEFAULT_HIGHLIGHT)
|
56
|
-
content_id = repository(content, language, content_id)
|
57
|
-
response(content_id, language, content)
|
58
|
+
def update(content_id, content, language = DEFAULT_HIGHLIGHT, title = nil)
|
59
|
+
content_id = repository(content, language, content_id, title)
|
60
|
+
response(content_id, language, content, title)
|
58
61
|
end
|
59
62
|
module_function :update
|
60
63
|
|
61
|
-
def changed?(content_id, content)
|
62
|
-
content.to_s.chomp
|
64
|
+
def changed?(content_id, content, language, title)
|
65
|
+
content.to_s.chomp != item(content_id).chomp ||
|
66
|
+
language.to_s.chomp != language(content_id).chomp ||
|
67
|
+
title.to_s.chomp != title(content_id).chomp
|
63
68
|
end
|
64
69
|
module_function :changed?
|
65
70
|
|
@@ -72,6 +77,7 @@ module Gast
|
|
72
77
|
Dir.glob(File.expand_path(Gast::PATH + '/**')).map do |dir|
|
73
78
|
{
|
74
79
|
content_id: dir.split('/').last,
|
80
|
+
title: File.exist?(dir + '/title') ? File.open(dir + '/title').read : nil,
|
75
81
|
updated_at: File.stat(dir + '/content').mtime
|
76
82
|
}
|
77
83
|
end
|
@@ -92,6 +98,10 @@ module Gast
|
|
92
98
|
def language(id)
|
93
99
|
escape_html { get_language(id) }
|
94
100
|
end
|
101
|
+
|
102
|
+
def title(id)
|
103
|
+
escape_html { get_title(id) }
|
104
|
+
end
|
95
105
|
module_function :language
|
96
106
|
|
97
107
|
extend Memo
|
data/lib/gast/repository.rb
CHANGED
@@ -3,7 +3,7 @@ require 'gast'
|
|
3
3
|
module Gast
|
4
4
|
class Repository
|
5
5
|
attr_reader :path
|
6
|
-
attr_writer :content, :language
|
6
|
+
attr_writer :content, :language, :title
|
7
7
|
attr_accessor :dir_name
|
8
8
|
|
9
9
|
def initialize; end
|
@@ -18,6 +18,7 @@ module Gast
|
|
18
18
|
def write
|
19
19
|
write_content
|
20
20
|
write_language
|
21
|
+
write_title
|
21
22
|
end
|
22
23
|
|
23
24
|
def log
|
@@ -64,6 +65,15 @@ module Gast
|
|
64
65
|
end
|
65
66
|
end
|
66
67
|
|
68
|
+
def write_title
|
69
|
+
path = File.expand_path(@path + '/title')
|
70
|
+
open(path, 'w', 0644) do |io|
|
71
|
+
io.flock(File::LOCK_EX)
|
72
|
+
io.write(@title)
|
73
|
+
io.flock(File::LOCK_UN)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
67
77
|
def new_name_of_repository
|
68
78
|
if @dir_name.nil?
|
69
79
|
@dir_name = Digest::SHA512.new.update(rand.to_s).to_s[0..30]
|
@@ -2,9 +2,11 @@
|
|
2
2
|
Items
|
3
3
|
%table{ class: "table table-striped" }
|
4
4
|
%thead
|
5
|
-
%tr
|
5
|
+
%tr
|
6
6
|
%th
|
7
7
|
Content ID
|
8
|
+
%th
|
9
|
+
Title
|
8
10
|
%th
|
9
11
|
Updated At
|
10
12
|
%tbody
|
@@ -13,5 +15,7 @@
|
|
13
15
|
%td
|
14
16
|
%a{ href: url("/posts/view/#{list[:content_id]}") }
|
15
17
|
= list[:content_id]
|
18
|
+
%td
|
19
|
+
= CGI.escapeHTML(list[:title])
|
16
20
|
%td
|
17
21
|
= list[:updated_at]
|
@@ -0,0 +1 @@
|
|
1
|
+
%input{name: "title", placeholder: "Title...", value:(!@title || @title == '') ? '' : @title, maxlength:40, size:40, style:"margin-left:30px;padding-left:10px;"}
|
@@ -1,8 +1,12 @@
|
|
1
1
|
%h1
|
2
2
|
= @content_id
|
3
3
|
%form{ role: "form", action: "/posts/edit/#{@content_id}", method: "GET" }
|
4
|
-
%
|
5
|
-
|
4
|
+
%div.col-xs-2
|
5
|
+
%button{ type: "submit", class: "btn btn-primary" }
|
6
|
+
Update
|
7
|
+
%div.col-xs-10
|
8
|
+
%h3{ style:"margin-top: 3px;" }
|
9
|
+
= (@title == "") ? " " : @title
|
6
10
|
|
7
11
|
%div{ style: "margin-top: 20px;" }
|
8
12
|
= preserve do
|
data/lib/gast/version.rb
CHANGED
data/spec/controller_spec.rb
CHANGED
@@ -5,6 +5,7 @@ describe Gast::App do
|
|
5
5
|
let(:hello_world) { 'Hello World' }
|
6
6
|
let(:welcome_to_underground) { 'Welcome to underground' }
|
7
7
|
let(:inline_html) { "<script>alert('Hello world!');</script>" }
|
8
|
+
let(:inline_html_title) {"<b>hoge</b>"}
|
8
9
|
let(:sample_of_code_ruby) { get_fixture('sample_of_code.rb') }
|
9
10
|
let(:view_path) { %r{.+/posts/view/[a-z0-9]+} }
|
10
11
|
|
@@ -100,6 +101,21 @@ describe Gast::App do
|
|
100
101
|
expect(last_response.body).to include(CGI.escapeHTML(inline_html))
|
101
102
|
end
|
102
103
|
|
104
|
+
it 'should be title is escaped by HTML' do
|
105
|
+
post('/posts/new', content: inline_html, title:inline_html_title)
|
106
|
+
|
107
|
+
expect(latest_title).to eq inline_html_title
|
108
|
+
|
109
|
+
get "/posts/view/#{dir_name_of_latest_repository}"
|
110
|
+
|
111
|
+
expect(last_response).to be_ok
|
112
|
+
expect(last_response.body).to include(CGI.escapeHTML(inline_html_title))
|
113
|
+
|
114
|
+
get '/posts/list'
|
115
|
+
expect(last_response).to be_ok
|
116
|
+
expect(last_response.body).to include('<b>hoge</b>')
|
117
|
+
end
|
118
|
+
|
103
119
|
it 'should be post language type the code highlight' do
|
104
120
|
post('/posts/new', content: sample_of_code_ruby, language: 'ruby')
|
105
121
|
|
data/spec/feature/index_spec.rb
CHANGED
@@ -24,4 +24,11 @@ describe 'the index page', type: :feature do
|
|
24
24
|
find('//textarea').set 'Hello world'
|
25
25
|
find('//textarea').text eq 'Hello world'
|
26
26
|
end
|
27
|
+
|
28
|
+
it 'should be able to write text on the title input' do
|
29
|
+
visit '/'
|
30
|
+
|
31
|
+
find('//input').set 'My Title'
|
32
|
+
find('//input').text eq 'My Title'
|
33
|
+
end
|
27
34
|
end
|
data/spec/repository_spec.rb
CHANGED
@@ -5,10 +5,12 @@ describe Gast::Repository do
|
|
5
5
|
let(:git) { Git.init(repo.path) }
|
6
6
|
let(:user_content) { 'Hello World' }
|
7
7
|
let(:selected_language) { 'ruby' }
|
8
|
+
let(:title) { 'My awesome title' }
|
8
9
|
|
9
10
|
before(:each) do
|
10
11
|
repo.content = user_content
|
11
12
|
repo.language = selected_language
|
13
|
+
repo.title = title
|
12
14
|
repo.create
|
13
15
|
repo.write
|
14
16
|
repo.commit!
|
@@ -28,6 +30,10 @@ describe Gast::Repository do
|
|
28
30
|
expect(latest_language_of_content).to eq selected_language
|
29
31
|
end
|
30
32
|
|
33
|
+
it 'should be title is My awesome title' do
|
34
|
+
expect(latest_title).to eq title
|
35
|
+
end
|
36
|
+
|
31
37
|
it 'should be save of commit message is correct' do
|
32
38
|
Timecop.freeze
|
33
39
|
expect(git.log.first.message).to eq "commit: #{DateTime.now}"
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- futoase
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -261,6 +261,7 @@ files:
|
|
261
261
|
- lib/gast/templates/navbar.haml
|
262
262
|
- lib/gast/templates/not_found.haml
|
263
263
|
- lib/gast/templates/save.haml
|
264
|
+
- lib/gast/templates/title.haml
|
264
265
|
- lib/gast/templates/view.haml
|
265
266
|
- lib/gast/version.rb
|
266
267
|
- spec/controller_spec.rb
|