Skip to content

Commit ce6dda8

Browse files
committed
Add worldbuilding prompts page
1 parent 5a14e17 commit ce6dda8

File tree

7 files changed

+71
-1
lines changed

7 files changed

+71
-1
lines changed

app/controllers/content_controller.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,13 @@ def content_symbol
205205

206206
def successful_response(url, notice)
207207
respond_to do |format|
208-
format.html { redirect_to url, notice: notice }
208+
format.html {
209+
if params.key?(:override) && params[:override].key?(:redirect_path)
210+
redirect_to params[:override][:redirect_path], notice: notice
211+
else
212+
redirect_to url, notice: notice
213+
end
214+
}
209215
format.json { render json: @content || {}, status: :success, notice: notice }
210216
end
211217
end

app/controllers/main_controller.rb

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ def dashboard
1919
ask_question
2020
end
2121

22+
def prompts
23+
return redirect_to new_user_session_path unless user_signed_in?
24+
25+
ask_question
26+
end
27+
2228
def recent_content
2329
recent_content = current_user.content.values.flatten.compact
2430

app/models/user.rb

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ def referrer
2727
after_create :initialize_stripe_customer, unless: -> { Rails.env == 'test' }
2828
after_create :initialize_referral_code
2929

30+
def createable_content_types
31+
[Universe, Character, Location, Item, Creature, Race, Religion, Group, Magic, Language, Scene].select do |c|
32+
can_create? c
33+
end
34+
end
35+
3036
# as_json creates a hash structure, which you then pass to ActiveSupport::json.encode to actually encode the object as a JSON string.
3137
# This is different from to_json, which converts it straight to an escaped JSON string,
3238
# which is undesireable in a case like this, when we want to modify it

app/views/cards/serendipitous/_content_question.html.erb

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ if question.present? &&
1919
<div id="tristan-answer">
2020
<%= form_for content do |f| %>
2121

22+
<% if defined?(redirect_path) %>
23+
<%= hidden_field :override, :redirect_path, value: redirect_path %>
24+
<% end %>
25+
2226
<div class="input-field">
2327
<%= f.text_area question[:field], class: 'content-question-input materialize-textarea', placeholder: content.class.human_attribute_name(question[:field]) %>
2428
</div>

app/views/layouts/_navbar.html.erb

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
5252
</li>
5353
<li class="divider"></li>
5454
<% end %>
55+
<li>
56+
<%= link_to prompts_path do %>
57+
<i class="material-icons left">lightbulb_outline</i>
58+
Worldbuilding prompts
59+
<% end %>
60+
</li>
5561
<li>
5662
<%= link_to notebook_export_path do %>
5763
<i class="material-icons left">file_download</i>

app/views/main/prompts.html.erb

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<% if @question.present? && @question[:question].present? %>
2+
<div class="row">
3+
<div class="col m9 s12">
4+
<%= render partial: 'cards/serendipitous/content_question', locals: {
5+
question: @question,
6+
content: @content,
7+
redirect_path: prompts_path
8+
} %>
9+
</div>
10+
<div class="col m3 s12">
11+
<h5>Recently updated</h5>
12+
<%= render 'cards/user/recent_activity' %>
13+
</div>
14+
</div>
15+
<% else %>
16+
<%= image_tag 'tristan/small',
17+
class: 'tooltipped tristan right',
18+
data: {
19+
position: 'left',
20+
delay: '500',
21+
tooltip: "Hey, I'm Tristan! Once you've created some pages in your digital notebook, I'll come up with some writing prompts for you!"
22+
} %>
23+
<h5>Writing prompts</h5>
24+
<p>
25+
<% if current_user.content_count.zero? %>
26+
Once you've created some ideas in Notebook.ai, you can visit this page for writing prompts set in your world. They'll star your characters, in your locations, using your items, seeing your creatures, practicing your religions, and so on &mdash; so check back frequently for the latest prompts just for you!
27+
<% else %>
28+
It looks like your world is pretty fleshed out already, and you've answered all the questions I've come up with. Check back later and I might have a writing prompt for you, but I bet I can come up with some sooner if you
29+
<% new_content = (current_user.createable_content_types - [Universe]).sample %>
30+
<%= link_to new_polymorphic_path(new_content) do %>
31+
create
32+
<% if current_user.send(new_content.name.downcase.pluralize).any? %>
33+
another
34+
<% else %>
35+
<%= %w(a e i o u).include?(new_content.name.downcase[0]) ? 'an' : 'a' %>
36+
<% end %>
37+
<%= new_content.name.downcase %>!
38+
<% end %>
39+
<% end %>
40+
</p>
41+
<% end %>

config/routes.rb

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
get '/content', to: 'main#dashboard', as: :dashboard
3131
get '/content/recent', to: 'main#recent_content', as: :recent_content
3232
get '/submissions', to: 'main#comingsoon'
33+
get '/prompts', to: 'main#prompts', as: :prompts
3334

3435
# Billing
3536
scope '/billing' do

0 commit comments

Comments
 (0)