rutt 0.4.1 → 0.5.0

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.5.0
data/lib/rutt.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'rutt/helper'
1
2
  require 'rutt/db/config'
2
3
  require 'rutt/db/feed'
3
4
  require 'rutt/db/item'
data/lib/rutt/db/feed.rb CHANGED
@@ -32,12 +32,12 @@ module Rutt
32
32
  $db.execute("delete from feeds where id = ?", feed['id'])
33
33
  end
34
34
 
35
- def all(min_limit=0, max_limit=-1)
35
+ def all
36
36
  $db.execute(%{
37
37
  select f.*,
38
38
  (select count(*) from items iu where iu.feed_id = f.id) as num_items,
39
39
  (select count(*) from items ir where ir.read = 0 and ir.feed_id = f.id) as unread
40
- from feeds f where unread > 0 order by id desc limit #{min_limit},#{max_limit}
40
+ from feeds f where unread > 0 order by id desc
41
41
  })
42
42
  end
43
43
 
data/lib/rutt/db/item.rb CHANGED
@@ -22,8 +22,8 @@ module Rutt
22
22
  })
23
23
  end
24
24
 
25
- def all(feed, min_limit=0, max_limit=-1)
26
- $db.execute("select * from items where feed_id = ? order by published_at desc limit #{min_limit},#{max_limit}", feed['id'])
25
+ def all(feed)
26
+ $db.execute("select * from items where feed_id = ? order by published_at desc", feed['id'])
27
27
  end
28
28
 
29
29
  def mark_as_unread(item)
@@ -0,0 +1,10 @@
1
+ class Array
2
+ def / len
3
+ a = []
4
+ each_with_index do |x, i|
5
+ a << [] if i % len == 0
6
+ a.last << x
7
+ end
8
+ a
9
+ end
10
+ end
data/lib/rutt/screen.rb CHANGED
@@ -5,28 +5,24 @@ module Rutt
5
5
  @stdscr = stdscr
6
6
 
7
7
  @min_y = 1
8
- @max_y = @stdscr.getmaxy
9
-
10
- @min_limit = @min_y - 1
11
- @max_limit = @max_y - 5
8
+ @max_y = @stdscr.getmaxy - 5
12
9
 
13
10
  @cur_y = 1
14
11
  @cur_x = 0
12
+
13
+ @pages = []
14
+ @cur_page = 0
15
15
  end
16
16
 
17
17
  def incr_page
18
- @min_limit = @max_limit
19
- @max_limit += (@max_y - 5)
18
+ check_page = @cur_page + 1
19
+ check_page = @cur_page if check_page >= @pages.length
20
+ @cur_page = check_page
20
21
  end
21
22
 
22
23
  def decr_page
23
- @max_limit = @min_limit
24
- @min_limit -= (@max_y - 5)
25
-
26
- if @max_limit <= 0
27
- @min_limit = @min_y - 1
28
- @max_limit = @max_y - 5
29
- end
24
+ @cur_page -= 1
25
+ @cur_page = 0 if @cur_page < 0
30
26
  end
31
27
 
32
28
  def display_menu
@@ -2,14 +2,12 @@ module Rutt
2
2
  module Screen
3
3
  class Content < Base
4
4
  def initialize(stdscr, item)
5
+ super(stdscr)
6
+
5
7
  @item = item
6
8
  @menu = "i:back b:open in browser"
7
9
 
8
- super(stdscr)
9
- end
10
-
11
- def display_content
12
- # @content = `elinks -dump -dump-charset ascii -force-html #{@item['url']}`
10
+ # Get the content
13
11
  source = open(@item['url']).read
14
12
  content = Nokogiri::HTML(::Readability::Document.new(source).content).text
15
13
 
@@ -17,10 +15,27 @@ module Rutt
17
15
  s.gsub(/.{0,74}(?:\s|\Z)/){($& + 5.chr).gsub(/\n\005/,"\n")}.gsub(/((\n|^)[>|\s]*[>|].*?)\005/, "\\1").gsub(/\005/,"\n").split("\n") << "\n"
18
16
  end.flatten
19
17
 
20
- @stdscr.addstr(" #{@item['title']} (#{@item['url']})\n\n")
18
+ @pages = @content / @max_y
19
+ end
20
+
21
+ def display_content
22
+ # @content = `elinks -dump -dump-charset ascii -force-html #{@item['url']}`
21
23
 
