pixhibitee 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c7ce2729192a74d0cd911c2656d258ddba81f98e
4
+ data.tar.gz: 5de3a145cb28c8e140fe613a3eb8838c354de0dc
5
+ SHA512:
6
+ metadata.gz: b304f318a7abfdf53c535e4d92c82473c784f8b988264433e34cf9980debd5ad7875b7e9980d566089b5a61e260800286d7ba0503707872a9a1ba0121adee8c3
7
+ data.tar.gz: f11bd8d2d5ed687933eca6ad00c10803e596812042af07ea126ad0bfb7813408fb7884f32e54eb63f2502505e1c17efe757acff635d810c94e2d026a3de586ae
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
17
+ /var/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org/"
2
+
3
+ # Specify your gem's dependencies in pixhibitee.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2015 Masafumi Yokoyama <myokoym@gmail.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Pixhibitee
2
+
3
+ An image viewer as a web application for local files.
4
+
5
+ You can open your pictures exhibition easily on web.
6
+
7
+ ## Installation
8
+
9
+ $ gem install pixhibitee
10
+
11
+ ## Usage
12
+
13
+ $ cd /path/to/directory
14
+ $ pixhibitee [OPTIONS]
15
+
16
+ ### OPTIONS
17
+
18
+ * `--silent`
19
+ * Don't open in browser
20
+ * `--public`
21
+ * Publish to network
22
+ * `--port=PORT`
23
+ * Set port number
24
+
25
+ ## License
26
+
27
+ MIT License.
28
+
29
+ See LICENSE.txt for details.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc "Run test"
4
+ task :test do
5
+ Bundler::GemHelper.install_tasks
6
+ ruby("test/run-test.rb")
7
+ end
8
+
9
+ task :default => :test
data/bin/pixhibitee ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "pixhibitee/command"
4
+
5
+ Pixhibitee::Command.start
data/config.ru ADDED
@@ -0,0 +1,6 @@
1
+ base_dir = File.expand_path(File.dirname(__FILE__))
2
+ lib_dir = File.join(base_dir, "lib")
3
+ $LOAD_PATH.unshift(lib_dir)
4
+ require "pixhibitee/app"
5
+
6
+ run Pixhibitee::App
@@ -0,0 +1,53 @@
1
+ require "sinatra/base"
2
+ require "tilt/haml"
3
+ require "mime/types"
4
+
5
+ module Pixhibitee
6
+ class App < Sinatra::Base
7
+ set :public_folder, Proc.new { Dir.pwd }
8
+
9
+ get "/*" do
10
+ base_path = params["splat"][0]
11
+ @paths = collect_image_files(base_path)
12
+ @sub_directories = collect_sub_directories(base_path)
13
+ haml :index
14
+ end
15
+
16
+ helpers do
17
+ def collect_image_files(base_path)
18
+ collect_files(base_path) do |path|
19
+ displayable?(path)
20
+ end
21
+ end
22
+
23
+ def collect_sub_directories(base_path)
24
+ collect_files(base_path) do |path|
25
+ File.directory?(path)
26
+ end
27
+ end
28
+
29
+ def collect_files(base_path)
30
+ expanded_path = File.expand_path(base_path)
31
+ paths = Dir.glob("#{expanded_path}/*").select do |path|
32
+ yield(path)
33
+ end
34
+ paths.map do |path|
35
+ format_link(path, expanded_path, base_path)
36
+ end
37
+ end
38
+
39
+ def displayable?(path)
40
+ mime_type = MIME::Types.type_for(path)[0]
41
+ return false unless mime_type
42
+ return false if File.size(path) > 1_000_000
43
+ mime_type.media_type == "image"
44
+ end
45
+
46
+ def format_link(path, expanded_path, base_path)
47
+ src = "#{path.sub(expanded_path, base_path)}"
48
+ src = "/#{src}" unless src.start_with?("/")
49
+ src
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,49 @@
1
+ require "thor"
2
+ require "launchy"
3
+ require "pixhibitee"
4
+
5
+ module Pixhibitee
6
+ class Command < Thor
7
+ default_command :start
8
+
9
+ map "-v" => :version
10
+
11
+ desc "version", "Show version number."
12
+ def version
13
+ puts Pixhibitee::VERSION
14
+ end
15
+
16
+ desc "start", "Start web server."
17
+ option :silent, :type => :boolean, :desc => "Don't open in browser"
18
+ option :public, :type => :boolean, :desc => "Publish to network"
19
+ option :port, :type => :string, :desc => "Set port number"
20
+ def start
21
+ web_server_thread = Thread.new do
22
+ if options[:public]
23
+ start_public_server
24
+ else
25
+ start_private_server
26
+ end
27
+ end
28
+ Launchy.open("http://localhost:#{port}") unless options[:silent]
29
+ web_server_thread.join
30
+ end
31
+
32
+ private
33
+ def port
34
+ options[:port] || "4567"
35
+ end
36
+
37
+ def start_private_server
38
+ Pixhibitee::App.run!
39
+ end
40
+
41
+ def start_public_server
42
+ Rack::Server.start({
43
+ :config => File.join(File.dirname(__FILE__), "../../config.ru"),
44
+ :Host => "0.0.0.0",
45
+ :Port => port,
46
+ })
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module Pixhibitee
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,79 @@
1
+ -# -*- coding: utf-8 -*-
2
+ !!!
3
+ %html
4
+ %head
5
+ %meta(http-equiv="content-type" content="text/html; charset=utf-8")
6
+ %meta(http-equiv="content-style-type" content="text/css")
7
+ %meta(http-equiv="content-script-type" content="text/javascript")
8
+ %link(rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/jquery.slick/1.5.6/slick.css" media="all")
9
+ %link(rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/jquery.slick/1.5.6/slick-theme.css" media="all")
10
+
11
+ %title Pixhibitee
12
+ %body
13
+ %div.slider-nav
14
+ - @paths.each do |path|
15
+ %div
16
+ %img{src: path, width: 120, height: 80}
17
+
18
+ %div.slider-for{align: "center"}
19
+ - @paths.each do |path|
20
+ %div
21
+ %img{src: path}
22
+
23
+ %p
24
+ - @sub_directories.each do |dir|
25
+ [
26
+ %a{href: dir}= dir
27
+ ]
28
+
29
+ Powered by
30
+ %a{href: "http://www.ruby-lang.org/"} Ruby
31
+ ,
32
+ %a{href: "http://www.sinatrarb.com/intro.html"} Sinatra
33
+ ,
34
+ %a{href: "http://haml.info/"} Haml
35
+ ,
36
+ %a{href: "http://kenwheeler.github.io/slick/"} slick
37
+ and
38
+ %a{href: "https://github.com/myokoym/pixhibitee"} Pixhibitee
39
+
40
+ %script(src="//code.jquery.com/jquery-1.11.3.min.js")
41
+ %script(src="//cdn.jsdelivr.net/jquery.slick/1.5.6/slick.min.js")
42
+
43
+ :javascript
44
+ (function() {
45
+ $(document).ready(function() {
46
+ $('.slider-for').slick({
47
+ slidesToShow: 1,
48
+ slidesToScroll: 1,
49
+ arrows: false,
50
+ fade: true,
51
+ autoplay: true,
52
+ autoplaySpeed: 10000,
53
+ asNavFor: '.slider-nav'
54
+ });
55
+ var responsives = new Array(20);
56
+ for (var i = 0; i < 20; i++) {
57
+ var slides = 20 - i;
58
+ responsives[i] = {
59
+ breakpoint: (140 * slides),
60
+ settings: {
61
+ slidesPerRow: slides,
62
+ slidesToShow: slides
63
+ }
64
+ };
65
+ }
66
+ $('.slider-nav').slick({
67
+ adaptiveHeight: true,
68
+ asNavFor: '.slider-for',
69
+ arrows: true,
70
+ dots: true,
71
+ centerMode: true,
72
+ focusOnSelect: true,
73
+ slidesPerRow: 8,
74
+ slidesToShow: 8,
75
+ slidesToScroll: 1,
76
+ responsive: responsives
77
+ });
78
+ });
79
+ }())
data/lib/pixhibitee.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "pixhibitee/version"
2
+ require "pixhibitee/app"
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pixhibitee/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pixhibitee"
8
+ spec.version = Pixhibitee::VERSION
9
+ spec.authors = ["Masafumi Yokoyama"]
10
+ spec.email = ["myokoym@gmail.com"]
11
+
12
+ spec.description = %q{An image viewer as a web application for local files. You can open your pictures exhibition easily on web.}
13
+ spec.summary = %q{Image viewer as a web application}
14
+ spec.homepage = "https://github.com/myokoym/pixhibitee"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency("sinatra")
23
+ spec.add_runtime_dependency("haml")
24
+ spec.add_runtime_dependency("mime-types")
25
+ spec.add_runtime_dependency("thor")
26
+
27
+ spec.add_development_dependency("test-unit")
28
+ spec.add_development_dependency("bundler")
29
+ spec.add_development_dependency("rake")
30
+ end
data/test/run-test.rb ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "test-unit"
4
+
5
+ base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
6
+ lib_dir = File.join(base_dir, "lib")
7
+ test_dir = File.join(base_dir, "test")
8
+ $LOAD_PATH.unshift(lib_dir)
9
+ $LOAD_PATH.unshift(test_dir)
10
+
11
+ 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,19 @@
1
+ require "fileutils"
2
+ require "stringio"
3
+ require "pixhibitee/version"
4
+ require "pixhibitee/command"
5
+
6
+ class CommandTest < Test::Unit::TestCase
7
+ def setup
8
+ @command = Pixhibitee::Command.new
9
+ end
10
+
11
+ def test_version
12
+ s = ""
13
+ io = StringIO.new(s)
14
+ $stdout = io
15
+ @command.version
16
+ assert_equal("#{Pixhibitee::VERSION}\n", s)
17
+ $stdout = STDOUT
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pixhibitee
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Masafumi Yokoyama
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: haml
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mime-types
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: test-unit
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: An image viewer as a web application for local files. You can open your
112
+ pictures exhibition easily on web.
113
+ email:
114
+ - myokoym@gmail.com
115
+ executables:
116
+ - pixhibitee
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".gitignore"
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/pixhibitee
126
+ - config.ru
127
+ - lib/pixhibitee.rb
128
+ - lib/pixhibitee/app.rb
129
+ - lib/pixhibitee/command.rb
130
+ - lib/pixhibitee/version.rb
131
+ - lib/pixhibitee/views/index.haml
132
+ - pixhibitee.gemspec
133
+ - test/run-test.rb
134
+ - test/test-app.rb
135
+ - test/test-command.rb
136
+ homepage: https://github.com/myokoym/pixhibitee
137
+ licenses:
138
+ - MIT
139
+ metadata: {}
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.2.2
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: Image viewer as a web application
160
+ test_files:
161
+ - test/run-test.rb
162
+ - test/test-app.rb
163
+ - test/test-command.rb
164
+ has_rdoc: