forked from OpenNeo/impress
Add more info to NC Mall section of Item Getting Guide
NC prices, some CSS, and also a new application-level helper that adds a feature I've long wanted and been working around for Turbo: the ability to specific that a stylesheet is specific to the current page, and should be unloaded when removed! I use this to write `sources.sass` without the usual `body.items-sources` scoping that we've historically used to control what pages a stylesheet applies to. (In the long past, this was because a lot of stylesheets were—and still are–routed through the `application.sass` stylesheet! But even for more recent standalone page stylesheets, I've done the scoping, to avoid issues with styles leaking beyond the page they're meant for when Turbo does a navigation.)
This commit is contained in:
parent
d3b3a3060c
commit
d8b577aab1
5 changed files with 43 additions and 1 deletions
14
app/assets/stylesheets/items/sources.sass
Normal file
14
app/assets/stylesheets/items/sources.sass
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
.nc-mall-items
|
||||||
|
list-style: none
|
||||||
|
display: flex
|
||||||
|
flex-wrap: wrap
|
||||||
|
gap: 1em
|
||||||
|
|
||||||
|
li
|
||||||
|
display: flex
|
||||||
|
flex-direction: column
|
||||||
|
align-items: center
|
||||||
|
width: auto
|
||||||
|
|
||||||
|
.add-to-cart
|
||||||
|
font-size: 85%
|
|
@ -175,6 +175,14 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Includes a stylesheet designed for this specific page of the app, which
|
||||||
|
# should be removed when navigating to another page. We use Turbo's
|
||||||
|
# `data-turbo-track="dynamic"` option to do this.
|
||||||
|
def page_stylesheet_link_tag(src, options={})
|
||||||
|
options = {data: {"turbo-track": "dynamic"}}.deep_merge(options)
|
||||||
|
stylesheet_link_tag src, options
|
||||||
|
end
|
||||||
|
|
||||||
def secondary_nav(&block)
|
def secondary_nav(&block)
|
||||||
content_for :before_flashes,
|
content_for :before_flashes,
|
||||||
content_tag(:nav, :id => 'secondary-nav', &block)
|
content_tag(:nav, :id => 'secondary-nav', &block)
|
||||||
|
|
|
@ -175,6 +175,10 @@ class Item < ApplicationRecord
|
||||||
@wanted || false
|
@wanted || false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def current_nc_price
|
||||||
|
nc_mall_record.current_price
|
||||||
|
end
|
||||||
|
|
||||||
def restricted_zones(options={})
|
def restricted_zones(options={})
|
||||||
options[:scope] ||= Zone.all
|
options[:scope] ||= Zone.all
|
||||||
options[:scope].find(restricted_zone_ids)
|
options[:scope].find(restricted_zone_ids)
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
class NCMallRecord < ApplicationRecord
|
class NCMallRecord < ApplicationRecord
|
||||||
belongs_to :item
|
belongs_to :item
|
||||||
|
|
||||||
|
def current_price
|
||||||
|
discount_price || price
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,16 @@
|
||||||
|
|
||||||
- if @nc_mall_items.present?
|
- if @nc_mall_items.present?
|
||||||
%h2 NC Mall items
|
%h2 NC Mall items
|
||||||
= render @nc_mall_items
|
%p
|
||||||
|
These items are available in the NC Mall right now! You can buy them
|
||||||
|
with #{link_to "Neocash", "https://secure.nc.neopets.com/get-neocash"},
|
||||||
|
a special currency you can purchase directly from Neopets or redeem via gift cards.
|
||||||
|
%ul.nc-mall-items
|
||||||
|
- @nc_mall_items.each do |item|
|
||||||
|
%li
|
||||||
|
= render item
|
||||||
|
%button.add-to-cart{onclick: "alert('Todo!')"}
|
||||||
|
Buy (#{item.current_nc_price} NC)
|
||||||
|
|
||||||
- if @np_items.present?
|
- if @np_items.present?
|
||||||
%h2 Neopoint items
|
%h2 Neopoint items
|
||||||
|
@ -16,3 +25,6 @@
|
||||||
- if @other_nc_items.present?
|
- if @other_nc_items.present?
|
||||||
%h2 Other NC items
|
%h2 Other NC items
|
||||||
= render @other_nc_items
|
= render @other_nc_items
|
||||||
|
|
||||||
|
- content_for :stylesheets do
|
||||||
|
= page_stylesheet_link_tag "items/sources"
|
||||||
|
|
Loading…
Reference in a new issue