Skip to content

Commit

Permalink
Add worldbuilding prompts page
Browse files Browse the repository at this point in the history
  • Loading branch information
drusepth committed Apr 11, 2017
1 parent 5a14e17 commit ce6dda8
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/controllers/content_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,13 @@ def content_symbol

def successful_response(url, notice)
respond_to do |format|
format.html { redirect_to url, notice: notice }
format.html {
if params.key?(:override) && params[:override].key?(:redirect_path)
redirect_to params[:override][:redirect_path], notice: notice
else
redirect_to url, notice: notice
end
}
format.json { render json: @content || {}, status: :success, notice: notice }
end
end
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/main_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ def dashboard
ask_question
end

def prompts
return redirect_to new_user_session_path unless user_signed_in?

ask_question
end

def recent_content
recent_content = current_user.content.values.flatten.compact

Expand Down
6 changes: 6 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def referrer
after_create :initialize_stripe_customer, unless: -> { Rails.env == 'test' }
after_create :initialize_referral_code

def createable_content_types
[Universe, Character, Location, Item, Creature, Race, Religion, Group, Magic, Language, Scene].select do |c|
can_create? c
end
end

# as_json creates a hash structure, which you then pass to ActiveSupport::json.encode to actually encode the object as a JSON string.
# This is different from to_json, which converts it straight to an escaped JSON string,
# which is undesireable in a case like this, when we want to modify it
Expand Down
4 changes: 4 additions & 0 deletions app/views/cards/serendipitous/_content_question.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ if question.present? &&
<div id="tristan-answer">
<%= form_for content do |f| %>

<% if defined?(redirect_path) %>
<%= hidden_field :override, :redirect_path, value: redirect_path %>
<% end %>

<div class="input-field">
<%= f.text_area question[:field], class: 'content-question-input materialize-textarea', placeholder: content.class.human_attribute_name(question[:field]) %>
</div>
Expand Down
6 changes: 6 additions & 0 deletions app/views/layouts/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
</li>
<li class="divider"></li>
<% end %>
<li>
<%= link_to prompts_path do %>
<i class="material-icons left">lightbulb_outline</i>
Worldbuilding prompts
<% end %>
</li>
<li>
<%= link_to notebook_export_path do %>
<i class="material-icons left">file_download</i>
Expand Down
41 changes: 41 additions & 0 deletions app/views/main/prompts.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<% if @question.present? && @question[:question].present? %>
<div class="row">
<div class="col m9 s12">
<%= render partial: 'cards/serendipitous/content_question', locals: {
question: @question,
content: @content,
redirect_path: prompts_path
} %>
</div>
<div class="col m3 s12">
<h5>Recently updated</h5>
<%= render 'cards/user/recent_activity' %>
</div>
</div>
<% else %>
<%= image_tag 'tristan/small',
class: 'tooltipped tristan right',
data: {
position: 'left',
delay: '500',
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!"
} %>
<h5>Writing prompts</h5>
<p>
<% if current_user.content_count.zero? %>
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!
<% else %>
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
<% new_content = (current_user.createable_content_types - [Universe]).sample %>
<%= link_to new_polymorphic_path(new_content) do %>
create
<% if current_user.send(new_content.name.downcase.pluralize).any? %>
another
<% else %>
<%= %w(a e i o u).include?(new_content.name.downcase[0]) ? 'an' : 'a' %>
<% end %>
<%= new_content.name.downcase %>!
<% end %>
<% end %>
</p>
<% end %>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
get '/content', to: 'main#dashboard', as: :dashboard
get '/content/recent', to: 'main#recent_content', as: :recent_content
get '/submissions', to: 'main#comingsoon'
get '/prompts', to: 'main#prompts', as: :prompts

# Billing
scope '/billing' do
Expand Down

0 comments on commit ce6dda8

Please sign in to comment.