Selaa lähdekoodia

Add DB stuff for global app settings.

old-ruby
Ben Kurtovic 9 vuotta sitten
vanhempi
commit
fc8f04a62a
13 muutettua tiedostoa jossa 67 lisäystä ja 10 poistoa
  1. +2
    -0
      README.md
  2. +5
    -1
      app/helpers/application_helper.rb
  3. +4
    -0
      app/helpers/tools_helper.rb
  4. +6
    -0
      app/models/admin_setting.rb
  5. +2
    -5
      app/views/layouts/application.html.erb
  6. +9
    -1
      app/views/shared/_footer.html.erb
  7. +3
    -1
      app/views/shared/_header.html.erb
  8. +1
    -1
      app/views/tools/index.html.erb
  9. +8
    -0
      db/migrate/20150313054643_create_admin_settings.rb
  10. +6
    -1
      db/schema.rb
  11. +5
    -0
      db/seeds.rb
  12. +9
    -0
      test/fixtures/admin_settings.yml
  13. +7
    -0
      test/models/admin_setting_test.rb

+ 2
- 0
README.md Näytä tiedosto

@@ -8,3 +8,5 @@ Installing
----------

calefaction can be deployed as a standard Rails app.

- describe db setup here...

+ 5
- 1
app/helpers/application_helper.rb Näytä tiedosto

@@ -3,7 +3,7 @@ require 'calefaction/version'
module ApplicationHelper

def get_title(title = '')
base = '[Site Name]'
base = AdminSetting.get('site_name')
title.empty? ? base : "#{title} : #{base}"
end

@@ -12,4 +12,8 @@ module ApplicationHelper
year = Time.now.year
year > start ? "#{start}–#{year}" : start
end

def get_copyright_holders
AdminSetting.get('copyright')
end
end

+ 4
- 0
app/helpers/tools_helper.rb Näytä tiedosto

@@ -1,2 +1,6 @@
module ToolsHelper

def get_description
AdminSetting.get('description')
end
end

+ 6
- 0
app/models/admin_setting.rb Näytä tiedosto

@@ -0,0 +1,6 @@
class AdminSetting < ActiveRecord::Base

def self.get(key)
self.find_by(key: key).value
end
end

+ 2
- 5
app/views/layouts/application.html.erb Näytä tiedosto

@@ -7,14 +7,11 @@
<%= csrf_meta_tags %>
</head>
<body>
<div id="header">
<%= render "shared/header" %>
<%= render "shared/header" %>
</div>
<div id="content">
<%= yield %>
</div>
<div id="footer">
<%= render "shared/footer" %>
</div>
<%= render "shared/footer" %>
</body>
</html>

+ 9
- 1
app/views/shared/_footer.html.erb Näytä tiedosto

@@ -1 +1,9 @@
<p>Copyright &copy; <%= get_copyright_year %> [copyright holders] &bull; Running Calefaction <%= Calefaction::Version::VERSION_STRING %> &bull; <a href="//eveonline.com">EVE Online</a> and all related trademarks are property of <a href="//ccpgames.com">CCP hf</a>.</p>
<div id="footer">
<p>
Copyright &copy; <%= get_copyright_year %> <%= get_copyright_holders %>
&bull;
Running Calefaction <%= Calefaction::Version::VERSION_STRING %>
&bull;
<a href="//eveonline.com">EVE Online</a> and all related trademarks are property of <a href="//ccpgames.com">CCP hf</a>.
</p>
</div>

+ 3
- 1
app/views/shared/_header.html.erb Näytä tiedosto

@@ -1 +1,3 @@
<!-- -->
<div id="header">
<!-- -->
</div>

+ 1
- 1
app/views/tools/index.html.erb Näytä tiedosto

@@ -12,4 +12,4 @@
</p>
<p>Tools: ...</p>

<p>[Site description]</p>
<p><%= get_description %></p>

+ 8
- 0
db/migrate/20150313054643_create_admin_settings.rb Näytä tiedosto

@@ -0,0 +1,8 @@
class CreateAdminSettings < ActiveRecord::Migration
def change
create_table :admin_settings do |t|
t.string :key
t.string :value
end
end
end

+ 6
- 1
db/schema.rb Näytä tiedosto

@@ -11,7 +11,12 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150311175036) do
ActiveRecord::Schema.define(version: 20150313054643) do

create_table "admin_settings", force: :cascade do |t|
t.string "key"
t.string "value"
end

create_table "users", force: :cascade do |t|
t.string "name"


+ 5
- 0
db/seeds.rb Näytä tiedosto

@@ -5,3 +5,8 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)

AdminSetting.create(key: 'site_name', value: 'Your Corporation')
AdminSetting.create(key: 'corporation', value: 'Your Corporation')
AdminSetting.create(key: 'description', value: 'Your corporation\'s description goes here!')
AdminSetting.create(key: 'copyright', value: 'Your Corporation/Your Name')

+ 9
- 0
test/fixtures/admin_settings.yml Näytä tiedosto

@@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
key: MyString
value: MyString

two:
key: MyString
value: MyString

+ 7
- 0
test/models/admin_setting_test.rb Näytä tiedosto

@@ -0,0 +1,7 @@
require 'test_helper'

class AdminSettingTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

Ladataan…
Peruuta
Tallenna