diff --git a/app/assets/stylesheets/application.css.sass b/app/assets/stylesheets/application.css.sass index 021e8b5..2c26938 100644 --- a/app/assets/stylesheets/application.css.sass +++ b/app/assets/stylesheets/application.css.sass @@ -29,6 +29,7 @@ @import "shared/boxes" @import "shared/query_highlight" @import "shared/formtastic" +@import "shared/helpers" @import "partials/header" @import "partials/search_bar" diff --git a/app/assets/stylesheets/mods/index.css.sass b/app/assets/stylesheets/mods/index.css.sass index 3b97051..17f18d7 100644 --- a/app/assets/stylesheets/mods/index.css.sass +++ b/app/assets/stylesheets/mods/index.css.sass @@ -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% diff --git a/app/assets/stylesheets/mods/show.css.sass b/app/assets/stylesheets/mods/show.css.sass index f9edf0c..218145c 100644 --- a/app/assets/stylesheets/mods/show.css.sass +++ b/app/assets/stylesheets/mods/show.css.sass @@ -10,7 +10,7 @@ &-image +span(4 of 12 no-gutter) @extend %pretty-border - &-img + img max-width: 100% display: block diff --git a/app/assets/stylesheets/shared/helpers.css.sass b/app/assets/stylesheets/shared/helpers.css.sass new file mode 100644 index 0000000..c9850d0 --- /dev/null +++ b/app/assets/stylesheets/shared/helpers.css.sass @@ -0,0 +1,3 @@ +.translation_missing + box-shadow: 0px 0px 3px red + background-color: rgba(red,0.2) \ No newline at end of file diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 00ecd9e..87438c0 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3ec72e7..ce381e4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/helpers/mods_helper.rb b/app/helpers/mods_helper.rb index 4cebee9..3034244 100644 --- a/app/helpers/mods_helper.rb +++ b/app/helpers/mods_helper.rb @@ -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 diff --git a/app/models/mod.rb b/app/models/mod.rb index 251a1b3..4e4c907 100644 --- a/app/models/mod.rb +++ b/app/models/mod.rb @@ -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" diff --git a/app/models/mod_file.rb b/app/models/mod_file.rb index 1c640d5..950d0ce 100644 --- a/app/models/mod_file.rb +++ b/app/models/mod_file.rb @@ -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 diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml index 820057e..e22db0a 100644 --- a/app/views/layouts/_header.html.haml +++ b/app/views/layouts/_header.html.haml @@ -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? \ No newline at end of file + %strong= t('.how_to.submit') + = t('.how_to.end') \ No newline at end of file diff --git a/app/views/layouts/_search_bar.html.haml b/app/views/layouts/_search_bar.html.haml index 2a39e28..710011d 100644 --- a/app/views/layouts/_search_bar.html.haml +++ b/app/views/layouts/_search_bar.html.haml @@ -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} \ No newline at end of file + %input.input.input-text.input-text-search#search-input{type: 'text', placeholder: t('.search'), name: 'q', value: params[:q], maxlength: 30} \ No newline at end of file diff --git a/app/views/mods/_download_button.html.haml b/app/views/mods/_download_button.html.haml index ed2faf5..f3b533e 100644 --- a/app/views/mods/_download_button.html.haml +++ b/app/views/mods/_download_button.html.haml @@ -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') \ No newline at end of file + = link_to t('.more_versions'), mod_path(mod, anchor: 'download') \ No newline at end of file diff --git a/app/views/mods/_filter_bar.html.haml b/app/views/mods/_filter_bar.html.haml index c2e78f8..e9ef79b 100644 --- a/app/views/mods/_filter_bar.html.haml +++ b/app/views/mods/_filter_bar.html.haml @@ -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 diff --git a/app/views/mods/_mod_data_table.html.haml b/app/views/mods/_mod_data_table.html.haml index 34d908c..83a161a 100644 --- a/app/views/mods/_mod_data_table.html.haml +++ b/app/views/mods/_mod_data_table.html.haml @@ -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 \ No newline at end of file diff --git a/app/views/mods/index.html.haml b/app/views/mods/index.html.haml index dae9cd9..7b51b78 100644 --- a/app/views/mods/index.html.haml +++ b/app/views/mods/index.html.haml @@ -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 diff --git a/app/views/mods/new.html.haml b/app/views/mods/new.html.haml index b52f11f..296f39b 100644 --- a/app/views/mods/new.html.haml +++ b/app/views/mods/new.html.haml @@ -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 diff --git a/app/views/mods/show.html.haml b/app/views/mods/show.html.haml index f24836f..3e6636d 100644 --- a/app/views/mods/show.html.haml +++ b/app/views/mods/show.html.haml @@ -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 diff --git a/app/views/static/how_to_install.html.haml b/app/views/static/how_to_install.html.haml index b7f467d..0851839 100644 --- a/app/views/static/how_to_install.html.haml +++ b/app/views/static/how_to_install.html.haml @@ -1,4 +1,4 @@ -- title t 'title.static.how_to_install' +- title t '.title' :markdown ## How to install mods diff --git a/app/views/static/how_to_make.html.haml b/app/views/static/how_to_make.html.haml index a89c75b..18b8858 100644 --- a/app/views/static/how_to_make.html.haml +++ b/app/views/static/how_to_make.html.haml @@ -1,4 +1,4 @@ -- title t 'title.static.how_to_make' +- title t '.title' :markdown ## How to create mods diff --git a/app/views/static/how_to_submit.html.haml b/app/views/static/how_to_submit.html.haml index be9e695..911a47f 100644 --- a/app/views/static/how_to_submit.html.haml +++ b/app/views/static/how_to_submit.html.haml @@ -1,4 +1,4 @@ -- title t 'title.static.how_to_submit' +- title t '.title' :markdown ## How to submit mods diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 9254b31..aafa686 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -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. \ No newline at end of file +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 diff --git a/config/environments/test.rb b/config/environments/test.rb index 82ca386..632a483 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index a34da96..93957ca 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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': diff --git a/config/locales/layouts.en.yml b/config/locales/layouts.en.yml new file mode 100644 index 0000000..e180b5d --- /dev/null +++ b/config/locales/layouts.en.yml @@ -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 \ No newline at end of file diff --git a/config/locales/mods.en.yml b/config/locales/mods.en.yml new file mode 100644 index 0000000..e8dda0c --- /dev/null +++ b/config/locales/mods.en.yml @@ -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} \ No newline at end of file diff --git a/config/locales/static.en.yml b/config/locales/static.en.yml new file mode 100644 index 0000000..539406c --- /dev/null +++ b/config/locales/static.en.yml @@ -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 \ No newline at end of file diff --git a/public/images/medium/missing.png b/public/images/missing_large_thumbnail.png similarity index 100% rename from public/images/medium/missing.png rename to public/images/missing_large_thumbnail.png diff --git a/public/images/thumb/missing.png b/public/images/missing_thumbnail.png similarity index 100% rename from public/images/thumb/missing.png rename to public/images/missing_thumbnail.png diff --git a/spec/helpers/mods_helper_spec.rb b/spec/helpers/mods_helper_spec.rb index 5dde106..271bc3d 100644 --- a/spec/helpers/mods_helper_spec.rb +++ b/spec/helpers/mods_helper_spec.rb @@ -19,6 +19,7 @@ RSpec.describe ModsHelper, :type => :helper do expect(link_to_file_url_with_name(file)) .to eq "#{file.attachment_file_name} (#{number_to_human_size(file.attachment_file_size)})" 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))