gast 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62f0f0b4b03eaf63cbfb2e6ddb5d41137b174ddd
4
- data.tar.gz: 5d18e8c2a79ade92fb5c3ca3881a24f75d0549c4
3
+ metadata.gz: ff0f8ec7fce32cf0d453a25839940dc20580b28e
4
+ data.tar.gz: 5444c833df7d594157daffaf413d6139a047975a
5
5
  SHA512:
6
- metadata.gz: beee6f573bde844c995656b335571892c1e7a45fdff0679b18b4c23fc1c07acf2527ed636f956272769eab887084345eb1ea239a26bf9e49967dbf39629b88f1
7
- data.tar.gz: f42392c4a42e9f6cde24c7a98b08fdf600663b0f3aeb51c49874d58538b9c9627ba918f6eca3a42a0ab164ead6bc830d63bbc1af1a071671fbe534488578206e
6
+ metadata.gz: 7e6464539b961580930079e0a4e9c11be05cbfb8e6256d995915b5f15f58a178ceed9ab96e567a00caea90d355c8d96f356993db13b69515cf0b712a132c1d20
7
+ data.tar.gz: b2479da1e1f4393620114c180534b24a3c684c76e65dc8d8186de4521dd571384f5e37e1983ecb50e931eda2764bb3330d2ddf1ad2fe953423aeea6f22cf99dd
data/Guardfile CHANGED
@@ -3,9 +3,7 @@
3
3
 
4
4
  guard :spork, :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
5
5
  watch('lib/gast.rb')
6
- watch('lib/gast/app.rb')
7
- watch('lib/gast/memo.rb.rb')
8
- watch('lib/gast/version.rb')
6
+ watch(%r{^lib/gast/(.+)\.rb$})
9
7
  watch('Gemfile.lock')
10
8
  watch('spec/spec_helper.rb') { :rspec }
11
9
  watch('test/test_helper.rb') { :test_unit }
data/lib/gast/app.rb CHANGED
@@ -55,6 +55,7 @@ module Gast
55
55
 
56
56
  get '/posts/view/:id' do
57
57
  @item = Gast::Memo.item(params[:id].to_s)
58
+ @language = Gast::Memo.language(params[:id].to_s)
58
59
  @content_hash = params[:id].to_s
59
60
  haml :view
60
61
  end
@@ -68,14 +69,17 @@ module Gast
68
69
  put '/posts/update/:id' do
69
70
  @result = Gast::Memo.update(
70
71
  id=params[:id].to_s,
71
- content=params[:content].to_s
72
+ content=params[:content].to_s,
73
+ language=params[:language].to_s
72
74
  )
73
75
  redirect to("/posts/view/#{params[:id]}")
74
76
  end
75
77
 
76
78
  post '/posts/new' do
77
- new_id = Gast::Memo.save(params[:content].to_s)
78
- redirect to("/posts/view/#{new_id}")
79
+ results = Gast::Memo.save(
80
+ params[:content].to_s, params[:language].to_s
81
+ )
82
+ redirect to("/posts/view/#{results[:id]}")
79
83
  end
80
84
 
81
85
  end
data/lib/gast/memo.rb CHANGED
@@ -4,21 +4,29 @@ module Gast
4
4
 
5
5
  class Memo
6
6
 
7
- def self.save(content)
7
+ def self.save(content, language="no-highlight")
8
8
  @repo = Gast::Repository.new
9
9
  @repo.content = CGI.unescapeHTML(content.to_s)
10
+ @repo.language = CGI.unescapeHTML(language.to_s)
10
11
  @repo.publish
11
12
  @repo.commit!
12
- @repo.dir_name
13
+ {
14
+ id: @repo.dir_name,
15
+ language: language
16
+ }
13
17
  end
14
18
 
15
- def self.update(id, content)
19
+ def self.update(id, content, language="no-highlight")
16
20
  return id if content.to_s.chomp == item(id).chomp
17
21
  @repo = Gast::Repository.new(id)
