Major cleanup. Moved many texts to I18n. Added the most basic user page.

master
Zequez 2015-07-16 22:41:04 -03:00
parent 20ab9c9490
commit a9517e21dc
29 changed files with 233 additions and 159 deletions

View File

@ -29,6 +29,7 @@
@import "shared/boxes"
@import "shared/query_highlight"
@import "shared/formtastic"
@import "shared/helpers"
@import "partials/header"
@import "partials/search_bar"

View File

@ -99,32 +99,19 @@ $mods-list-size: 12-$filter-size
&:last-child
margin-bottom: 0
// .mod-thumbnail .asset-thumbnail
// border-radius: 5px 0px 0px 5px
// &:first-child
// border-radius: $border-radius $border-radius 0px 0px
// .mod-thumbnail .asset-thumbnail
// border-radius: $border-radius 0px 0px 0px
// &:last-child
// border-radius: 0px 0px $border-radius $border-radius
// .mod-thumbnail .asset-thumbnail
// border-radius: 0px 0px 0px $border-radius
//-- Thumbnail --//
&-thumbnail
@extend %pretty-border
+span(2 of no-gutter $mods-list-size)
overflow: hidden
&-link
a
//@extend %thumbnail-hover
display: block
width: 100%
overflow: hidden
&-img
img
display: block
width: 100%

View File

@ -10,7 +10,7 @@
&-image
+span(4 of 12 no-gutter)
@extend %pretty-border
&-img
img
max-width: 100%
display: block

View File

@ -0,0 +1,3 @@
.translation_missing
box-shadow: 0px 0px 3px red
background-color: rgba(red,0.2)

View File

@ -1,5 +1,7 @@
class UsersController < ApplicationController
def show
@user = User.find params[:id]
@user = User.where(slug: params[:id]).first
@mods = @user ? @user.mods : Mod.where(author_name: params[:id])
@name = @user ? @user.name : params[:id]
end
end

View File

@ -14,15 +14,39 @@ module ApplicationHelper
### Misc helpers:
####################
def missing_image_thumbnail
root_path + 'images/thumb/missing.png'
def link_wrap_if(link_condition, *options, &block)
if link_condition
link_to link_condition, *options, &block
else
capture &block
end
end
def missing_image_medium
root_path + 'images/medium/missing.png'
def missing_img(size, img_tag_options = {})
img_tag_options = img_tag_options.reverse_merge({
src: missing_img_url(size),
title: t('helpers.no_image_available')
})
tag :img, img_tag_options
end
def if_na(value, result = nil, na = 'N/A', &block)
def mod_img(mod, size)
tag :img,
src: mod_img_url(mod, size),
class: 'mod-img',
title: (t('helpers.no_image_available') if !mod.imgur)
end
def mod_img_url(mod, size)
mod.imgur(size).presence || missing_img_url(size)
end
def missing_img_url(size)
root_path + "images/missing_#{size}.png"
end
def if_na(value, result = nil, na = nil, &block)
na = na || t('helpers.not_available')
use_na = (!!value == value) ? !value : value.blank?
if use_na
na
@ -35,15 +59,6 @@ module ApplicationHelper
end
end
# def if_na(condition, result = nil, &block)
# condition = condition.blank? if !!condition == condition # check if boolean
# if !result and block_given?
# condition ? capture(&block) : 'N/A'
# else
# condition ? result : 'N/A'
# end
# end
def body_controller_classes
controller_path = params[:controller].split('/')
controller_path.each_index.map{|i| controller_path[0..i].join('-')} << params[:action]
@ -55,7 +70,7 @@ module ApplicationHelper
def title(page_title = nil, options = {suffix: true})
@title ||= ''
@title = page_title.to_s + @title unless page_title.nil?
@title = @title + t('title.suffix') if options[:suffix]
@title = @title + t('layouts.application.title.suffix') if options[:suffix]
@title = @title.strip
content_for :title, @title[0].upcase + @title[1..-1]
end
@ -102,7 +117,7 @@ module ApplicationHelper
def version_filter_option(version, &block)
content_tag :option,
"For Factorio v#{version.number}",
t('.for_game_version', version: version.number),
value: version_filter_url(version),
selected: version_filter_selected_state(version)
end

