diff --git a/app/assets/stylesheets/mobile.css.scss b/app/assets/stylesheets/mobile.css.scss
new file mode 100644
index 000000000..2f362cdd4
--- /dev/null
+++ b/app/assets/stylesheets/mobile.css.scss
@@ -0,0 +1,62 @@
+/*
+ *= require "./common/010_reset"
+ *= require "./common/020_base"
+ *= require "./common/030_links"
+*/
+
+body {
+ padding: 5px;
+}
+
+/* paginator */
+div.paginator {
+ font-size: 20pt;
+ font-weight: bold;
+ text-align: center;
+
+ li {
+ display: inline;
+
+ a, span {
+ border: 1px solid #EAEAEA;
+ padding: 3px 18px;
+ margin: 0 3px;
+ display: inline-block;
+ }
+ }
+}
+
+/* posts/index */
+article.post-preview {
+ margin: 15px 0;
+ width: 150px;
+ text-align: center;
+ vertical-align: middle;
+ display: inline-block;
+ a {
+ width: 150px;
+ display: block;
+ margin: 0 auto;
+ }
+ img {
+ margin: 0 auto;
+ }
+}
+
+/* posts/show */
+img#image {
+ margin-top: 5px;
+}
+
+div#tags {
+ margin-top: 10px;
+
+ li {
+ margin: 10px 0;
+ }
+
+ a.search-tag {
+ font-size: 24pt;
+ font-weight: bold;
+ }
+}
diff --git a/app/controllers/mobile/posts_controller.rb b/app/controllers/mobile/posts_controller.rb
new file mode 100644
index 000000000..bd733d451
--- /dev/null
+++ b/app/controllers/mobile/posts_controller.rb
@@ -0,0 +1,18 @@
+class Mobile::PostsController < ApplicationController
+ layout "mobile"
+ before_filter :set_mobile_mode
+
+ def index
+ @post_set = PostSets::Post.new(params[:tags], params[:page], CurrentUser.user.per_page, false)
+ @posts = @post_set.posts
+ end
+
+ def show
+ @post = Post.find(params[:id])
+ end
+
+private
+ def set_mobile_mode
+ CurrentUser.mobile_mode = true
+ end
+end
diff --git a/app/logical/current_user.rb b/app/logical/current_user.rb
index c68630175..d40fe4ee5 100644
--- a/app/logical/current_user.rb
+++ b/app/logical/current_user.rb
@@ -11,6 +11,7 @@ class CurrentUser
ensure
self.user = old_user
self.ip_addr = old_ip_addr
+ self.mobile_mode = false
end
end
@@ -30,6 +31,14 @@ class CurrentUser
Thread.current[:current_ip_addr]
end
+ def self.mobile_mode=(mode)
+ Thread.current[:mobile_mode] = mode
+ end
+
+ def self.mobile_mode?
+ Thread.current[:mobile_mode]
+ end
+
def self.id
if user.nil?
nil
diff --git a/app/models/post.rb b/app/models/post.rb
index 4f1799e59..0402d741e 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -118,6 +118,10 @@ class Post < ActiveRecord::Base
end
def file_url_for(user)
+ if CurrentUser.mobile_mode?
+ return large_file_url
+ end
+
case user.default_image_size
when "large"
if image_width > Danbooru.config.large_image_width
@@ -132,6 +136,10 @@ class Post < ActiveRecord::Base
end
def file_path_for(user)
+ if CurrentUser.mobile_mode?
+ return large_file_path
+ end
+
case user.default_image_size
when "large"
if image_width > Danbooru.config.large_image_width
@@ -155,6 +163,14 @@ class Post < ActiveRecord::Base
end
module ImageMethods
+ def device_scale
+ if large_image_width > 320
+ 320.0 / (large_image_width + 10)
+ else
+ 1.0
+ end
+ end
+
def twitter_card_supported?
image_width.to_i >= 280 && image_height.to_i >= 150
end
@@ -181,6 +197,10 @@ class Post < ActiveRecord::Base
end
def image_width_for(user)
+ if CurrentUser.mobile_mode?
+ return large_image_width
+ end
+
case user.default_image_size
when "large"
large_image_width
@@ -191,6 +211,10 @@ class Post < ActiveRecord::Base
end
def image_height_for(user)
+ if CurrentUser.mobile_mode?
+ return large_image_height
+ end
+
case user.default_image_size
when "large"
large_image_height
diff --git a/app/presenters/post_set_presenters/base.rb b/app/presenters/post_set_presenters/base.rb
index c06c1d69c..402844d12 100644
--- a/app/presenters/post_set_presenters/base.rb
+++ b/app/presenters/post_set_presenters/base.rb
@@ -4,7 +4,7 @@ module PostSetPresenters
raise NotImplementedError
end
- def post_previews_html(template)
+ def post_previews_html(template, options = {})
html = ""
if posts.empty?
@@ -12,7 +12,7 @@ module PostSetPresenters
end
posts.each do |post|
- html << PostPresenter.preview(post, :tags => @post_set.tag_string, :raw => @post_set.raw)
+ html << PostPresenter.preview(post, options.merge(:tags => @post_set.tag_string, :raw => @post_set.raw))
html << "\n"
end
diff --git a/app/presenters/post_set_presenters/post.rb b/app/presenters/post_set_presenters/post.rb
index 290f77c43..2fea5d315 100644
--- a/app/presenters/post_set_presenters/post.rb
+++ b/app/presenters/post_set_presenters/post.rb
@@ -48,8 +48,8 @@ module PostSetPresenters
RelatedTagCalculator.calculate_from_post_set_to_array(post_set).map(&:first)
end
- def tag_list_html(template)
- tag_set_presenter.tag_list_html(template)
+ def tag_list_html(template, options = {})
+ tag_set_presenter.tag_list_html(template, options)
end
end
end
diff --git a/app/views/layouts/mobile.html.erb b/app/views/layouts/mobile.html.erb
new file mode 100644
index 000000000..768a5485c
--- /dev/null
+++ b/app/views/layouts/mobile.html.erb
@@ -0,0 +1,20 @@
+
+
+
+ <%= yield :page_title %>
+
+ <%= csrf_meta_tag %>
+ <%= stylesheet_link_tag "mobile", :media => "screen" %>
+ <%= javascript_include_tag "mobile" %>
+ <%= Danbooru.config.custom_html_header_content %>
+ <%= yield :html_header %>
+
+
+
+ <%= link_to Danbooru.config.app_name, "/" %>
+
+
+ <%= yield :layout %>
+
+
+
diff --git a/app/views/mobile/posts/index.html.erb b/app/views/mobile/posts/index.html.erb
new file mode 100644
index 000000000..8f3cee7c2
--- /dev/null
+++ b/app/views/mobile/posts/index.html.erb
@@ -0,0 +1,16 @@
+<%= form_tag(m_posts_path, :method => "get") do %>
+ <%= text_field_tag("tags", params[:tags], :size => 30) %>
+ <%= submit_tag "Go", :name => nil %>
+<% end %>
+
+<%= @post_set.presenter.post_previews_html(self, :path_prefix => "/m/posts") %>
+
+<%= numbered_paginator(@post_set.posts) %>
+
+
+ <%= @post_set.presenter.tag_list_html(self, :name_only => true, :path_prefix => "/m/posts") %>
+
+
+<%= content_for(:html_header) do %>
+
+<% end %>
diff --git a/app/views/mobile/posts/show.html.erb b/app/views/mobile/posts/show.html.erb
new file mode 100644
index 000000000..5654899a2
--- /dev/null
+++ b/app/views/mobile/posts/show.html.erb
@@ -0,0 +1,14 @@
+<%= form_tag(m_posts_path, :method => "get") do %>
+ <%= text_field_tag("tags", params[:tags], :size => 20) %>
+ <%= submit_tag "Go", :name => nil %>
+<% end %>
+
+<%= @post.presenter.image_html(self) %>
+
+
+ <%= @post.presenter.tag_list_html(self, :name_only => true, :path_prefix => "/m/posts") %>
+
+
+<%= content_for(:html_header) do %>
+
+<% end %>
diff --git a/app/views/posts/partials/index/_related.html.erb b/app/views/posts/partials/index/_related.html.erb
index 9ec07248c..92fa24811 100644
--- a/app/views/posts/partials/index/_related.html.erb
+++ b/app/views/posts/partials/index/_related.html.erb
@@ -10,5 +10,7 @@
<% end %>
<%= link_to "Random post", random_posts_path(:tags => params[:tags]) %>
+
+ <%= link_to "Mobile version", m_posts_path(:tags => params[:tags]) %>
diff --git a/app/views/posts/partials/show/_options.html.erb b/app/views/posts/partials/show/_options.html.erb
index 66e5f9479..1462982df 100644
--- a/app/views/posts/partials/show/_options.html.erb
+++ b/app/views/posts/partials/show/_options.html.erb
@@ -49,6 +49,8 @@
<% if CurrentUser.is_admin? %>
<%= link_to "Expunge", expunge_moderator_post_post_path(:post_id => post.id), :remote => true, :method => :post, :id => "expunge", :confirm => "This will permanently delete this post (meaning the file will be deleted). Are you sure you want to delete this post?" %>
<% end %>
+
+ <%= link_to "Mobile version", m_post_path(post) %>
<% end %>
<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index 2cc61b2be..c514b7320 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -3,6 +3,9 @@ Danbooru::Application.routes.draw do
resources :users, :only => [:edit, :update]
resource :alias_and_implication_import, :only => [:new, :create]
end
+ namespace :mobile do
+ resources :posts, :only => [:index, :show]
+ end
namespace :moderator do
resource :dashboard, :only => [:show]
resources :ip_addrs, :only => [:index] do
@@ -257,6 +260,8 @@ Danbooru::Application.routes.draw do
resources :wpages, :controller => "wiki_pages"
resources :ftopics, :controller => "forum_topics"
resources :fposts, :controller => "forum_posts"
+ match "/m/posts", :controller => "mobile/posts", :action => "index"
+ match "/m/posts/:id", :controller => "mobile/posts", :action => "show"
# legacy aliases
match "/artist" => redirect {|params, req| "/artists?page=#{req.params[:page]}&search[name]=#{CGI::escape(req.params[:name].to_s)}"}
diff --git a/db/structure.sql b/db/structure.sql
index 79f4b5af6..38465995c 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -508,6 +508,78 @@ CREATE SEQUENCE amazon_backups_id_seq
ALTER SEQUENCE amazon_backups_id_seq OWNED BY amazon_backups.id;
+--
+-- Name: artist_commentaries; Type: TABLE; Schema: public; Owner: -; Tablespace:
+--
+
+CREATE TABLE artist_commentaries (
+ id integer NOT NULL,
+ post_id integer NOT NULL,
+ original_title text,
+ original_description text,
+ translated_title text,
+ translated_description text,
+ created_at timestamp without time zone NOT NULL,
+ updated_at timestamp without time zone NOT NULL
+);
+
+
+--
+-- Name: artist_commentaries_id_seq; Type: SEQUENCE; Schema: public; Owner: -
+--
+
+CREATE SEQUENCE artist_commentaries_id_seq
+ START WITH 1
+ INCREMENT BY 1
+ NO MAXVALUE
+ NO MINVALUE
+ CACHE 1;
+
+
+--
+-- Name: artist_commentaries_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
+--
+
+ALTER SEQUENCE artist_commentaries_id_seq OWNED BY artist_commentaries.id;
+
+
+--
+-- Name: artist_commentary_versions; Type: TABLE; Schema: public; Owner: -; Tablespace:
+--
+
+CREATE TABLE artist_commentary_versions (
+ id integer NOT NULL,
+ post_id integer NOT NULL,
+ updater_id integer NOT NULL,
+ updater_ip_addr inet NOT NULL,
+ original_title text,
+ original_description text,
+ translated_title text,
+ translated_description text,
+ created_at timestamp without time zone NOT NULL,
+ updated_at timestamp without time zone NOT NULL
+);
+
+
+--
+-- Name: artist_commentary_versions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
+--
+
+CREATE SEQUENCE artist_commentary_versions_id_seq
+ START WITH 1
+ INCREMENT BY 1
+ NO MAXVALUE
+ NO MINVALUE
+ CACHE 1;
+
+
+--
+-- Name: artist_commentary_versions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
+--
+
+ALTER SEQUENCE artist_commentary_versions_id_seq OWNED BY artist_commentary_versions.id;
+
+
--
-- Name: artist_urls; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
@@ -2814,6 +2886,20 @@ ALTER TABLE ONLY advertisements ALTER COLUMN id SET DEFAULT nextval('advertiseme
ALTER TABLE ONLY amazon_backups ALTER COLUMN id SET DEFAULT nextval('amazon_backups_id_seq'::regclass);
+--
+-- Name: id; Type: DEFAULT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY artist_commentaries ALTER COLUMN id SET DEFAULT nextval('artist_commentaries_id_seq'::regclass);
+
+
+--
+-- Name: id; Type: DEFAULT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY artist_commentary_versions ALTER COLUMN id SET DEFAULT nextval('artist_commentary_versions_id_seq'::regclass);
+
+
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
@@ -3797,6 +3883,22 @@ ALTER TABLE ONLY amazon_backups
ADD CONSTRAINT amazon_backups_pkey PRIMARY KEY (id);
+--
+-- Name: artist_commentaries_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
+--
+
+ALTER TABLE ONLY artist_commentaries
+ ADD CONSTRAINT artist_commentaries_pkey PRIMARY KEY (id);
+
+
+--
+-- Name: artist_commentary_versions_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
+--
+
+ALTER TABLE ONLY artist_commentary_versions
+ ADD CONSTRAINT artist_commentary_versions_pkey PRIMARY KEY (id);
+
+
--
-- Name: artist_urls_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
@@ -4114,6 +4216,27 @@ CREATE INDEX index_advertisement_hits_on_created_at ON advertisement_hits USING
CREATE INDEX index_advertisements_on_ad_type ON advertisements USING btree (ad_type);
+--
+-- Name: index_artist_commentaries_on_post_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
+--
+
+CREATE UNIQUE INDEX index_artist_commentaries_on_post_id ON artist_commentaries USING btree (post_id);
+
+
+--
+-- Name: index_artist_commentary_versions_on_post_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
+--
+
+CREATE INDEX index_artist_commentary_versions_on_post_id ON artist_commentary_versions USING btree (post_id);
+
+
+--
+-- Name: index_artist_commentary_versions_on_updater_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
+--
+
+CREATE INDEX index_artist_commentary_versions_on_updater_id ON artist_commentary_versions USING btree (updater_id);
+
+
--
-- Name: index_artist_urls_on_artist_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
@@ -6431,4 +6554,8 @@ INSERT INTO schema_migrations (version) VALUES ('20130712162600');
INSERT INTO schema_migrations (version) VALUES ('20130914175431');
-INSERT INTO schema_migrations (version) VALUES ('20131006193238');
\ No newline at end of file
+INSERT INTO schema_migrations (version) VALUES ('20131006193238');
+
+INSERT INTO schema_migrations (version) VALUES ('20131117150705');
+
+INSERT INTO schema_migrations (version) VALUES ('20131118153503');
\ No newline at end of file