18
22
  @repo.content = CGI.unescapeHTML(content.to_s)
23
+ @repo.language = CGI.unescapeHTML(language.to_s)
19
24
  @repo.publish
20
25
  @repo.commit!
21
- @repo.dir_name
26
+ {
27
+ id: @repo.dir_name,
28
+ language: language
29
+ }
22
30
  end
23
31
 
24
32
  def self.number
@@ -37,6 +45,12 @@ module Gast
37
45
  )
38
46
  end
39
47
 
48
+ def self.language(id)
49
+ CGI.escapeHTML(
50
+ File.read(File.expand_path(Gast::PATH + "/#{id}/language"))
51
+ )
52
+ end
53
+
40
54
  def initialize; end
41
55
 
42
56
  end
@@ -23,9 +23,13 @@ module Gast
23
23
  @content = content
24
24
  end
25
25
 
26
+ def language=(language)
27
+ @language = language.to_s
28
+ end
29
+
26
30
  def publish
27
- @save_path = File.expand_path(@path + '/content')
28
- open(@save_path, 'w', 0644) { |io| io.write(@content) }
31
+ save_content
32
+ save_language
29
33
  end
30
34
 
31
35
  def remove!
@@ -51,6 +55,16 @@ module Gast
51
55
  end
52
56
  end
53
57
 
58
+ def save_content
59
+ path = File.expand_path(@path + "/content")
60
+ open(path, 'w', 0644) { |io| io.write(@content) }
61
+ end
62
+
63
+ def save_language
64
+ path = File.expand_path(@path + '/language')
65
+ open(path, 'w', 0644) { |io| io.write(@language) }
66
+ end
67
+
54
68
  end
55
69
 
56
70
  end
@@ -1,8 +1,11 @@
1
1
  .form-group
2
- %select
3
- %option
2
+ %select{ name: "language" }
3
+ %option{ value: "python" }
4
4
  python
5
- %textarea{ class: "form-control", style: "margin-top: 10px; height: 30em;", name: "content" }
6
- = @item
5
+ %option{ value: "ruby"}
6
+ ruby
7
+ = preserve do
8
+ %textarea{ class: "form-control", style: "margin-top: 10px; height: 30em;", name: "content", wrap: "hard" }
9
+ = @item
7
10
  %button{ type: "submit", class: "btn btn-primary" }
8
11
  Submit
@@ -4,5 +4,7 @@
4
4
  %link{:href=>"//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css", :rel=>"stylesheet"}
5
5
  %script{:src=>"//code.jquery.com/jquery-2.1.0.min.js"}
6
6
  %script{:src=>"//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"}
7
- %link{ rel: 'stylesheet', href: stylesheet_path('application') }
8
-
7
+ %script{ src: 'http://yandex.st/highlightjs/8.0/highlight.min.js' }
8
+ %link{ rel: 'stylesheet', href: '//yandex.st/highlightjs/8.0/styles/default.min.css' }
9
+ :javascript
10
+ hljs.initHighlightingOnLoad();
@@ -6,3 +6,4 @@
6
6
  = haml :navbar
7
7
  .container
8
8
  = yield
9
+
@@ -3,5 +3,9 @@
3
3
  %form{ role: "form", action: "/posts/edit/#{params[:id].to_s}", method: "GET" }
4
4
  %button{ type: "submit", class: "btn btn-primary" }
5
5
  Update
6
- %p{ style: "margin-top: 20px;" }
7
- = @item
6
+
7
+ %div{ style: "margin-top: 20px;" }
8
+ = preserve do
9
+ %pre{ style: "white-space: pre-wrap;" }
10
+ %code{ class: "#{@language}" }
11
+ = @item
data/lib/gast/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gast
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -15,6 +15,8 @@ describe Gast::App do
15
15
  let(:hello_world) { "Hello World" }
16
16
  let(:welcome_to_underground) { "Welcome to underground" }
17
17
  let(:inline_html) { "<script>alert('Hello world!');</script>" }
