feedcellar-web 0.1.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/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # feedcellar-web
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/feedcellar-web.svg)](http://badge.fury.io/rb/feedcellar-web)
4
+
5
+ Feedcellar::Web is a Web interface for [Feedcellar][] that is full-text searchable RSS feed reader and data store.
6
+
7
+ [Feedcellar]:http://myokoym.net/feedcellar/
8
+
9
+ ## Demo
10
+
11
+ http://myokoym.net/feedcellar-demo/
12
+
13
+ ## Installation
14
+
15
+ $ gem install feedcellar-web
16
+
17
+ ## Usage
18
+
19
+ ### Show help
20
+
21
+ $ feedcellar-web
22
+
23
+ ### Show feeds in a web browser
24
+
25
+ $ feedcellar-web start [--silent]
26
+
27
+ Or
28
+
29
+ $ rackup
30
+
31
+ #### Enable cache (using Racknga)
32
+
33
+ $ FEEDCELLAR_ENABLE_CACHE=true rackup
34
+
35
+ ## License
36
+
37
+ Copyright (c) 2013-2015 Masafumi Yokoyama `<myokoym@gmail.com>`
38
+
39
+ LGPLv2.1 or later.
40
+
41
+ See 'LICENSE.txt' or 'http://www.gnu.org/licenses/lgpl-2.1' for details.
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ # Rakefile
2
+ #
3
+ # Copyright (C) 2013 Masafumi Yokoyama <myokoym@gmail.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ require "bundler/gem_tasks"
20
+
21
+ desc "Run test"
22
+ task :test do
23
+ Bundler::GemHelper.install_tasks
24
+ ruby("test/run-test.rb")
25
+ end
26
+
27
+ task :default => :test
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # executable: feedcellar-web
4
+ #
5
+ # Copyright (C) 2013-2015 Masafumi Yokoyama <myokoym@gmail.com>
6
+ #
7
+ # This library is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation; either
10
+ # version 2.1 of the License, or (at your option) any later version.
11
+ #
12
+ # This library is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ # Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public
18
+ # License along with this library; if not, write to the Free Software
19
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+
21
+ require "feedcellar/web/command"
22
+
23
+ Feedcellar::Web::Command.start
data/config.ru ADDED
@@ -0,0 +1,34 @@
1
+ # config.ru
2
+ #
3
+ # Copyright (C) 2014-2015 Masafumi Yokoyama <myokoym@gmail.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ base_dir = File.expand_path(File.dirname(__FILE__))
20
+ lib_dir = File.join(base_dir, "lib")
21
+ $LOAD_PATH.unshift(lib_dir)
22
+ require "feedcellar/web/app"
23
+
24
+ ENV["FEEDCELLAR_HOME"] ||= File.join(base_dir, ".feedcellar")
25
+
26
+ if ENV["FEEDCELLAR_ENABLE_CACHE"]
27
+ require "racknga"
28
+ require "racknga/middleware/cache"
29
+
30
+ cache_database_path = File.join(base_dir, "var", "cache", "db")
31
+ use Racknga::Middleware::Cache, :database_path => cache_database_path
32
+ end
33
+
34
+ run Feedcellar::Web::App
@@ -0,0 +1,54 @@
1
+ # coding: utf-8
2
+ #
3
+ # feedcellar-web.gemspec
4
+ #
5
+ # Copyright (C) 2013-2015 Masafumi Yokoyama <myokoym@gmail.com>
6
+ #
7
+ # This library is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation; either
10
+ # version 2.1 of the License, or (at your option) any later version.
11
+ #
12
+ # This library is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ # Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public
18
+ # License along with this library; if not, write to the Free Software
19
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+
21
+ lib = File.expand_path('../lib', __FILE__)
22
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
23
+ require 'feedcellar/web/version'
24
+
25
+ Gem::Specification.new do |spec|
26
+ spec.name = "feedcellar-web"
27
+ spec.version = Feedcellar::Web::VERSION
28
+ spec.authors = ["Masafumi Yokoyama"]
29
+ spec.email = ["myokoym@gmail.com"]
30
+ spec.description = %q{Feedcellar::Web is a Web interfface for Feedcellar that is a full-text searchable RSS feed reader and data store by Groonga (via Rroonga) with Ruby.}
31
+ spec.summary = %q{Web interface for Feedcellar}
32
+ spec.homepage = "http://myokoym.net/feedcellar/"
33
+ spec.license = "LGPLv2.1 or later"
34
+
35
+ spec.files = `git ls-files`.split($/)
36
+ spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
37
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
38
+ spec.require_paths = ["lib"]
39
+
40
+ spec.add_runtime_dependency("feedcellar", ">= 0.5.0")
41
+ spec.add_runtime_dependency("thor")
42
+ spec.add_runtime_dependency("sinatra")
43
+ spec.add_runtime_dependency("padrino-helpers")
44
+ spec.add_runtime_dependency("kaminari")
45
+ spec.add_runtime_dependency("haml")
46
+ spec.add_runtime_dependency("launchy")
47
+ spec.add_runtime_dependency("racknga")
48
+
49
+ spec.add_development_dependency("test-unit")
50
+ spec.add_development_dependency("test-unit-notify")
51
+ spec.add_development_dependency("test-unit-rr")
52
+ spec.add_development_dependency("bundler")
53
+ spec.add_development_dependency("rake")
54
+ end
@@ -0,0 +1,94 @@
1
+ # class Feedcellar::Web::App
2
+ #
3
+ # Copyright (C) 2014-2015 Masafumi Yokoyama <myokoym@gmail.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ require "feedcellar"
20
+ require "sinatra/base"
21
+ require "haml"
22
+ require "padrino-helpers"
23
+ require "kaminari/sinatra"
24
+
25
+ module Feedcellar
26
+ module Web
27
+ class App < Sinatra::Base
28
+ helpers Kaminari::Helpers::SinatraHelpers
29
+
30
+ get "/" do
31
+ haml :index
32
+ end
33
+
34
+ get "/search" do
35
+ if params[:word]
36
+ words = params[:word].split(" ")
37
+ else
38
+ words = []
39
+ end
40
+ options ||= {}
41
+ options[:resource_id] = params[:resource_id] if params[:resource_id]
42
+ @feeds = search(words, options)
43
+ if @feeds
44
+ page = params[:page]
45
+ n_per_page = options[:n_per_page] || 50
46
+ @paginated_feeds = pagenate_feeds(@feeds, page, n_per_page)
47
+ end
48
+ haml :index
49
+ end
50
+
51
+ get "/registers.opml" do
52
+ content_type :xml
53
+ opml = nil
54
+ GroongaDatabase.new.open(Command.new.database_dir) do |database|
55
+ opml = Opml.build(database.resources.records)
56
+ end
57
+ opml
58
+ end
59
+
60
+ helpers do
61
+ def search(words, options={})
62
+ database = GroongaDatabase.new
63
+ database.open(Command.new.database_dir)
64
+ GroongaSearcher.search(database, words, options)
65
+ end
66
+
67
+ def pagenate_feeds(feeds, page, n_per_page)
68
+ Kaminari.paginate_array(feeds.to_a).page(page).per(n_per_page)
69
+ end
70
+
71
+ def grouping(table)
72
+ key = "resource"
73
+ table.group(key).sort_by {|item| item.n_sub_records }.reverse
74
+ end
75
+
76
+ def drilled_url(resource)
77
+ url("/search?resource_id=#{resource._id}&word=#{params[:word]}")
78
+ end
79
+
80
+ def drilled_label(resource)
81
+ "#{resource.title} (#{resource.n_sub_records})"
82
+ end
83
+
84
+ def groonga_version
85
+ Groonga::VERSION[0..2].join(".")
86
+ end
87
+
88
+ def rroonga_version
89
+ Groonga::BINDINGS_VERSION.join(".")
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,51 @@
1
+ # class Feedcellar::Web::Command
2
+ #
3
+ # Copyright (C) 2013-2015 Masafumi Yokoyama <myokoym@gmail.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ require "thor"
20
+ require "launchy"
21
+ require "feedcellar/web"
22
+
23
+ module Feedcellar
24
+ module Web
25
+ class Command < Thor
26
+ map "-v" => :version
27
+
28
+ attr_reader :database_dir
29
+
30
+ def initialize(*args)
31
+ super
32
+ default_base_dir = File.join(File.expand_path("~"), ".feedcellar")
33
+ @base_dir = ENV["FEEDCELLAR_HOME"] || default_base_dir
34
+ @database_dir = File.join(@base_dir, "db")
35
+ end
36
+
37
+ desc "version", "Show version number."
38
+ def version
39
+ puts Feedcellar::Web::VERSION
40
+ end
41
+
42
+ desc "start", "Start web server."
43
+ option :silent, :type => :boolean, :desc => "Don't open in browser"
44
+ def start
45
+ web_server_thread = Thread.new { Feedcellar::Web::App.run! }
46
+ Launchy.open("http://localhost:4567") unless options[:silent]
47
+ web_server_thread.join
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,23 @@
1
+ # constant Feedcellar::Web::VERSION
2
+ #
3
+ # Copyright (C) 2015 Masafumi Yokoyama <myokoym@gmail.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ module Feedcellar
20
+ module Web
21
+ VERSION = "0.1.0"
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ %h1 feedcellar-web
2
+ %p= "Powered by Groonga #{groonga_version} and Rroonga #{rroonga_version}."
3
+ %form{:action => url("/search", false, true), :method => :get}
4
+ %input{:type => "textarea", :name => "word", :size => 20, :value => params[:word]}
5
+ %input{:type => "submit", :value => "Search"}
6
+ - if @feeds
7
+ %p
8
+ - grouping(@feeds).each do |resource|
9
+ = link_to(drilled_label(resource), drilled_url(resource))
10
+ = paginate(@paginated_feeds)
11
+ %ul
12
+ - @paginated_feeds.each do |feed|
13
+ %li
14
+ %p
15
+ = link_to("#{feed.title} - #{feed.resource.title}", feed.link)
16
+ = paginate(@paginated_feeds)
@@ -0,0 +1,6 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %title feedcellar-web
5
+ %body
6
+ = yield
@@ -0,0 +1,20 @@
1
+ # modlue Feedcellar::Web
2
+ #
3
+ # Copyright (C) 2013-2015 Masafumi Yokoyama <myokoym@gmail.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ require "feedcellar/web/version"
20
+ require "feedcellar/web/app"
data/public/.gitkeep ADDED
File without changes
data/test/run-test.rb ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # run-test.rb
4
+ #
5
+ # Copyright (C) 2013-2015 Masafumi Yokoyama <myokoym@gmail.com>
6
+ #
7
+ # This library is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation; either
10
+ # version 2.1 of the License, or (at your option) any later version.
11
+ #
12
+ # This library is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ # Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public
18
+ # License along with this library; if not, write to the Free Software
19
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+
21
+ require "test-unit"
22
+ require "test/unit/notify"
23
+ require "test/unit/rr"
24
+
25
+ base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
26
+ lib_dir = File.join(base_dir, "lib")
27
+ test_dir = File.join(base_dir, "test")
28
+ $LOAD_PATH.unshift(lib_dir)
29
+ $LOAD_PATH.unshift(test_dir)
30
+
31
+ exit Test::Unit::AutoRunner.run(true, test_dir)
data/test/test-app.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "rack/test"
2
+
3
+ class AppTest < Test::Unit::TestCase
4
+ include Rack::Test::Methods
5
+
6
+ def app
7
+ @app ||= Rack::Builder.parse_file("config.ru").first
8
+ end
9
+
10
+ def test_index
11
+ get "/"
12
+ assert_true(last_response.ok?)
13
+ end
14
+ end
@@ -0,0 +1,48 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # class CommandTest
4
+ #
5
+ # Copyright (C) 2015 Masafumi Yokoyama <myokoym@gmail.com>
6
+ #
7
+ # This library is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation; either
10
+ # version 2.1 of the License, or (at your option) any later version.
11
+ #
12
+ # This library is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ # Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public
18
+ # License along with this library; if not, write to the Free Software
19
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+
21
+ require "fileutils"
22
+ require "stringio"
23
+ require "feedcellar/web/version"
24
+ require "feedcellar/web/command"
25
+
26
+ class CommandTest < Test::Unit::TestCase
27
+ def setup
28
+ @tmpdir = File.join(File.dirname(__FILE__), "tmp")
29
+ FileUtils.rm_rf(@tmpdir)
30
+ FileUtils.mkdir_p(@tmpdir)
31
+ ENV["FEEDCELLAR_HOME"] = @tmpdir
32
+ @command = Feedcellar::Web::Command.new
33
+ @database_dir = @command.database_dir
34
+ end
35
+
36
+ def teardown
37
+ FileUtils.rm_rf(@tmpdir)
38
+ end
39
+
40
+ def test_version
41
+ s = ""
42
+ io = StringIO.new(s)
43
+ $stdout = io
44
+ @command.version
45
+ assert_equal("#{Feedcellar::Web::VERSION}\n", s)
46
+ $stdout = STDOUT
47
+ end
48
+ end