tkh_admin_panel 0.1.1 → 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +7 -0
- data/README.md +9 -3
- data/app/assets/stylesheets/admin.css.scss +9 -0
- data/app/controllers/settings_controller.rb +24 -0
- data/app/models/setting.rb +12 -0
- data/app/views/layouts/admin.html.erb +7 -3
- data/app/views/settings/edit.html.erb +22 -0
- data/app/views/settings/show.html.erb +15 -0
- data/app/views/shared/_admin_sidebar.html.erb +2 -1
- data/app/views/shared/_language_switcher.html.erb +2 -1
- data/config/routes.rb +5 -0
- data/lib/generators/tkh_admin_panel/copy_files/templates/_admin_sidebar.html.erb +1 -0
- data/lib/generators/tkh_admin_panel/create_or_update_locales/templates/de.yml +3 -0
- data/lib/generators/tkh_admin_panel/create_or_update_migrations/create_or_update_migrations_generator.rb +25 -0
- data/lib/generators/tkh_admin_panel/create_or_update_migrations/templates/create_settings.rb +32 -0
- data/lib/tasks/tkh_admin_panel_tasks.rake +2 -0
- data/lib/tkh_admin_panel/version.rb +1 -1
- metadata +10 -2
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
+
## 0.2
|
6
|
+
|
7
|
+
* Added german locale and translations. Upgrader need to run the update task and run migrations
|
8
|
+
* Added a site settings scaffold to be used throughout the whole app
|
9
|
+
* Improved style of forms
|
10
|
+
|
11
|
+
|
5
12
|
## 0.1.1
|
6
13
|
|
7
14
|
* Cleaned up CSS file
|
data/README.md
CHANGED
@@ -2,9 +2,7 @@
|
|
2
2
|
|
3
3
|
This is a Rails engine with an admin panel layout, assets and basic functionality. Powered by Twitter Bootstrap + SASS for a modern responsive design.
|
4
4
|
|
5
|
-
Primarily developed for Ten Thousand Hours but we are happy to share if anybody finds it useful.
|
6
|
-
|
7
|
-
It's primarily developed to work in sync with the tkh_cms gem suite but over time more and more effort will be made to make it work in isolation.
|
5
|
+
Primarily developed for Ten Thousand Hours but we are happy to share if anybody finds it useful. It's primarily developed to work in sync with the tkh_cms gem suite but over time more and more effort will be made to make it work in isolation.
|
8
6
|
|
9
7
|
Please note that this gem is still in its infancy. I'm just getting started.
|
10
8
|
|
@@ -21,6 +19,10 @@ And then execute:
|
|
21
19
|
Install the admin_sidebar partial
|
22
20
|
|
23
21
|
$ rake tkh_admin_panel:setup
|
22
|
+
|
23
|
+
Run the migrations
|
24
|
+
|
25
|
+
$ rake db:migrate
|
24
26
|
|
25
27
|
Start or restart your server!
|
26
28
|
|
@@ -36,6 +38,10 @@ Update the gem:
|
|
36
38
|
Update locale files.
|
37
39
|
|
38
40
|
$ rake tkh_admin_panel:update
|
41
|
+
|
42
|
+
Run new migrations if any
|
43
|
+
|
44
|
+
$ rake db:migrate
|
39
45
|
|
40
46
|
Start or restart your server!
|
41
47
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class SettingsController < ApplicationController
|
2
|
+
|
3
|
+
before_filter :authenticate
|
4
|
+
before_filter :authenticate_with_admin
|
5
|
+
|
6
|
+
def show
|
7
|
+
@setting = Setting.first
|
8
|
+
switch_to_admin_layout
|
9
|
+
end
|
10
|
+
|
11
|
+
def edit
|
12
|
+
@setting = Setting.first
|
13
|
+
switch_to_admin_layout
|
14
|
+
end
|
15
|
+
|
16
|
+
def update
|
17
|
+
@setting = Setting.first
|
18
|
+
if @setting.update_attributes(params[:setting])
|
19
|
+
redirect_to @setting, notice: 'Settings were successfully updated.'
|
20
|
+
else
|
21
|
+
render action: "edit", layout: 'admin'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# this is needed for now to make mass assignment security compatible with the translation of globalize3
|
2
|
+
Globalize::ActiveRecord::Translation.class_eval do
|
3
|
+
attr_accessible :locale
|
4
|
+
end
|
5
|
+
|
6
|
+
class Setting < ActiveRecord::Base
|
7
|
+
|
8
|
+
attr_accessible :site_name, :site_tagline, :blog_name, :blog_tagline, :disable_blog, :enable_comments_in_pages, :enable_comments_in_blog
|
9
|
+
|
10
|
+
translates :site_name, :site_tagline, :blog_name, :blog_tagline
|
11
|
+
|
12
|
+
end
|
@@ -4,7 +4,9 @@
|
|
4
4
|
<meta charset="utf-8">
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
6
|
<title>
|
7
|
-
<% if defined?(
|
7
|
+
<% if defined?(Setting) && !Setting.first.site_name.blank? %>
|
8
|
+
<%= t("admin_panel_for") + ' ' + Setting.first.site_name %>
|
9
|
+
<% elsif defined?(APP_SETTINGS) && APP_SETTINGS['site_name'] %>
|
8
10
|
<%= t("admin_panel_for") + ' ' + APP_SETTINGS['site_name'] %>
|
9
11
|
<% else %>
|
10
12
|
<%= t 'admin_panel' %>
|
@@ -31,8 +33,10 @@
|
|
31
33
|
<div class="span12">
|
32
34
|
<%= render 'shared/login_info' %>
|
33
35
|
<h1>
|
34
|
-
<% if defined?(
|
35
|
-
<%= (t("admin_panel_for") + ' ' + link_to(
|
36
|
+
<% if defined?(Setting) && !Setting.first.site_name.blank? %>
|
37
|
+
<%= (t("admin_panel_for") + ' ' + link_to(Setting.first.site_name, root_path)).html_safe %>
|
38
|
+
<% elsif defined?(APP_SETTINGS) && APP_SETTINGS['site_name'] %>
|
39
|
+
<%= t("admin_panel_for") + ' ' + APP_SETTINGS['site_name'] %>
|
36
40
|
<% else %>
|
37
41
|
<%= t 'admin_panel' %>
|
38
42
|
<% end %>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<h1>Edit Settings</h1>
|
2
|
+
|
3
|
+
<%= simple_form_for @setting, :html => { class: 'form-horizontal' } do |f| %>
|
4
|
+
<%= f.error_notification %>
|
5
|
+
|
6
|
+
<div class="form-inputs">
|
7
|
+
<%= f.input :site_name %><br />
|
8
|
+
<%= f.input :site_tagline, hint: 'a small descriptive sentence' %><br />
|
9
|
+
<%= f.input :enable_comments_in_pages, as: :boolean, inline_label: true, label: false %><br />
|
10
|
+
<%= f.input :disable_blog, as: :boolean, inline_label: true, label: false, hint: 'should be checked if you do NOT want a blog' %><br />
|
11
|
+
<%= f.input :blog_name %><br />
|
12
|
+
<%= f.input :blog_tagline, hint: 'a small descriptive sentence' %><br />
|
13
|
+
<%= f.input :enable_comments_in_blog, as: :boolean, inline_label: true, label: false %>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
<div class="form-actions">
|
17
|
+
<%= f.button :submit, :class => 'btn btn-primary' %>
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<% end %>
|
21
|
+
|
22
|
+
<%= render 'shared/admin_sidebar' %>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<h1>Settings</h1>
|
2
|
+
|
3
|
+
<p>
|
4
|
+
<strong>Site name:</strong> <%= @setting.site_name %><br />
|
5
|
+
<strong>Site tagline:</strong> <%= @setting.site_tagline %><br />
|
6
|
+
<strong>Enable comments in pages?:</strong> <%= @setting.enable_comments_in_pages? ? "<span class=\"label label-success\">✓</span>".html_safe : "<span class=\"label label-important\">X</span>".html_safe %><br />
|
7
|
+
<strong>Blog enabled?:</strong> <%= @setting.disable_blog? ? "<span class=\"label label-important\">X</span>".html_safe : "<span class=\"label label-success\">✓</span>".html_safe %><br />
|
8
|
+
<strong>Blog name:</strong> <%= @setting.blog_name %><br />
|
9
|
+
<strong>Site name:</strong> <%= @setting.blog_tagline %><br />
|
10
|
+
<strong>Enable comments in blog?:</strong> <%= @setting.enable_comments_in_blog? ? "<span class=\"label label-success\">✓</span>".html_safe : "<span class=\"label label-important\">X</span>".html_safe %>
|
11
|
+
</p>
|
12
|
+
|
13
|
+
<%= link_to t('edit'), edit_setting_path(@setting), class: 'btn btn-primary' %>
|
14
|
+
|
15
|
+
<%= render 'shared/admin_sidebar' %>
|
@@ -1,7 +1,8 @@
|
|
1
1
|
<% content_for :admin_sidebar do %>
|
2
2
|
<h2>Sections</h2>
|
3
3
|
<ul>
|
4
|
-
<li
|
4
|
+
<li><%= link_to 'site settings', setting_path(1) %></li>
|
5
|
+
<li>other links go here</li>
|
5
6
|
</ul>
|
6
7
|
|
7
8
|
<p>To override this, run "rake tkh_admin_panel:setup" and customize the new partial to your liking.</p>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
module TkhAdminPanel
|
4
|
+
module Generators
|
5
|
+
class CreateOrUpdateMigrationsGenerator < ::Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
desc "create or update setting migrations"
|
9
|
+
def self.next_migration_number(path)
|
10
|
+
unless @prev_migration_nr
|
11
|
+
@prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
12
|
+
else
|
13
|
+
@prev_migration_nr += 1
|
14
|
+
end
|
15
|
+
@prev_migration_nr.to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
def copy_migrations
|
19
|
+
puts 'creating or updating setting migrations'
|
20
|
+
migration_template "create_settings.rb", "db/migrate/create_settings.rb"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class CreateSettings < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
create_table :settings do |t|
|
5
|
+
t.string :site_name
|
6
|
+
t.string :site_tagline
|
7
|
+
t.boolean :enable_comments_in_pages, default: false
|
8
|
+
t.boolean :disable_blog, default: false
|
9
|
+
t.string :blog_name
|
10
|
+
t.string :blog_tagline
|
11
|
+
t.boolean :enable_comments_in_blog, default: true
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
Setting.create_translation_table! :site_name => :string, :site_tagline => :string, :blog_name => :string, :blog_tagline => :string
|
15
|
+
# normally it's not a good idea to populate a table in the migration but I think this is an exception
|
16
|
+
Setting.create([
|
17
|
+
{ site_name: 'Name of the web site',
|
18
|
+
site_tagline: 'A short descriptive sentence',
|
19
|
+
enable_comments_in_pages: false,
|
20
|
+
disable_blog: false,
|
21
|
+
blog_name: 'Name of the blog',
|
22
|
+
blog_tagline: "A short descriptive sentence",
|
23
|
+
enable_comments_in_blog: true
|
24
|
+
}
|
25
|
+
])
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.down
|
29
|
+
drop_table :settings
|
30
|
+
Setting.drop_translation_table!
|
31
|
+
end
|
32
|
+
end
|
@@ -4,11 +4,13 @@ namespace :tkh_admin_panel do
|
|
4
4
|
task :setup do
|
5
5
|
system 'rails g tkh_admin_panel:copy_files -f'
|
6
6
|
system 'rails g tkh_admin_panel:create_or_update_locales -f'
|
7
|
+
system 'rails g tkh_admin_panel:create_or_update_migrations'
|
7
8
|
end
|
8
9
|
|
9
10
|
desc "Update locale and other files"
|
10
11
|
task :update do
|
11
12
|
system 'rails g tkh_admin_panel:copy_files -s'
|
12
13
|
system 'rails g tkh_admin_panel:create_or_update_locales -f'
|
14
|
+
system 'rails g tkh_admin_panel:create_or_update_migrations -s'
|
13
15
|
end
|
14
16
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tkh_admin_panel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.2'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
@@ -77,15 +77,23 @@ files:
|
|
77
77
|
- app/assets/javascripts/custom.js.coffee
|
78
78
|
- app/assets/stylesheets/admin.css.scss
|
79
79
|
- app/assets/stylesheets/bootstrap_and_overrides.css.scss
|
80
|
+
- app/controllers/settings_controller.rb
|
81
|
+
- app/models/setting.rb
|
80
82
|
- app/views/layouts/admin.html.erb
|
83
|
+
- app/views/settings/edit.html.erb
|
84
|
+
- app/views/settings/show.html.erb
|
81
85
|
- app/views/shared/_admin_sidebar.html.erb
|
82
86
|
- app/views/shared/_language_switcher.html.erb
|
87
|
+
- config/routes.rb
|
83
88
|
- lib/generators/tkh_admin_panel/copy_files/copy_files_generator.rb
|
84
89
|
- lib/generators/tkh_admin_panel/copy_files/templates/_admin_sidebar.html.erb
|
85
90
|
- lib/generators/tkh_admin_panel/create_or_update_locales/create_or_update_locales_generator.rb
|
91
|
+
- lib/generators/tkh_admin_panel/create_or_update_locales/templates/de.yml
|
86
92
|
- lib/generators/tkh_admin_panel/create_or_update_locales/templates/en.yml
|
87
93
|
- lib/generators/tkh_admin_panel/create_or_update_locales/templates/es.yml
|
88
94
|
- lib/generators/tkh_admin_panel/create_or_update_locales/templates/fr.yml
|
95
|
+
- lib/generators/tkh_admin_panel/create_or_update_migrations/create_or_update_migrations_generator.rb
|
96
|
+
- lib/generators/tkh_admin_panel/create_or_update_migrations/templates/create_settings.rb
|
89
97
|
- lib/tasks/tkh_admin_panel_tasks.rake
|
90
98
|
- lib/tkh_admin_panel.rb
|
91
99
|
- lib/tkh_admin_panel/tkh_admin_panel_action_controller_extension.rb
|