diff --git a/app/controllers/continents_controller.rb b/app/controllers/continents_controller.rb new file mode 100644 index 00000000..9a2791a7 --- /dev/null +++ b/app/controllers/continents_controller.rb @@ -0,0 +1,13 @@ + +class ContinentsController < ContentController + private + + def content_param_list + [ + :name, :universe_id, :privacy + ] + [ # + + ] + end +end + \ No newline at end of file diff --git a/app/models/continent.rb b/app/models/continent.rb deleted file mode 100644 index 23815a25..00000000 --- a/app/models/continent.rb +++ /dev/null @@ -1,4 +0,0 @@ -class Continent < ApplicationRecord - belongs_to :user - belongs_to :universe -end diff --git a/app/models/page_types/continent.rb b/app/models/page_types/continent.rb new file mode 100644 index 00000000..5ad6342b --- /dev/null +++ b/app/models/page_types/continent.rb @@ -0,0 +1,38 @@ + +class Continent < ActiveRecord::Base + acts_as_paranoid + + belongs_to :user + validates :user_id, presence: true # belongs_to are no longer optional in rails 6 so we probably don't need this on any content type + + validates :name, presence: true + + include BelongsToUniverse + include IsContentPage + + include Serendipitous::Concern + + include Authority::Abilities + self.authorizer_name = 'ExtendedContentAuthorizer' + + def description + overview_field_value('Description') + end + + def self.color + 'lighten-1 text-lighten-1 green' + end + + def self.hex_color + '#66BB6A' + end + + def self.icon + 'explore' + end + + def self.content_name + 'continent' + end +end + \ No newline at end of file diff --git a/app/models/page_types/country.rb b/app/models/page_types/country.rb index 7261cf89..06dac742 100644 --- a/app/models/page_types/country.rb +++ b/app/models/page_types/country.rb @@ -42,6 +42,6 @@ class Country < ApplicationRecord end def self.icon - 'explore' + 'flag' end end diff --git a/app/models/page_types/universe.rb b/app/models/page_types/universe.rb index 2789ab88..b98f3578 100644 --- a/app/models/page_types/universe.rb +++ b/app/models/page_types/universe.rb @@ -49,6 +49,7 @@ class Universe < ApplicationRecord has_many :sports has_many :schools has_many :foods + has_many :continents has_many :contributors, dependent: :destroy diff --git a/config/attributes/continent.yml b/config/attributes/continent.yml new file mode 100644 index 00000000..acad7ff9 --- /dev/null +++ b/config/attributes/continent.yml @@ -0,0 +1,105 @@ +:overview: + :label: Overview + :icon: info + :attributes: + - :name: name + :label: Local name + :field_type: name + - :name: other_names + :label: Other names + - :name: description + :label: Description + - :name: universe_id + :label: Universe + :field_type: universe + - :name: + :label: Tags + :field_type: tags +:geography: + :label: Geography + :icon: info + :attributes: + - :name: area + :label: Area + - :name: population + :label: Population + - :name: crops + :label: Crops + - :name: landmarks + :label: Landmarks + :field_type: link + - :name: creatures + :label: Creatures + :field_type: link + - :name: floras + :label: Floras + :field_type: link +:culture: + :label: Culture + :icon: info + :attributes: + - :name: demonym + :label: Demonym + - :name: politics + :label: Politics + - :name: economy + :label: Economy + - :name: tourism + :label: Tourism + - :name: countries + :label: Countries + :field_type: link + - :name: languages + :label: Languages + :field_type: link + - :name: traditions + :label: Traditions + :field_type: link + - :name: governments + :label: Governments + :field_type: link + - :name: popular_foods + :label: Popular foods + :field_type: link +:climate: + :label: Climate + :icon: info + :attributes: + - :name: temperature + :label: Temperature + - :name: seasons + :label: Seasons + - :name: humidity + :label: Humidity + - :name: precipitation + :label: Precipitation + - :name: winds + :label: Winds + - :name: natural_disasters + :label: Natural disasters +:history: + :label: History + :icon: info + :attributes: + - :name: formation + :label: Formation + - :name: discovery + :label: Discovery + - :name: wars + :label: Wars +:gallery: + :label: Gallery + :icon: photo_library +:changelog: + :label: Changelog + :icon: history +:notes: + :label: Notes + :icon: edit + :attributes: + - :name: notes + :label: Notes + - :name: private_notes + :label: Private Notes + :description: Private notes are always visible to only you, even if content is made public and shared. + \ No newline at end of file diff --git a/config/initializers/content_types.rb b/config/initializers/content_types.rb index e752644c..6f61545d 100644 --- a/config/initializers/content_types.rb +++ b/config/initializers/content_types.rb @@ -1,7 +1,7 @@ Rails.application.config.content_types = { # The complete list of all content types all: [ - Universe, Character, Location, Item, Building, Condition, Country, Creature, Deity, Flora, + Universe, Character, Location, Item, Building, Condition, Continent, Country, Creature, Deity, Flora, Food, Government, Group, Job, Landmark, Language, Magic, Planet, Race, Religion, Scene, School, Sport, Technology, Town, Tradition, Vehicle, @@ -16,7 +16,8 @@ Rails.application.config.content_types = { # These content types are available to be turned on available: [ Building, Condition, Country, Creature, Deity, Flora, Government, Group, Job, Landmark, Language, - Magic, Planet, Race, Religion, Scene, Technology, Town, Tradition, Vehicle, Sport, School, Food + Magic, Planet, Race, Religion, Scene, Technology, Town, Tradition, Vehicle, Sport, School, Food, + Continent ], # These content types can be created by any user @@ -26,11 +27,12 @@ Rails.application.config.content_types = { premium: [ Building, Condition, Country, Creature, Deity, Flora, Government, Group, Job, Landmark, Language, Magic, Planet, Race, Religion, Scene, Technology, Town, Tradition, Vehicle, - Sport, Food, School + Sport, Food, School, Continent ], # Content types to label as "new" around the site new: [ + Continent ] } diff --git a/config/locales/en.yml b/config/locales/en.yml index 4589d2e5..8047b50a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -869,6 +869,31 @@ en: religions: Which religions are associated with %{name}? notable_events: What notable events throughout history are related to %{name}? + continent: + name: What do the people %{name} call it? + other_names: What other names is %{name} called? + description: What is %{name}'s description? + + area: How large is %{name}? + population: How many people live in %{name}? + crops: What crops are usually grown in %{name}? + + demonym: What are the people that live in %{name} called? + politics: What are the politics like in %{name}? + economy: What is the economy like in %{name}? + tourism: What is the tourism like in %{name}? + + temperature: How hot does it get in %{name}? How cold? + seasons: What are the seasons like in %{name}? + humidity: How humid is it in %{name}? + precipitation: What kind of precipitation does %{name} experience? How often? + winds: What are the winds like in %{name}? + natural_disasters: What natural disasters are common in %{name}? + + formation: How did %{name} originally form? + discovery: How was %{name} discovered? + wars: What wars have been fought in %{name}? + blacklist: _: - id @@ -908,6 +933,7 @@ en: sport: Recreation and competition at their best school: Education shapes your world's future food: Every world gets a little better with food + continent: The largest land masses in your world content_descriptions: universe: > @@ -964,6 +990,8 @@ en: From Hogwarts to Walkerville to Brakebills, schools educate every new generation in our worlds. food: > People of all kinds eat and drink things of all kinds. Come eat, drink, and be merry! + continent: > + Underneath our feet, continents form the base and borders our worlds are built upon attributefield: > Attributes can be anything you need to define just the detail you need. Select the type of content diff --git a/db/migrate/20200128231056_create_continents.rb b/db/migrate/20200128231056_create_continents.rb index d52d1165..3e9f14e3 100644 --- a/db/migrate/20200128231056_create_continents.rb +++ b/db/migrate/20200128231056_create_continents.rb @@ -6,6 +6,7 @@ class CreateContinents < ActiveRecord::Migration[6.0] t.references :universe, null: false, foreign_key: true t.datetime :deleted_at t.string :privacy + t.string :page_type, default: 'Continent' t.timestamps end diff --git a/db/migrate/20200128233630_add_archived_at_to_continents.rb b/db/migrate/20200128233630_add_archived_at_to_continents.rb new file mode 100644 index 00000000..8679e064 --- /dev/null +++ b/db/migrate/20200128233630_add_archived_at_to_continents.rb @@ -0,0 +1,5 @@ +class AddArchivedAtToContinents < ActiveRecord::Migration[6.0] + def change + add_column :continents, :archived_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 4c142f88..703103a9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_01_28_231056) do +ActiveRecord::Schema.define(version: 2020_01_28_233630) do create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false @@ -403,8 +403,10 @@ ActiveRecord::Schema.define(version: 2020_01_28_231056) do t.integer "universe_id", null: false t.datetime "deleted_at" t.string "privacy" + t.string "page_type", default: "Continent" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.datetime "archived_at" t.index ["universe_id"], name: "index_continents_on_universe_id" t.index ["user_id"], name: "index_continents_on_user_id" end diff --git a/docs/content_types.md b/docs/content_types.md index 365b9b94..7e2db8da 100644 --- a/docs/content_types.md +++ b/docs/content_types.md @@ -4,7 +4,7 @@ Checklist to create a new content type: - e.g. https://github.com/indentlabs/notebook/issues/258 - Generate models (with non-relation fields) - - `rails g model Planet name:string user:references universe:references deleted_at:datetime privacy:string` + - `rails g model Planet name:string user:references universe:references deleted_at:datetime archived_at:datetime privacy:string` - Edit the migration to add a page_type column with default value Planet - `rake db:migrate` @@ -29,6 +29,8 @@ Checklist to create a new content type: - add line for each to content_oneliners - add content_descriptions (of relatively the same size) +- Restart the server + - Give it a shot through the UI! :) - fill in each field to make sure all fields are working/permitted - make sure new/create and show/edit are working diff --git a/lib/tasks/page_type.rake b/lib/tasks/page_type.rake index 34fcdac6..139b5ff1 100644 --- a/lib/tasks/page_type.rake +++ b/lib/tasks/page_type.rake @@ -16,14 +16,14 @@ namespace :page_type do editable_fields = klass.columns.map(&:name) - %w(id deleted_at created_at updated_at user_id) editable_fields.map!(&:to_sym) - # Move model from models/ to models/content_types/ + # Move model from models/ to models/page_types/ # (we write the file in the next step; this just removes the original) puts "Removing base model at models/#{page_type.downcase}.rb" `rm app/models/#{page_type.downcase}.rb` # Add concerns to new model - puts "Writing class definition to app/models/content_types/#{page_type.downcase}.rb" - #TODO: read from content_types/_template.erb or something? + puts "Writing class definition to app/models/page_types/#{page_type.downcase}.rb" + #TODO: read from page_types/_template.erb or something? class_definition = """ class #{page_type} < ActiveRecord::Base acts_as_paranoid @@ -57,7 +57,7 @@ class #{page_type} < ActiveRecord::Base end end """ - File.open("app/models/content_types/#{page_type.downcase}.rb", 'w') do |file| + File.open("app/models/page_types/#{page_type.downcase}.rb", 'w') do |file| file.write(class_definition) end diff --git a/test/fixtures/continents.yml b/test/fixtures/continents.yml new file mode 100644 index 00000000..976f7aa1 --- /dev/null +++ b/test/fixtures/continents.yml @@ -0,0 +1,15 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + user: one + universe: one + deleted_at: 2020-01-28 17:10:56 + privacy: MyString + +two: + name: MyString + user: two + universe: two + deleted_at: 2020-01-28 17:10:56 + privacy: MyString diff --git a/test/models/continent_test.rb b/test/models/continent_test.rb new file mode 100644 index 00000000..d0338b5c --- /dev/null +++ b/test/models/continent_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ContinentTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end