View File

@ -68,4 +68,32 @@ module ModsHelper
link_to "#{file.attachment_file_name} (#{number_to_human_size(file.attachment_file_size)})", file.attachment.url
end
end
def admin_edit_link(mod)
link_to t('helpers.admin_edit'), edit_mod_path(mod) if can? :manage, Mod
end
def index_title
if current_page? '/'
title t('.title.root')
else
title_append t('.title.version', version: @game_version.number) if @game_version
title_append t('.title.mods')
title_append t('.title.category', category: @category.name) if @category
title_append t(".title.sort.#{@sort}") if @sort
title
end
end
# - if current_page? '/'
# - title t 'title.root'
# - else
# - if @game_version
# - title_append t('title.mods.index.version', version: @game_version.number)
# - title_append t('title.mods.index.mods')
# - if @category
# - title_append t('title.mods.index.category', category: @category.name)
# - if @sort
# - title_append t(@sort, scope: 'title.mods.index.sort')
# - title
end

View File

@ -181,6 +181,18 @@ class Mod < ActiveRecord::Base
"http://imgur.com/#{imgur}"
end
def imgur(size = false)
return nil if self[:imgur].blank?
return self[:imgur] unless size
case size
when :normal then imgur_normal
when :thumbnail then imgur_thumbnail
when :large_thumbnail then imgur_large_thumbnail
else
super
end
end
def imgur_normal
# Yeah, it could be something else than JPG, but Imgur doesn't care, they're cool
"http://i.imgur.com/#{imgur}.jpg"

View File

@ -18,10 +18,6 @@ class ModFile < ActiveRecord::Base
end
def available_url
if download_url.blank?
attachment.blank? ? '' : attachment.url
else
download_url
end
download_url.presence || (attachment.present? ? attachment.url : '')
end
end

View File

@ -7,20 +7,20 @@
- if user_signed_in?
= link_to current_user.name, user_path(current_user)
|
= link_to 'Logout', destroy_user_session_path
= link_to t('.sign_out'), destroy_user_session_path
- else
= link_to 'Login', new_user_session_path
= link_to t('.sign_in'), new_user_session_path
|
= link_to 'Register', new_user_registration_path
= link_to t('.sign_up'), new_user_registration_path
.instructions
.instructions-button
How do I
%a{href: how_to_make_static_url}
%strong make
\/
= t('.how_to.start')
%a{href: how_to_install_static_url}
%strong install
%strong= t('.how_to.install')
\/
%a{href: how_to_make_static_url}
%strong= t('.how_to.make')
\/
%a{href: how_to_submit_static_url}
%strong submit
mods?
%strong= t('.how_to.submit')
= t('.how_to.end')

View File

@ -2,17 +2,13 @@
%ul.sorters
%li.sorter><
= sort_link :most_recent do
= icon 'history', 'Recently updated'
= icon 'history', t('.most_recent')
%li.sorter><
= sort_link :alpha do
= icon 'sort-alpha-asc', 'Alphabetically'
= icon 'sort-alpha-asc', t('.alpha')
%li.sorter<>
= sort_link :popular do
= icon 'star-o', 'Most Popular'
-# %li.sorter<>
-# = sort_link :forum_comments do
-# = icon 'comments-o'
-# Most comments
= icon 'star-o', t('.popular')
.text-filter
= search_form do
%input.input.input-text.input-text-search#search-input{type: 'text', placeholder: 'Search', name: 'q', value: params[:q], maxlength: 30}
%input.input.input-text.input-text-search#search-input{type: 'text', placeholder: t('.search'), name: 'q', value: params[:q], maxlength: 30}

View File