18
+ let(:sample_of_code_ruby) { get_fixture('sample_of_code.rb') }
19
+
18
20
  let(:view_path) { /.+\/posts\/view\/[a-z0-9]+/ }
19
21
 
20
22
  it "should be get index" do
@@ -105,4 +107,29 @@ describe Gast::App do
105
107
 
106
108
  end
107
109
 
110
+ it "should be post language type the code highlight" do
111
+ post '/posts/new', { content: sample_of_code_ruby, language: "ruby" }
112
+ repository = File.expand_path(Dir.glob(repo_dir + '/**').first)
113
+
114
+ expect(File.read(repository + '/content')).to eq sample_of_code_ruby
115
+ expect(File.read(repository + '/language')).to eq "ruby"
116
+
117
+ get "/posts/view/#{repository.split('/').last}"
118
+
119
+ expect(last_response).to be_ok
120
+ end
121
+
122
+ it "should be succeeded change of language type" do
123
+ post '/posts/new', { content: sample_of_code_ruby, language: "ruby" }
124
+ repository = File.expand_path(Dir.glob(repo_dir + '/**').first)
125
+
126
+ expect(File.read(repository + '/content')).to eq sample_of_code_ruby
127
+ expect(File.read(repository + '/language')).to eq "ruby"
128
+
129
+ put "/posts/update/#{repository.split('/').last}", { content: sample_of_code_ruby, language: "python" }
130
+
131
+ expect(File.read(repository + '/content')).to eq sample_of_code_ruby
132
+ expect(File.read(repository + '/language')).to eq "python"
133
+ end
134
+
108
135
  end
@@ -0,0 +1,13 @@
1
+ require 'cgi'
2
+
3
+ module Gast
4
+ class Post
5
+ def initalize(content)
6
+ @content = content
7
+ end
8
+
9
+ def view
10
+ CGI.escapeHTML(@content)
11
+ end
12
+ end
13
+ end
@@ -11,9 +11,11 @@ describe Gast::Repository do
11
11
  let(:repo_dir) { "/tmp/gast" }
12
12
 
13
13
  let(:user_content) { "Hello World" }
14
+ let(:selected_language) { "ruby" }
14
15
 
15
16
  before(:each) {
16
17
  repo.content = user_content
18
+ repo.language = selected_language
17
19
  repo.publish
18
20
  repo.commit!
19
21
  }
@@ -30,6 +32,10 @@ describe Gast::Repository do
30
32
  expect(File.read(repo.path + '/content')).to eq user_content
31
33
  end
32
34
 
35
+ it "should be language is a ruby" do
36
+ expect(File.read(repo.path + '/language')).to eq selected_language
37
+ end
38
+
33
39
  it "should be save of commit message is correct" do
34
40
  Timecop.freeze
35
41
  expect(git.log.first.message).to eq "commit: #{DateTime.now.to_s}"
data/spec/spec_helper.rb CHANGED
@@ -38,3 +38,7 @@ RSpec.configure do |config|
38
38
 
39
39
  config.order = 'random'
40
40
  end
41
+
42
+ def get_fixture(name)
43
+ File.read(File.expand_path('./fixtures/' + name, __dir__))
44
+ end
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - futoase
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-22 00:00:00.000000000 Z
11
+ date: 2014-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -271,6 +271,7 @@ files:
271
271
  - lib/gast/templates/view.haml
272
272
  - lib/gast/version.rb
273
273
  - spec/controller_spec.rb
274
+ - spec/fixtures/sample_of_code.rb
274
275
  - spec/memo_spec.rb
275
276
  - spec/repository_spec.rb
276
277
  - spec/spec_helper.rb
@@ -300,6 +301,7 @@ specification_version: 4
300
301
  summary: memo application of using git
301
302
  test_files:
302
303
  - spec/controller_spec.rb
304
+ - spec/fixtures/sample_of_code.rb
303
305
  - spec/memo_spec.rb
304
306
  - spec/repository_spec.rb
305
307
  - spec/spec_helper.rb