22
- lines = @content[@min_limit..@max_limit]
23
- lines.each { |line| @stdscr.addstr(" #{line}\n") } if lines
24
+ @cur_y = @min_y
25
+ @stdscr.move(@cur_y, 0)
26
+ @stdscr.addstr(" #{@item['title']}\n")
27
+ @cur_y += 1
28
+ @stdscr.move(@cur_y, 0)
29
+ @stdscr.addstr(" #{@item['url']}\n")
30
+ @cur_y += 1
31
+
32
+ @pages[@cur_page].each do |line|
33
+ @stdscr.move(@cur_y, 0)
34
+ @stdscr.addstr(" #{line}\n")
35
+
36
+ @cur_y += 1
37
+ end
38
+ @cur_y = @min_y
24
39
 
25
40
  @stdscr.refresh
26
41
  end
@@ -2,16 +2,18 @@ module Rutt
2
2
  module Screen
3
3
  class Feed < Base
4
4
  def initialize(stdscr)
5
+ super(stdscr)
6
+
5
7
  @menu = "q:Quit d:delete r:refresh all"
6
8
 
7
- super(stdscr)
9
+ @feeds = DB::Feed::all
10
+ @pages = @feeds / @max_y
8
11
  end
9
12
 
10
13
  def display_feeds
11
14
  @cur_y = @min_y
12
15
 
13
- @feeds = DB::Feed::all(@min_limit, @max_limit)
14
- @feeds.each do |feed|
16
+ @pages[@cur_page].each do |feed|
15
17
  # next if feed['unread'] == 0 # This should be configurable: feed.showread
16
18
 
17
19
  @stdscr.move(@cur_y, 0)
@@ -60,9 +62,7 @@ module Rutt
60
62
  @stdscr.move(2, 0)
61
63
  @stdscr.addstr("Are you sure you want to delete #{feed['title']}? ")
62
64
  d = @stdscr.getch
63
- if d.chr =~ /y/i
64
- DB::Feed::delete(feed)
65
- end
65
+ DB::Feed::delete(feed) if d.chr =~ /y/i
66
66
  window
67
67
  move_pointer(cur_y, move_to=true)
68
68
  when /p/i
@@ -73,8 +73,8 @@ module Rutt
73
73
  window
74
74
  when / /
75
75
  cur_y = @cur_y
76
- @stdscr.addstr("#{@feeds[cur_y]}")
77
- item_screen = Item.new(@stdscr, @feeds[cur_y - 1])
76
+ @stdscr.addstr("#{@pages[@cur_page][cur_y]}")
77
+ item_screen = Item.new(@stdscr, @pages[@cur_page][cur_y - 1])
78
78
  item_screen.loop
79
79
 
80
80
  window
@@ -2,17 +2,19 @@ module Rutt
2
2
  module Screen
3
3
  class Item < Base
4
4
  def initialize(stdscr, feed)
5
+ super(stdscr)
6
+
5
7
  @feed = feed
6
8
  @menu = " i:quit r:refresh m:mark as read u:mark as unread a:mark all as read b:open in browser"
7
9
 
8
- super(stdscr)
10
+ @items = DB::Item::all(@feed)
11
+ @pages = @items / @max_y
9
12
  end
10
13
 
11
14
  def display_items
12
15
  @cur_y = @min_y
13
16
 
14
- @items = DB::Item::all(@feed, @min_limit, @max_limit)
15
- @items.each do |item|
17
+ @pages[@cur_page].each do |item|
16
18
  item_status = case item['read'].to_i
17
19
  when 0 then 'N'
18
20
  when 1 then ' '
data/rutt.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rutt}
8
- s.version = "0.4.1"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Abhi Yerra"]
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
32
32
  "lib/rutt/db/config.rb",
33
33
  "lib/rutt/db/feed.rb",
34
34
  "lib/rutt/db/item.rb",
35
+ "lib/rutt/helper.rb",
35
36
  "lib/rutt/opml.rb",
36
37
  "lib/rutt/screen.rb",
37
38
  "lib/rutt/screen/content.rb",
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rutt
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 1
10
- version: 0.4.1
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Abhi Yerra
@@ -215,6 +215,7 @@ files:
215
215
  - lib/rutt/db/config.rb
216
216
  - lib/rutt/db/feed.rb
217
217
  - lib/rutt/db/item.rb
218
+ - lib/rutt/helper.rb
218
219
  - lib/rutt/opml.rb
219
220
  - lib/rutt/screen.rb
220
221
  - lib/rutt/screen/content.rb