@ -2,7 +2,7 @@
.mod-link.btn.btn-download
%a{href: mod.latest_version.files.first.available_url}
= icon 'download'
Download
= t('.download')
%ul.btn-download-versions
- mod.latest_versions_with_files(2) do |version, file|
%li
@ -15,4 +15,4 @@
-#= "v#{file.mod_version.game_versions_string}"
- if mod.versions.size > 2
%li
= link_to 'More versions...', mod_path(mod, anchor: 'download')
= link_to t('.more_versions'), mod_path(mod, anchor: 'download')

View File

@ -2,19 +2,17 @@
.filter-bar-item
.version-filter
%select.input.version-filter-input
%option{value: version_filter_url(nil)} Any Factorio version
%option{value: version_filter_url(nil)}= t('.any_game_version')
- @game_versions.each do |version|
= version_filter_option version
-#%option{value: version_filter_url(version)}
-# For Factorio
-# = "v#{version.number}"
.filter-bar-item
%h2.categories-filter-title Categories
%h2.categories-filter-title= t('.categories')
%ul.categories-filter
%li.category-filter
= category_link nil do
%i.fa.fa-cog
All (#{all_categories_mods_count})
= t('.all')
(#{all_categories_mods_count})
- @categories.each do |category|
%li.category-filter
= category_link category do

View File

@ -1,28 +1,28 @@
%ul.mod-data
%li
.data-name Factorio version
.data-name= t('.game_version')
.data-value= if_na(@mod.game_versions_string)
%li
.data-name Author
.data-name= t('.author')
.data-value= if_na(@mod.author, nil, @mod.author_name) { link_to @mod.author_name, @mod.author }
%li{class: ('wide' if @mod.has_versions?)}
.data-name First version
.data-name= t('.first_version')
.data-value= if_na(@mod.has_versions?) { mod_release(@mod.versions.first) }
%li{class: ('wide' if @mod.has_versions?)}
.data-name Last version
.data-name= t('.last_version')
.data-value= if_na(@mod.has_versions?) { mod_release(@mod.versions.last) }
%li.wide
.data-name Source
.data-name= t('.source')
.data-value= if_na(@mod.github) { link_to @mod.github_url, @mod.github_url }
%li.wide
.data-name Forum post URL
.data-name= t('.forum_post_url')
.data-value
= if_na(@mod.forum_url) do
- if @mod.forum_post
= forum_post_stats_link
- else
= link_to "On the Factorio forums", @mod.forum_url
= link_to t('.forum_post_url_title'), @mod.forum_url
- if @mod.forum_subforum_url.present?
%li.wide
.data-name Subforum URL
.data-name= t('.subforum_url')
.data-value= link_to @mod.forum_subforum_url

View File

@ -1,14 +1,4 @@
- if current_page? '/'
- title t 'title.root'
- else
- if @game_version
- title_append t('title.mods.index.version', version: @game_version.number)
- title_append t('title.mods.index.mods')
- if @category
- title_append t('title.mods.index.category', category: @category.name)
- if @sort
- title_append t(@sort, scope: 'title.mods.index.sort')
- title
- index_title
= render partial: 'filter_bar'
@ -16,22 +6,18 @@
= render partial: 'mods_filters_list'
- if @query
.info-box
Huh? Trying to search? Search is pretty basic and plain for now. I apologize the inconvenience.
.info-box= t('.search_notice')
.mods-index
- @mods.each do |mod|
.mod
.mod-thumbnail<
%a.mod-thumbnail-link{href: mod_url(mod)}
- if mod.imgur.present?
%img.mod-thumbnail-img{src: mod.imgur_thumbnail }
- else
%img.mod-thumbnail-img.mod-thumbnail-img-missing{src: missing_image_thumbnail, title: 'No image available'}
= mod_img(mod, :thumbnail)
.mod-info-container
%h2.mod-title
= link_to mod.name, mod, class: 'highlight-query'
= link_to '[Edit]', edit_mod_path(mod) if can? :manage, Mod
= admin_edit_link(mod)
.mod-subtitle
- mod.categories.each do |category|
= category_tag_link category
@ -59,7 +45,7 @@
- if mod.author
= link_to mod.author_name, mod.author
- else
= mod.author_name
= link_to mod.author_name, user_url(mod.author_name)
= icon 'user'
-# %a.mod-link.mod-official-site{href: '#'}
-# Official mod site

View File

@ -1,10 +1,10 @@
- title @mod.new_record? ? t('title.mods.new') : t('title.mods.edit', name: @mod.name)
- title @mod.new_record? ? t('.title') : t('.title_edit', name: @mod.name)
.mods-edit
- if @mod.new_record?
%h2 Create new mod
%h2= t('.new')
- else
%h2
Edit
= t('.edit')
= link_to @mod.name, @mod
= semantic_form_for @mod do |f|
= f.inputs do
@ -23,7 +23,7 @@
= f.semantic_fields_for :versions do |ff|
= render 'version_fields', f: ff
.nested-form-links.mod-versions-links
= link_to_add_association 'Add version', f, :versions
= link_to_add_association t('.add_version'), f, :versions
// Nested mod versions
// Nested mod files
// Nested mod files

View File

@ -1,13 +1,9 @@
- title t 'title.mods.show', name: @mod.name
- title t '.title', name: @mod.name
.mods-show
.mod
.mod-image
- if @mod.imgur.present?
%a.mod-image-link{href: @mod.imgur_normal, target: '_blank'}
%img.mod-image-img{src: @mod.imgur_large_thumbnail}
- else
%img.mod-image-img.mod-image-img-missing{src: missing_image_medium, title: 'No image available'}
= link_wrap_if(@mod.imgur(:normal)) { mod_img(@mod, :large_thumbnail) }
.mod-info-container
%h2.mod-title= @mod.name
.mod-subtitle
@ -21,33 +17,32 @@
= render partial: 'download_button', locals: { mod: @mod }
.mod-downloads#downloads
- if @mod.has_files?
%h3 All releases
%h3= t('.all_releases')
%table.mod-downloads-table
%thead
%tr
%th Mod version
%th Factorio version
%th File download
%th Release date
%th= t('.downloads_table.mod_version')
%th= t('.downloads_table.game_version')
%th= t('.downloads_table.file_version')
%th= t('.downloads_table.release_date')
%tbody
- @mod.latest_versions_with_files do |version, file|
%tr
%td= "#{version.number} #{file.name}"
%td= version.game_versions_string
%td= link_to_file_url_with_name(file)
//%td= pretty_date version.released_at.to_s(:rfc822)
%td= mod_date version.released_at
- else
%h3 This mod doesn't have anything to download :(
%h3= t('.no_downloads')
- if @mod.subforum_url.present?
.mod-forum
%h3 Mod subforum
%h3= t('.mod_subforum')
.mod-forum-iframe-cover
%iframe.mod-forum-iframe{src: @mod.subforum_url}
- elsif @mod.forum_url.present?
.mod-forum
%h3
Mod forum post
= t('.mod_forum_post')
- if @mod.forum_post
= forum_post_stats_link
.mod-forum-iframe-cover

View File

@ -1,4 +1,4 @@
- title t 'title.static.how_to_install'
- title t '.title'
:markdown
## How to install mods

View File

@ -1,4 +1,4 @@
- title t 'title.static.how_to_make'
- title t '.title'
:markdown
## How to create mods

View File

@ -1,4 +1,4 @@
- title t 'title.static.how_to_submit'
- title t '.title'
:markdown
## How to submit mods

View File

@ -1,5 +1,9 @@
- title "#{@user.name } profile"
- title "#{@name} profile"
%h2 #{@user.name}'s profile
%h2 Mods by #{@name}
There is nothing here yet.
Haven't gotten to properly do this page yet, so here is a quick list of mods by this author:
%ul
- @mods.each do |mod|
%li= link_to mod.name, mod

View File

@ -35,5 +35,5 @@ Rails.application.configure do
config.active_support.deprecation = :stderr
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
config.action_view.raise_on_missing_translations = true
end

View File

@ -1,46 +1,8 @@
# Files in the config/locales directory are used for internationalization
# and are automatically loaded by Rails. If you want to use locales other
# than English, add the necessary files in this directory.
#
# To use the locales, use `I18n.t`:
#
# I18n.t 'hello'
#
# In views, this is aliased to just `t`:
#
# <%= t('hello') %>
#
# To use a different locale, set it with `I18n.locale`:
#
# I18n.locale = :es
#
# This would use the information in config/locales/es.yml.
#
# To learn more, please read the Rails Internationalization guide
# available at http://guides.rubyonrails.org/i18n.html.
en:
title:
suffix: " - Factorio Mods "
root: Latest Factorio mods
mods:
new: Create new mod
edit: Edit %{name}
index:
version: " for Factorio v%{version} "
mods: ' mods '
category: " %{category} "
sort:
most_recent: ' recently updated '
alpha: ' '
downloads: ' most downloaded '
popular: ' most popular'
forum_comments: ' most forum comments '
show: '%{name}'
static:
how_to_install: How to install mods on Factorio
how_to_make: How to create mods for Factorio
how_to_submit: How to submit mods to FactorioMods
helpers:
no_image_available: No image available
not_available: N/A
admin_edit: '[Edit]'
error_pages:
'401':

View File

@ -0,0 +1,21 @@
en:
layouts:
application:
title:
suffix: " - Factorio Mods "
header:
sign_out: Logout
sign_in: Login
sign_up: Register
how_to:
start: How do I
make: make
install: install
submit: submit
end: mods?
search_bar:
search: Search
most_recent: Recently updated
alpha: Alphabetically
popular: Most popular
forum_comments: Most comments

View File

@ -0,0 +1,59 @@
en:
mods:
new:
title: Create new mod
title_edit: Edit %{name} # We use the same view
edit: Edit
new: Create new mod
add_version: Add version
show:
title: "%{name}"
no_downloads: This mod doesn't have anything to download :(
downloads_table:
game_version: Factorio version
mod_version: Mod version
file_version: File version
release_date: Release date
all_releases: All releases
mod_subforum: Mod subforum
mod_forum_post: Mod forum post
index:
title:
root: Latest Factorio mods
version: " for Factorio v%{version} "
mods: ' mods '
category: " %{category} "
sort:
most_recent: ' recently updated '
alpha: ' '
downloads: ' most downloaded '
popular: ' most popular'
forum_comments: ' most forum comments '
show: '%{name}'
search_notice: |
Huh? Trying to search? Search is pretty
basic and plain for now. I apologize the inconvenience.
admin_edit: Edit
post_on_the_factorio_forum: Post on the official Factorio forums
mod_data_table:
game_version: Factorio version
author: Author
first_version: First version
last_version: Last version
source: Source
forum_post_url: Forum post URL
forum_post_url_title: On the Factorio forums
subforum_url: Subforum URL
download_button:
more_versions: More versions...
download: Download
filter_bar:
any_game_version: Any Factorio version
categories: Categories
all: All
for_game_version: For Factorio v%{version}

View File

@ -0,0 +1,8 @@
en:
static:
how_to_install:
title: How to install mods on Factorio
how_to_make:
title: How to create mods for Factorio
how_to_submit:
title: How to submit mods to FactorioMods

View File

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

View File

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

@ -19,6 +19,7 @@ RSpec.describe ModsHelper, :type => :helper do
expect(link_to_file_url_with_name(file))
.to eq "<a href=\"#{file.attachment.url}\">#{file.attachment_file_name} (#{number_to_human_size(file.attachment_file_size)})</a>"
end
it 'should return a link to the attachment URL if the download URL is an empty string' do
file = build :mod_file, download_url: ''
expect(link_to_file_url_with_name(file))