tiqbi 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # tiqbi(乳首)
2
2
  text-mode interface for qiita. 美
3
3
 
4
+
5
+ # Screenshot
6
+ ![http://pic.toqoz.net/cda7bc8341e1027a56eed200a301280b8a639d68.png](http://pic.toqoz.net/cda7bc8341e1027a56eed200a301280b8a639d68.png)
7
+
4
8
  # Usage
5
9
 
6
10
  ```sh
data/lib/tiqbi.rb CHANGED
@@ -3,16 +3,16 @@
3
3
  require 'logger'
4
4
  require 'curses'
5
5
  require 'sanitize'
6
- require 'qiita'
6
+ require 'active_support/cache'
7
7
 
8
8
  require 'tiqbi/version'
9
9
  require 'tiqbi/utils'
10
- require 'tiqbi/view'
10
+ require 'tiqbi/view_controller'
11
11
 
12
12
  module Tiqbi
13
13
  extend self
14
14
  extend Utils
15
- attr_accessor :view, :options
15
+ attr_accessor :view_controller, :options
16
16
 
17
17
  F_YELLOW_B_BLACK = 1
18
18
  F_RED_B_BLACK = 2
@@ -22,15 +22,14 @@ module Tiqbi
22
22
  # initialize console
23
23
  self.options = options
24
24
  configure_curses
25
- # get default window
26
25
  curses_screen = Curses.stdscr
27
- self.view = View.new(curses_screen)
26
+ self.view_controller = ViewController.new(curses_screen)
28
27
 
29
28
  # event loop
30
29
  begin
31
30
  loop {
32
- ch = view.current_window.getch
33
- view.on_input(ch)
31
+ ch = view_controller.current_view.getch
32
+ view_controller.on_input(ch)
34
33
  }
35
34
  ensure
36
35
  Curses.close_screen
@@ -41,6 +40,10 @@ module Tiqbi
41
40
  Pathname.new(File.dirname(__FILE__)).join("..")
42
41
  end
43
42
 
43
+ def cache
44
+ @cache ||= ActiveSupport::Cache::MemoryStore.new
45
+ end
46
+
44
47
  def logger
45
48
  @logger ||= Logger.new root.join('logs/app.log')
46
49
  end
@@ -0,0 +1,26 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'qiita'
3
+
4
+ module Tiqbi
5
+ module Qiita
6
+ extend self
7
+
8
+ def get(method, *args)
9
+ cache_key = "#{method}_#{args.join('_')}"
10
+ unless Tiqbi.cache.exist?(cache_key)
11
+ data = ::Qiita.send(method, *args) rescue nil
12
+ Tiqbi.cache.write(cache_key, data.dup) if data
13
+ else
14
+ data = Tiqbi.cache.read(cache_key).dup
15
+ end
16
+ data
17
+ end
18
+
19
+ def items
20
+ get(:item, "") || []
21
+ end
22
+ def item(uuid)
23
+ get(:item, uuid) || {}
24
+ end
25
+ end
26
+ end
data/lib/tiqbi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tiqbi
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,11 +1,11 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  require 'forwardable'
4
- require 'tiqbi/window/collection'
5
- require 'tiqbi/window/cursor'
4
+ require 'tiqbi/view/collection'
5
+ require 'tiqbi/view/cursor'
6
6
 
7
7
  module Tiqbi
8
- module Window
8
+ module View
9
9
  class Base
10
10
  attr_accessor :c_window, :cursor, :top_statement
11
11
  attr_reader :collection
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Tiqbi
4
- module Window
4
+ module View
5
5
  class Collection
6
6
  attr_accessor :collection
7
7
  def initialize(collection = [])
@@ -1,10 +1,10 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- require "tiqbi/window/base"
3
+ require "tiqbi/view/base"
4
4
 
5
5
  module Tiqbi
6
- module Window
7
- class CommandWindow < Base
6
+ module View
7
+ class CommandView < Base
8
8
  def initialize(*args)
9
9
  super(*args)
10
10
  end
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Tiqbi
4
- module Window
4
+ module View
5
5
  class Cursor
6
6
  attr_accessor :x, :y
7
7
 
@@ -1,10 +1,10 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- require "tiqbi/window/base"
3
+ require "tiqbi/view/base"
4
4
 
5
5
  module Tiqbi
6
- module Window
7
- class DetailWindow < Base
6
+ module View
7
+ class DetailView < Base
8
8
  include Tiqbi::Utils
9
9
 
10
10
  def initialize(*args)
@@ -1,10 +1,10 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- require "tiqbi/window/base"
3
+ require "tiqbi/view/base"
4
4
 
5
5
  module Tiqbi
6
- module Window
7
- class MainWindow < Base
6
+ module View
7
+ class MainView < Base
8
8
  def initialize(*args)
9
9
  # create subwindow
10
10
  super(*args)
@@ -0,0 +1,94 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'tiqbi/qiita'
4
+ require 'tiqbi/view/main_view'
5
+ require 'tiqbi/view/detail_view'
6
+ require 'tiqbi/view/command_view'
7
+
8
+ module Tiqbi
9
+ class ViewController
10
+ MAIN_VIEW = 1
11
+ DETAIL_VIEW = 2
12
+ COMMAND_VIEW = 3
13
+
14
+ include Utils
15
+ attr_accessor :views
16
+
17
+ def initialize(c_scr)
18
+ # calc size
19
+ scr_x = c_scr.maxx - c_scr.begx
20
+ scr_y = c_scr.maxy - c_scr.begy
21
+ main_h = scr_y / 2
22
+ cmd_h = 1
23
+ detail_h = main_h - cmd_h
24
+ # initialize all views
25
+ @views = {
26
+ MAIN_VIEW => View::MainView.new(c_scr, main_h, scr_x, 0, 0),
27
+ DETAIL_VIEW => View::DetailView.new(c_scr, detail_h, scr_x, main_h, 0),
28
+ COMMAND_VIEW => View::CommandView.new(c_scr, cmd_h, scr_x, main_h + detail_h, 0)
29
+ }
30
+
31
+ items = Qiita.items
32
+ @views[MAIN_VIEW].collection = items
33
+ @views[MAIN_VIEW].print
34
+ end
35
+
36
+ def on_input(input)
37
+ case input
38
+ when ?j
39
+ current_view.cursor_down
40
+ when ?k
41
+ current_view.cursor_up
42
+ when 10
43
+ if current_view == view(MAIN_VIEW)
44
+ index = current_view.cursor.y
45
+ item = current_view.collection.at(index)
46
+ return unless item
47
+ item_detail = Qiita.item(item.uuid)
48
+ view(DETAIL_VIEW).item_loaded item_detail
49
+ switch_to_next_view view(DETAIL_VIEW)
50
+ end
51
+ when ?q
52
+ switch_to_previous_view
53
+ end
54
+ end
55
+
56
+ def view(view_id)
57
+ views[view_id]
58
+ end
59
+
60
+ def current_view
61
+ @current_view ||= view(MAIN_VIEW)
62
+ end
63
+
64
+ def current_view=(v)
65
+ @current_view = v
66
+ end
67
+
68
+ def view_history
69
+ @view_history ||= []
70
+ end
71
+
72
+ def switch_to_next_view(v)
73
+ view_history << current_view
74
+ self.current_view = v
75
+ switch_to(current_view)
76
+ end
77
+
78
+ def switch_to_previous_view
79
+ previous_view = view_history.shift
80
+ unless previous_view
81
+ exit
82
+ else
83
+ current_view.virtual_close
84
+ switch_to(previous_view)
85
+ end
86
+ end
87
+
88
+ def switch_to(v)
89
+ self.current_view = v
90
+ v.setpos(v.cursor.y, v.cursor.x)
91
+ v.refresh
92
+ end
93
+ end
94
+ end
data/tiqbi.gemspec CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Tiqbi::VERSION
17
17
 
18
18
  gem.add_dependency "slop"
19
+ gem.add_dependency "activesupport"
19
20
  gem.add_dependency "qiita", ">= 0.0.3"
20
21
  gem.add_dependency "sanitize"
21
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiqbi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-19 00:00:00.000000000 Z
12
+ date: 2012-10-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: slop
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: activesupport
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: qiita
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -75,15 +91,16 @@ files:
75
91
  - bin/tiqbi
76
92
  - cache/.gitkeep
77
93
  - lib/tiqbi.rb
94
+ - lib/tiqbi/qiita.rb
78
95
  - lib/tiqbi/utils.rb
79
96
  - lib/tiqbi/version.rb
80
- - lib/tiqbi/view.rb
81
- - lib/tiqbi/window/base.rb
82
- - lib/tiqbi/window/collection.rb
83
- - lib/tiqbi/window/command_window.rb
84
- - lib/tiqbi/window/cursor.rb
85
- - lib/tiqbi/window/detail_window.rb
86
- - lib/tiqbi/window/main_window.rb
97
+ - lib/tiqbi/view/base.rb
98
+ - lib/tiqbi/view/collection.rb
99
+ - lib/tiqbi/view/command_view.rb
100
+ - lib/tiqbi/view/cursor.rb
101
+ - lib/tiqbi/view/detail_view.rb
102
+ - lib/tiqbi/view/main_view.rb
103
+ - lib/tiqbi/view_controller.rb
87
104
  - tiqbi.gemspec
88
105
  homepage: https://github.com/ToQoz/tiqbi
89
106
  licenses: []
data/lib/tiqbi/view.rb DELETED
@@ -1,93 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require 'tiqbi/window/main_window'
4
- require 'tiqbi/window/detail_window'
5
- require 'tiqbi/window/command_window'
6
-
7
- module Tiqbi
8
- class View
9
- MAIN_WINDOW = 1
10
- DETAIL_WINDOW = 2
11
- COMMAND_WINDOW = 3
12
-
13
- include Utils
14
- attr_accessor :windows
15
-
16
- def initialize(c_screen)
17
- # calc size
18
- scr_x = c_screen.maxx - c_screen.begx
19
- scr_y = c_screen.maxy - c_screen.begy
20
- main_h = scr_y / 2
21
- cmd_h = 1
22
- detail_h = main_h - cmd_h
23
- # initialize all windows
24
- @windows = {
25
- MAIN_WINDOW => Window::MainWindow.new(c_screen, main_h, scr_x, 0, 0),
26
- DETAIL_WINDOW => Window::DetailWindow.new(c_screen, detail_h, scr_x, main_h, 0),
27
- COMMAND_WINDOW => Window::CommandWindow.new(c_screen, cmd_h, scr_x, main_h + detail_h, 0)
28
- }
29
-
30
- items = Qiita.item("") rescue []
31
- @windows[MAIN_WINDOW].collection = items
32
- @windows[MAIN_WINDOW].print
33
- end
34
-
35
- def on_input(input)
36
- case input
37
- when ?j
38
- current_window.cursor_down
39
- when ?k
40
- current_window.cursor_up
41
- when 10
42
- if current_window == window(MAIN_WINDOW)
43
- index = current_window.cursor.y
44
- item = current_window.collection.at(index)
45
- return unless item
46
- item_detail = Qiita.item(item.uuid) rescue {}
47
- window(DETAIL_WINDOW).item_loaded item_detail
48
- switch_to_next_window window(DETAIL_WINDOW)
49
- end
50
- when ?q
51
- switch_to_previous_window
52
- end
53
- end
54
-
55
- def window(window_id)
56
- windows[window_id]
57
- end
58
-
59
- def current_window
60
- @current_window ||= window(MAIN_WINDOW)
61
- end
62
-
63
- def current_window=(win)
64
- @current_window = win
65
- end
66
-
67
- def window_history
68
- @window_history ||= []
69
- end
70
-
71
- def switch_to_next_window(win)
72
- window_history << current_window
73
- self.current_window = win
74
- switch_to(current_window)
75
- end
76
-
77
- def switch_to_previous_window
78
- previous_win = window_history.shift
79
- unless previous_win
80
- exit
81
- else
82
- current_window.virtual_close
83
- switch_to(previous_win)
84
- end
85
- end
86
-
87
- def switch_to(win)
88
- self.current_window = win
89
- win.setpos(win.cursor.y, win.cursor.x)
90
- win.refresh
91
- end
92
- end
93
- end