golden-theme 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +27 -0
  6. data/Rakefile +2 -0
  7. data/app/assets/javascripts/golden/theme/bootstrap.js +7 -0
  8. data/app/assets/javascripts/golden/theme/bootstrap/ajax-chosen.js.coffee +10 -0
  9. data/app/assets/javascripts/golden/theme/bootstrap/ajax-tabs.js.coffee +42 -0
  10. data/app/assets/javascripts/golden/theme/bootstrap/bench-util-jquery.js.coffee +48 -0
  11. data/app/assets/javascripts/golden/theme/bootstrap/modal.js.coffee +60 -0
  12. data/app/assets/stylesheets/golden/theme/bootstrap.css +4 -0
  13. data/app/assets/stylesheets/golden/theme/bootstrap/devise.css.sass +9 -0
  14. data/app/controllers/concerns/golden/theme/bootstrap/pagination.rb +33 -0
  15. data/app/helpers/golden/theme/bootstrap/alert_helper.rb +24 -0
  16. data/app/helpers/golden/theme/bootstrap/button_helper.rb +13 -0
  17. data/app/helpers/golden/theme/bootstrap/common_helper.rb +39 -0
  18. data/app/helpers/golden/theme/bootstrap/dropdown_helper.rb +33 -0
  19. data/app/helpers/golden/theme/bootstrap/link_helper.rb +56 -0
  20. data/app/helpers/golden/theme/bootstrap/modal_helper.rb +63 -0
  21. data/app/helpers/golden/theme/bootstrap/tab_helper.rb +55 -0
  22. data/app/helpers/golden/theme/common_helper.rb +17 -0
  23. data/app/helpers/golden/theme/devise/user_helper.rb +23 -0
  24. data/app/views/application/_flash_messages.html.erb +10 -0
  25. data/app/views/application/bootstrap/_header.html.erb +24 -0
  26. data/app/views/application/bootstrap/_main_navigation.html.erb +8 -0
  27. data/app/views/application/bootstrap/_pagination.html.erb +9 -0
  28. data/app/views/application/bootstrap/_user_navigation.html.erb +22 -0
  29. data/config/locales/application.en.yml +19 -0
  30. data/config/locales/application.zh-TW.yml +19 -0
  31. data/config/locales/helpers.en.yml +25 -0
  32. data/config/locales/helpers.zh-TW.yml +25 -0
  33. data/config/locales/will_paginate.zh-TW.yml +33 -0
  34. data/golden-theme.gemspec +34 -0
  35. data/lib/golden/theme.rb +16 -0
  36. data/lib/golden/theme/bootstrap/link_renderer.rb +63 -0
  37. data/lib/golden/theme/engine.rb +6 -0
  38. data/lib/golden/theme/version.rb +5 -0
  39. metadata +221 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 63af6ed8665891c5163c8abf8d385bc32f7b91da
4
+ data.tar.gz: 059665596c4cd4b3c33bde9833bbe4769d321107
5
+ SHA512:
6
+ metadata.gz: 6feccdb968f5ccc3f8e695d6e8e9ecbeff5a09e98dd27441864b5959f65422f7b38937a2ba780ccdc34f114f1d5bfac1407c1b220124907336ec0b4241cc49b1
7
+ data.tar.gz: 3d5d709973e992ea8328ed8284a4ee0614fbb04156b0af835509afe5b43721759b2f50f64b53aec102be0428bca96b6dc276a5cb5be67fa0e1b6379ec5dff7ee
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in golden-theme.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Tse-Ching Ho
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # Golden::Theme
2
+
3
+ Provide theme helpers for Rails.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'golden-theme'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install golden-theme
18
+
19
+ ## Usage
20
+
21
+ ## Contributing
22
+
23
+ 1. Fork it ( https://github.com/[my-github-username]/golden-theme/fork )
24
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
25
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
26
+ 4. Push to the branch (`git push origin my-new-feature`)
27
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+
@@ -0,0 +1,7 @@
1
+ //= require jquery.ui.effect-highlight
2
+ //= require chosen-jquery
3
+
4
+ //= require golden/theme/bootstrap/bench-util-jquery
5
+ //= require golden/theme/bootstrap/modal
6
+ //= require golden/theme/bootstrap/ajax-tabs
7
+ //= require golden/theme/bootstrap/ajax-chosen
@@ -0,0 +1,10 @@
1
+ $ ->
2
+ $('.chosen-select').chosen
3
+ allow_single_deselect: true
4
+ no_results_text: 'No results matched'
5
+ width: '100%'
6
+
7
+ $('.ajax-chosen-select').chosen
8
+ allow_single_deselect: true
9
+ no_results_text: 'No results matched'
10
+ width: '100%'
@@ -0,0 +1,42 @@
1
+ $ ->
2
+ $('.nav-tabs-ajax')
3
+ .on 'ajax:beforeSend', 'a[data-toggle="tab"]', ->
4
+ $.bench.util.replaceDataTarget $(this), 'Loading...'
5
+ .on 'ajax:success', 'a[data-toggle="tab"]', (event, data, status, xhr) ->
6
+ $.bench.util.replaceDataTarget $(this), data
7
+ $.bench.util.enableChosen()
8
+ .on 'ajax:error', 'a[data-toggle="tab"]', (event, xhr, status, error) ->
9
+ if error == 'Unauthorized' or xhr.status == 401
10
+ $.bench.util.replaceDataTarget $(this), ''
11
+ $.bench.util.redirect_to_unauthorized_url
12
+ else
13
+ $.bench.util.replaceDataTarget $(this), status
14
+
15
+ $('.tab-content')
16
+ .on 'ajax:success', '.pagination a[data-toggle="tab"]', (event, data, status, xhr) ->
17
+ $.bench.util.replaceDataTarget $(this), data
18
+ .on 'ajax:error', '.pagination a[data-toggle="tab"]', (event, xhr, status, error) ->
19
+ if error == 'Unauthorized' or xhr.status == 401
20
+ $.bench.util.replaceDataTarget $(this), ''
21
+ $.bench.util.redirect_to_unauthorized_url
22
+ else
23
+ $.bench.util.replaceDataTarget $(this), status
24
+
25
+ $('.tab-pane')
26
+ .on 'ajax:success', '.simple_form', (event, data, status, xhr) ->
27
+ tab_pane = $(this).parent()
28
+ $.bench.util.appendFeedback(tab_pane, data)
29
+ if $.bench.util.hasErrorFeedback(tab_pane)
30
+ $.bench.util.replaceFeedback(tab_pane)
31
+ $.bench.util.enableChosen()
32
+ return true
33
+ tab_pane.html(data)
34
+ $.bench.util.enableChosen()
35
+ tab_pane.effect('highlight', 'slow')
36
+ .on 'ajax:error', '.simple_form', (event, xhr, status, error) ->
37
+ tab_pane = $(this).parent()
38
+ if error == 'Unauthorized' or xhr.status == 401
39
+ tab_pane.html('')
40
+ $.bench.util.redirect_to_unauthorized_url
41
+ else
42
+ tab_pane.html(status)
@@ -0,0 +1,48 @@
1
+ $ ->
2
+ #### namespace ####
3
+
4
+ $.bench ||= {}
5
+ $.bench.util ||= {}
6
+
7
+
8
+ #### util ####
9
+
10
+ $.bench.util.clearSelectOptions = (subject, disabled = true) ->
11
+ blank_option = $('<option>').attr('value', '')
12
+ if disabled
13
+ subject.prop('disabled', true)
14
+ subject.empty().append(blank_option)
15
+
16
+ $.bench.util.appendSelectOptions = (subject, choices, disabled = false) ->
17
+ return unless choices
18
+ $.each choices, (i, hash) ->
19
+ option = $('<option>').attr('value', hash['id']).text(hash['name'])
20
+ subject.append option
21
+ if !disabled
22
+ subject.prop('disabled', false)
23
+ subject.focus().children().first().text('')
24
+
25
+ $.bench.util.appendFeedback = (container, data) ->
26
+ if container.find('.feedback').size() < 1
27
+ $('<div>').addClass('feedback hide').html(data).appendTo(container)
28
+
29
+ $.bench.util.replaceFeedback = (container) ->
30
+ content = container.children('.feedback').html()
31
+ container.html(content)
32
+
33
+ $.bench.util.hasErrorFeedback = (container) ->
34
+ container.find('.feedback .alert-error').size() > 0
35
+
36
+ $.bench.util.replaceDataTarget = (subject, data) ->
37
+ target = $(subject.attr('data-target'))
38
+ target.html(data)
39
+
40
+ $.bench.util.enableChosen = () ->
41
+ $('.chosen-select, .ajax-chosen-select').chosen
42
+ allow_single_deselect: true
43
+ no_results_text: 'No results matched'
44
+ width: '100%'
45
+
46
+ $.bench.util.redirect_to_unauthorized_url = () ->
47
+ url = $('#unauthorized_sign_out_url').prop('href')
48
+ window.location.replace(url)
@@ -0,0 +1,60 @@
1
+ $ ->
2
+ #### namespace ####
3
+
4
+ $.modal ||= {}
5
+
6
+ #### modal ####
7
+ $.modal.showErrorModal = (status, error, modal = $(this)) ->
8
+ modal.html($('#error-modal').html())
9
+ .find('.modal-header h3').html(status).end()
10
+ .children('.modal-body').html(error || 'No Connection!')
11
+
12
+ $.modal.appendFeedback = (modal, data) ->
13
+ $('<div>').addClass('feedback hide').html(data).appendTo(modal)
14
+
15
+ $.modal.replaceFeedback = (modal) ->
16
+ modal.html(modal.children('.feedback').html())
17
+ $.modal.enableChosen()
18
+
19
+ $.modal.submitForm = (submit_id, modal = $(this)) ->
20
+ modal.find('.feedback').remove().end()
21
+ .modal('hide')
22
+ $.modal.disableOtherSubmit submit_id
23
+ $.modal.enableSingleSubmit submit_id
24
+ $(submit_id).removeAttr('data-toggle').click()
25
+ return true
26
+
27
+ $.modal.replaceTable = (table_id, modal = $(this)) ->
28
+ feedback_table = modal.find('.table')
29
+ table = $(table_id).find('.table')
30
+ table.html(feedback_table.html())
31
+ modal.find('.feedback').remove().end()
32
+ .modal('hide')
33
+ table.effect('shake')
34
+ return true
35
+
36
+ # $.rails.disableFormElements(form) will disable all disable-with element
37
+ $.modal.disableSingleSubmit = (element_id) ->
38
+ $(element_id).data('modal:enable-with', $(element_id).val())
39
+ $(element_id).val($(element_id).data('disable-with'))
40
+ $(element_id).prop('disabled', true)
41
+
42
+ # $.rails.enableFormElements(form) will enable all disable-with element
43
+ $.modal.enableSingleSubmit = (element_id) ->
44
+ if $(element_id).data('modal:enable-with')
45
+ $(element_id).val($(element_id).data('modal:enable-with'))
46
+ $(element_id).prop('disabled', false)
47
+
48
+ # disable other submit buttons other than the specified one
49
+ $.modal.disableOtherSubmit = (submit_id) ->
50
+ submit_button = $(submit_id)
51
+ submit_button.parents('form').find($.rails.disableSelector).each () ->
52
+ if submit_button.val() != $(this).val()
53
+ $(this).prop('disabled', true)
54
+ $(this).removeAttr('data-disable-with')
55
+
56
+ $.modal.enableChosen = () ->
57
+ $('.chosen-select').chosen
58
+ allow_single_deselect: true
59
+ no_results_text: 'No results matched'
60
+ width: '100%'
@@ -0,0 +1,4 @@
1
+ /*
2
+ *= require chosen
3
+ *= require golden/theme/bootstrap/devise
4
+ */
@@ -0,0 +1,9 @@
1
+ body
2
+ padding-top: 70px
3
+
4
+ #site-name
5
+ h1
6
+ margin: 0
7
+ a
8
+ margin: 0 10px 0 0
9
+ padding: 0.8em 0
@@ -0,0 +1,33 @@
1
+ module Golden::Theme::Bootstrap
2
+ module Pagination
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_action :clear_pagination_options
7
+ end
8
+
9
+ module ClassMethods
10
+ end
11
+
12
+ protected
13
+
14
+ def clear_pagination_options
15
+ Golden::Theme::Bootstrap::LinkRenderer.link_options = nil
16
+ end
17
+
18
+ def set_ajax_tab_pagination_render_options tab_name
19
+ Golden::Theme::Bootstrap::LinkRenderer.link_options = {
20
+ 'data-remote' => true,
21
+ 'data-type' => :html,
22
+ 'data-toggle' => 'tab',
23
+ 'data-target' => "##{tab_name}"
24
+ }
25
+ end
26
+
27
+ def last_page_collection query
28
+ last_page = query.paginate(page: 1).total_pages
29
+ params[:page] = last_page
30
+ query.paginate page: last_page
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,24 @@
1
+ module Golden::Theme::Bootstrap
2
+ module AlertHelper
3
+ def flash_box key, value
4
+ alert_class = case key.to_sym
5
+ when :notice, :alert
6
+ 'alert-warning'
7
+ when :error
8
+ 'alert-danger'
9
+ else
10
+ "alert-#{key}"
11
+ end
12
+ button_options = {
13
+ type: 'button',
14
+ name: nil,
15
+ class: 'close',
16
+ data: { dismiss: 'alert' },
17
+ 'aria-hidden' => 'true'
18
+ }
19
+ content_tag :div, class: "alert #{alert_class} alert-dismissable #{key}" do
20
+ button_tag('&times;'.html_safe, button_options) << value
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ module Golden::Theme::Bootstrap
2
+ module ButtonHelper
3
+ def render_btn_group tag = :div, options = {}
4
+ buttons = []
5
+ yield buttons if block_given?
6
+ text = buttons.join('').html_safe
7
+ options = {
8
+ class: 'btn-group'
9
+ }.deep_merge options
10
+ content_tag tag, text, options
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,39 @@
1
+ module Golden::Theme::Bootstrap
2
+ module CommonHelper
3
+ def render_list list = [], options = {}
4
+ options, list = list, [] if list.is_a? Hash
5
+ yield list if block_given?
6
+ items = ''.html_safe
7
+ list.each_with_index do |item, index|
8
+ if item.is_a? Array
9
+ item_options = item.pop
10
+ item_content = item.join('').html_safe
11
+ else
12
+ item_options = {}
13
+ item_content = item
14
+ end
15
+
16
+ item_class = []
17
+ item_class << 'first' if index == 0
18
+ item_class << 'last' if index == (list.length - 1)
19
+ link = item_content.match(/href=(["'])(.*?)(\1)/)[2] rescue nil
20
+ item_class << 'current active' if link and (current_page?(link) rescue false)
21
+ item_class << item_options.delete(:class) if item_options[:class]
22
+
23
+ li_class = item_class.empty? ? nil : item_class.join(' ')
24
+ items << content_tag(:li, item_content, item_options.merge(class: li_class) )
25
+ end
26
+ content_tag :ul, items, options
27
+ end
28
+
29
+ def link_to_callback_button callback_id, options = {}
30
+ options = {
31
+ data: {
32
+ callback_id: callback_id
33
+ },
34
+ class: 'callback hide'
35
+ }.deep_merge options
36
+ link_to nil, '', options
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,33 @@
1
+ module Golden::Theme::Bootstrap
2
+ module DropdownHelper
3
+ def dropdown_toggle text, url = '', options = {}
4
+ text = text.html_safe << ' '
5
+ text << content_tag(:span, nil, class: 'caret')
6
+ options = {
7
+ class: 'dropdown-toggle',
8
+ data: { toggle: 'dropdown' }
9
+ }.deep_merge options
10
+ link_to text, url, options
11
+ end
12
+
13
+ def dropdown_btn text, options = {}
14
+ text = text.html_safe << ' '
15
+ text << content_tag(:span, nil, class: 'caret')
16
+ options = {
17
+ name: nil,
18
+ type: 'button',
19
+ class: 'btn dropdown-toggle',
20
+ data: { toggle: 'dropdown' }
21
+ }.deep_merge options
22
+ button_tag text, options
23
+ end
24
+
25
+ def dropdown_menu options = {}, &block
26
+ options = {
27
+ role: 'menu',
28
+ class: 'dropdown-menu'
29
+ }.deep_merge options
30
+ render_list options, &block
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,56 @@
1
+ module Golden::Theme::Bootstrap
2
+ module LinkHelper
3
+ def iconed_link_to text, url, options = {}
4
+ icon_class = options.delete(:icon_class)
5
+ text = content_tag(:i, nil, class: icon_class) << ' ' << text
6
+ link_to text, url, options
7
+ end
8
+
9
+ def link_to_show url, options = {}
10
+ icon_class = options.delete(:icon_class) || 'glyphicon glyphicon-eye-open'
11
+ options = {
12
+ role: 'button',
13
+ class: 'btn btn-default',
14
+ icon_class: icon_class,
15
+ title: t('helpers.show')
16
+ }.deep_merge options
17
+ default_options = { }
18
+ iconed_link_to nil, url, options
19
+ end
20
+
21
+ def link_to_new url, options = {}
22
+ icon_class = options.delete(:icon_class) || 'glyphicon glyphicon-plus'
23
+ options = {
24
+ role: 'button',
25
+ class: 'btn btn-default',
26
+ icon_class: icon_class,
27
+ title: t('helpers.new')
28
+ }.deep_merge options
29
+ iconed_link_to nil, url, options
30
+ end
31
+
32
+ def link_to_edit url, options = {}
33
+ icon_class = options.delete(:icon_class) || 'glyphicon glyphicon-edit'
34
+ options = {
35
+ role: 'button',
36
+ class: 'btn btn-default',
37
+ icon_class: icon_class,
38
+ title: t('helpers.edit')
39
+ }.deep_merge options
40
+ iconed_link_to nil, url, options
41
+ end
42
+
43
+ def link_to_destroy url, options = {}
44
+ icon_class = options.delete(:icon_class) || 'glyphicon glyphicon-trash'
45
+ options = {
46
+ method: :delete,
47
+ data: { confirm: t('helpers.are_you_sure') },
48
+ role: 'button',
49
+ class: 'btn btn-default',
50
+ icon_class: icon_class,
51
+ title: t('helpers.destroy')
52
+ }.deep_merge options
53
+ iconed_link_to nil, url, options
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,63 @@
1
+ module Golden::Theme::Bootstrap
2
+ module ModalHelper
3
+ def link_to_modal text, url, modal_id, options = {}
4
+ options = {
5
+ remote: true,
6
+ data: {
7
+ toggle: 'modal',
8
+ target: modal_id,
9
+ type: 'html'
10
+ },
11
+ class: 'modal-open'
12
+ }.deep_merge options
13
+ link_to text, url, options
14
+ end
15
+
16
+ def link_to_open_modal text, url, modal_id, options = {}
17
+ options = {
18
+ remote: true,
19
+ data: {
20
+ toggle: 'modal',
21
+ target: modal_id,
22
+ type: 'html'
23
+ },
24
+ class: 'modal-open'
25
+ }.deep_merge options
26
+ iconed_link_to text, url, options
27
+ end
28
+
29
+ def link_to_edit_modal url, modal_id, options = {}
30
+ options = {
31
+ remote: true,
32
+ data: {
33
+ toggle: 'modal',
34
+ target: modal_id,
35
+ type: 'html'
36
+ },
37
+ class: 'modal-open btn btn-default'
38
+ }.deep_merge options
39
+ link_to_edit url, options
40
+ end
41
+
42
+ def link_to_close_button
43
+ options = {
44
+ type: 'button',
45
+ name: nil,
46
+ data: { dismiss: 'modal' },
47
+ class: 'btn btn-default'
48
+ }
49
+ button_tag t('helpers.close'), options
50
+ end
51
+
52
+ def modal_close_button
53
+ options = {
54
+ type: 'button',
55
+ name: nil,
56
+ 'aria-hidden' => 'true',
57
+ data: { dismiss: 'modal' },
58
+ class: 'close'
59
+ }
60
+ button_tag '&times;'.html_safe, options
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,55 @@
1
+ module Golden::Theme::Bootstrap
2
+ module TabHelper
3
+ def link_to_tab text, tab_pane_id, options = {}
4
+ options = {
5
+ data: {
6
+ toggle: 'tab',
7
+ target: tab_pane_id
8
+ }
9
+ }.deep_merge options
10
+ link_to text, tab_pane_id, options
11
+ end
12
+
13
+ def link_to_remote_tab text, url, tab_pane_id, options = {}
14
+ options = {
15
+ remote: true,
16
+ data: {
17
+ toggle: 'tab',
18
+ target: tab_pane_id,
19
+ type: 'html'
20
+ }
21
+ }.deep_merge options
22
+ link_to text, url, options
23
+ end
24
+
25
+ def nav_tab text, tag_id, default
26
+ active = tag_id == default
27
+ li_class = 'active' if active
28
+ [ link_to_tab(text, "##{tag_id}"), { class: li_class } ]
29
+ end
30
+
31
+ def tab_pane tag_id, default
32
+ active = tag_id == default
33
+ tab_class = 'tab-pane fade'
34
+ tab_class << ' active in' if active
35
+ content_tag :div, class: tab_class, id: tag_id do
36
+ yield active if block_given?
37
+ end
38
+ end
39
+
40
+ def remote_nav_tab text, url, tag_id, default
41
+ active = current_page?(url) || tag_id == default
42
+ li_class = 'active' if active
43
+ [ link_to_remote_tab(text, url, "##{tag_id}"), { class: li_class } ]
44
+ end
45
+
46
+ def remote_tab_pane url, tag_id, default
47
+ active = current_page?(url) || tag_id == default
48
+ tab_class = 'tab-pane fade'
49
+ tab_class << ' active in' if active
50
+ content_tag :div, class: tab_class, id: tag_id do
51
+ yield active if block_given?
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,17 @@
1
+ module Golden::Theme
2
+ module CommonHelper
3
+ def yes_or_no value
4
+ value ? t('helpers.yes') : t('helpers.no')
5
+ end
6
+
7
+ def yes_or_no_or_na value
8
+ return t('helpers.not_available') if value.nil?
9
+ yes_or_no value
10
+ end
11
+
12
+ def value_or_na value
13
+ return t('helpers.not_available') if value.blank?
14
+ value
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ module Golden::Theme::Devise
2
+ module UserHelper
3
+ def link_to_user_sign_up
4
+ text ||= t('.sign_up')
5
+ link_to text, main_app.new_user_registration_path
6
+ end
7
+
8
+ def link_to_user_sign_in text = nil
9
+ text ||= t('.sign_in')
10
+ link_to text, main_app.new_user_session_path
11
+ end
12
+
13
+ def link_to_user_sign_out
14
+ text = t('.sign_out')
15
+ link_to text, main_app.destroy_user_session_path, method: :delete
16
+ end
17
+
18
+ def link_to_edit_user_profile
19
+ text = t('.edit_profile')
20
+ link_to text, main_app.edit_user_registration_path
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,10 @@
1
+ <header class="hidden">
2
+ <h5><%= t('.title') %></h5>
3
+ </header>
4
+
5
+ <div class="messages">
6
+ <% flash.each do |key, value| %>
7
+ <% next if %w(timedout).include? key.to_s %>
8
+ <%= flash_box key, value %>
9
+ <% end %>
10
+ </div>
@@ -0,0 +1,24 @@
1
+ <header class="navbar navbar-inverse navbar-fixed-top" role="navigation">
2
+ <div class="container">
3
+ <div class="navbar-header">
4
+ <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
5
+ <span class="sr-only"><%= t('.nav_toggle') %></span>
6
+ <span class="icon-bar"></span>
7
+ <span class="icon-bar"></span>
8
+ <span class="icon-bar"></span>
9
+ </button>
10
+ <hgroup id="site-name">
11
+ <h1><%= link_to t('.site_title'), main_app.root_url, class: 'navbar-brand' %></h1>
12
+ </hgroup>
13
+ </div>
14
+
15
+ <div class="collapse navbar-collapse">
16
+ <nav role="main-navigation" id="main-navigation">
17
+ <%= render 'application/bootstrap/main_navigation' %>
18
+ </nav>
19
+ <aside role="user-navigation" id="user-navigation">
20
+ <%= render 'application/bootstrap/user_navigation' %>
21
+ </aside>
22
+ </div>
23
+ </div>
24
+ </header>
@@ -0,0 +1,8 @@
1
+ <header class="hidden">
2
+ <h5><%= t('.title') %></h5>
3
+ </header>
4
+
5
+ <div>
6
+ <%= render_list class: 'nav navbar-nav' do |li|
7
+ end %>
8
+ </div>
@@ -0,0 +1,9 @@
1
+ <%= will_paginate(collection, {
2
+ renderer: Golden::Theme::Bootstrap::LinkRenderer,
3
+ inner_window: 2,
4
+ outer_window: 0,
5
+ class: 'pagination',
6
+ previous_label: t('.previous_label'),
7
+ next_label: t('.next_label'),
8
+ params: params || {}
9
+ }) %>
@@ -0,0 +1,22 @@
1
+ <header class="hidden">
2
+ <h5><%= t('.title') %></h5>
3
+ </header>
4
+
5
+ <div id="user-identity">
6
+ <%= render_list class: 'nav navbar-nav pull-right' do |li|
7
+ if signed_in?
8
+ li << [
9
+ dropdown_toggle(current_user.name),
10
+ dropdown_menu do |li2|
11
+ li2 << link_to_edit_user_profile
12
+ li2 << ['', class: 'divider']
13
+ li2 << link_to_user_sign_out
14
+ end,
15
+ { class: 'dropdown' }
16
+ ]
17
+ else
18
+ li << link_to_user_sign_up
19
+ li << link_to_user_sign_in
20
+ end
21
+ end %>
22
+ </div>
@@ -0,0 +1,19 @@
1
+ en:
2
+ application:
3
+ flash_messages:
4
+ title: 'Flash messages'
5
+ bootstrap:
6
+ header:
7
+ nav_toggle: 'Toggle navigation'
8
+ site_title: 'GoldenTheme'
9
+ main_navigation:
10
+ title: 'Main navigation'
11
+ user_navigation:
12
+ title: 'User navigation'
13
+ sign_up: 'Sign Up'
14
+ sign_in: 'Sign In'
15
+ sign_out: 'Sign Out'
16
+ edit_profile: 'Edit Profile'
17
+ pagination:
18
+ previous_label: '&larr;'
19
+ next_label: '&rarr;'
@@ -0,0 +1,19 @@
1
+ zh-TW:
2
+ application:
3
+ flash_messages:
4
+ title: '動態訊息'
5
+ bootstrap:
6
+ header:
7
+ nav_toggle: '切換導覽列'
8
+ site_title: 'GoldenTheme'
9
+ main_navigation:
10
+ title: '網站導覽'
11
+ user_navigation:
12
+ title: '用戶導覽'
13
+ sign_up: '註冊'
14
+ sign_in: '登入'
15
+ sign_out: '登出'
16
+ edit_profile: '編輯個人資料'
17
+ pagination:
18
+ previous_label: '&larr;'
19
+ next_label: '&rarr;'
@@ -0,0 +1,25 @@
1
+ en:
2
+ helpers:
3
+ index: 'Index'
4
+ show: 'Show'
5
+ new: 'New'
6
+ edit: 'Edit'
7
+ destroy: 'Destroy'
8
+ are_you_sure: 'Are you sure?'
9
+ actions: 'Actions'
10
+ preview: 'Preview'
11
+ cancel: 'Cancel'
12
+ save: 'Save'
13
+ close: 'Close'
14
+ search: 'Search'
15
+ download: 'Download'
16
+ upload: 'Upload'
17
+ export: 'Export'
18
+ previous_step: 'Previous step'
19
+ next_step: 'Next step'
20
+ skip: 'Skip'
21
+ finish: 'Finish'
22
+ 'yes': 'Yes'
23
+ 'no': 'No'
24
+ not_available: '(Not Available)'
25
+ posted_by: 'Posted by %{name}'
@@ -0,0 +1,25 @@
1
+ zh-TW:
2
+ helpers:
3
+ index: '列表'
4
+ show: '顯示'
5
+ new: '新增'
6
+ edit: '編輯'
7
+ destroy: '刪除'
8
+ are_you_sure: '你確定嗎?'
9
+ actions: '動作'
10
+ preview: '預覽'
11
+ cancel: '取消'
12
+ save: '儲存'
13
+ close: '關閉'
14
+ search: '搜尋'
15
+ download: '下載'
16
+ upload: '上傳'
17
+ export: '匯出'
18
+ previous_step: '上一步'
19
+ next_step: '下一步'
20
+ skip: '略過'
21
+ finish: '完成'
22
+ 'yes': '是'
23
+ 'no': '否'
24
+ not_available: '(尚無資料)'
25
+ posted_by: '由 %{name} 發佈'
@@ -0,0 +1,33 @@
1
+ zh-TW:
2
+ will_paginate:
3
+ previous_label: "&#8592; 上一頁"
4
+ next_label: "下ㄧ頁 &#8594;"
5
+ page_gap: "&hellip;"
6
+
7
+ page_entries_info:
8
+ single_page:
9
+ zero: "沒有找到任何 %{model} 資料"
10
+ one: "顯示 1 筆 %{model} 資料"
11
+ other: "顯示所有 %{count} 筆 %{model} 資料"
12
+ single_page_html:
13
+ zero: "沒有找到任何 %{model} 資料"
14
+ one: "顯示 <b>1</b> 筆 %{model} 資料"
15
+ other: "顯示所有 <b>%{count}</b> 筆 %{model}"
16
+
17
+ multi_page: "顯示第 %{from} 到 %{to} 筆 %{model} 資料,總計 %{count} 筆"
18
+ multi_page_html: "顯示第 <b>%{from}</b> 到 <b>%{to}</b> 筆 %{model} 資料,總計 <b>%{count}</b> 筆"
19
+
20
+ # models:
21
+ # entry:
22
+ # zero: entries
23
+ # one: entry
24
+ # few: entries
25
+ # other: entries
26
+
27
+ # line_item:
28
+ # page_entries_info:
29
+ # single_page:
30
+ # zero: "Your shopping cart is empty"
31
+ # one: "Displaying one item in your cart"
32
+ # other: "Displaying all %{count} items"
33
+ # multi_page: "Displaying items %{from} - %{to} of %{count} in total"
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'golden/theme/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'golden-theme'
8
+ spec.version = Golden::Theme::VERSION
9
+ spec.authors = ['Tse-Ching Ho']
10
+ spec.email = ['tsechingho@gmail.com']
11
+ spec.summary = %q{Provide theme helpers for Rails.}
12
+ spec.description = %q{Provide theme helpers for Rails.}
13
+ spec.homepage = 'https://github.com/goldenio/golden-theme'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'rake'
23
+
24
+ spec.add_dependency 'sass-rails'
25
+ spec.add_dependency 'bootstrap-sass'
26
+ spec.add_dependency 'compass-rails'
27
+
28
+ spec.add_dependency 'coffee-rails'
29
+ spec.add_dependency 'jquery-rails'
30
+ spec.add_dependency 'jquery-ui-rails'
31
+
32
+ spec.add_dependency 'chosen-rails'
33
+ spec.add_dependency 'will_paginate'
34
+ end
@@ -0,0 +1,16 @@
1
+ require 'golden/theme/version'
2
+
3
+ require 'bootstrap-sass'
4
+ require 'compass-rails'
5
+ require 'jquery-ui-rails'
6
+ require 'chosen-rails'
7
+ require 'will_paginate'
8
+ require 'will_paginate/array'
9
+
10
+ module Golden
11
+ module Theme
12
+ end
13
+ end
14
+
15
+ require 'golden/theme/engine'
16
+ require 'golden/theme/bootstrap/link_renderer'
@@ -0,0 +1,63 @@
1
+ require 'will_paginate/view_helpers/action_view'
2
+
3
+ # you can just use pagination with ajax or not:
4
+ #
5
+ # 1) settings for ajax pagination, ex:
6
+ #
7
+ # Golden::Theme::Bootstrap::LinkRenderer.link_options = {
8
+ # 'data-remote' => true,
9
+ # 'data-type' => :html,
10
+ # 'data-toggle' => 'tab',
11
+ # 'data-target' => "##{state_name}"
12
+ # }
13
+ #
14
+ # 2) use in views:
15
+ #
16
+ # will_paginate(collection, {
17
+ # renderer: Golden::Theme::Bootstrap::LinkRenderer,
18
+ # inner_window: 2,
19
+ # outer_window: 0,
20
+ # class: 'pagination',
21
+ # previous_label: '&larr;'.html_safe,
22
+ # next_label: '&rarr;'.html_safe
23
+ # })
24
+ #
25
+ module Golden::Theme
26
+ module Bootstrap
27
+ class LinkRenderer < ::WillPaginate::ActionView::LinkRenderer
28
+ cattr_accessor :link_options
29
+
30
+ protected
31
+
32
+ def html_container(html)
33
+ tag :ul, html, container_attributes
34
+ end
35
+
36
+ def page_number(page)
37
+ options = { rel: rel_value(page) }
38
+ options.deep_merge! link_options unless link_options.blank?
39
+ unless page == current_page
40
+ tag :li, link(page, page, options)
41
+ else
42
+ tag :li, link(page, nil, {}), class: 'active'
43
+ end
44
+ end
45
+
46
+ def gap
47
+ tag :li, link(super, nil), class: 'disabled'
48
+ end
49
+
50
+ def previous_or_next_page(page, text, class_name)
51
+ options = {}
52
+ options.deep_merge! link_options unless link_options.blank?
53
+
54
+ class_name = "#{class_name} #{class_name[0..3]}"
55
+ if page
56
+ tag :li, link(text, page, options), class: class_name
57
+ else
58
+ tag :li, link(text, nil, {}), class: class_name + ' disabled'
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,6 @@
1
+ module Golden
2
+ module Theme
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Golden
2
+ module Theme
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,221 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: golden-theme
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tse-Ching Ho
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sass-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bootstrap-sass
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: compass-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coffee-rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: jquery-rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: jquery-ui-rails
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: chosen-rails
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: will_paginate
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Provide theme helpers for Rails.
154
+ email:
155
+ - tsechingho@gmail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - Gemfile
162
+ - LICENSE.txt
163
+ - README.md
164
+ - Rakefile
165
+ - app/assets/javascripts/golden/theme/bootstrap.js
166
+ - app/assets/javascripts/golden/theme/bootstrap/ajax-chosen.js.coffee
167
+ - app/assets/javascripts/golden/theme/bootstrap/ajax-tabs.js.coffee
168
+ - app/assets/javascripts/golden/theme/bootstrap/bench-util-jquery.js.coffee
169
+ - app/assets/javascripts/golden/theme/bootstrap/modal.js.coffee
170
+ - app/assets/stylesheets/golden/theme/bootstrap.css
171
+ - app/assets/stylesheets/golden/theme/bootstrap/devise.css.sass
172
+ - app/controllers/concerns/golden/theme/bootstrap/pagination.rb
173
+ - app/helpers/golden/theme/bootstrap/alert_helper.rb
174
+ - app/helpers/golden/theme/bootstrap/button_helper.rb
175
+ - app/helpers/golden/theme/bootstrap/common_helper.rb
176
+ - app/helpers/golden/theme/bootstrap/dropdown_helper.rb
177
+ - app/helpers/golden/theme/bootstrap/link_helper.rb
178
+ - app/helpers/golden/theme/bootstrap/modal_helper.rb
179
+ - app/helpers/golden/theme/bootstrap/tab_helper.rb
180
+ - app/helpers/golden/theme/common_helper.rb
181
+ - app/helpers/golden/theme/devise/user_helper.rb
182
+ - app/views/application/_flash_messages.html.erb
183
+ - app/views/application/bootstrap/_header.html.erb
184
+ - app/views/application/bootstrap/_main_navigation.html.erb
185
+ - app/views/application/bootstrap/_pagination.html.erb
186
+ - app/views/application/bootstrap/_user_navigation.html.erb
187
+ - config/locales/application.en.yml
188
+ - config/locales/application.zh-TW.yml
189
+ - config/locales/helpers.en.yml
190
+ - config/locales/helpers.zh-TW.yml
191
+ - config/locales/will_paginate.zh-TW.yml
192
+ - golden-theme.gemspec
193
+ - lib/golden/theme.rb
194
+ - lib/golden/theme/bootstrap/link_renderer.rb
195
+ - lib/golden/theme/engine.rb
196
+ - lib/golden/theme/version.rb
197
+ homepage: https://github.com/goldenio/golden-theme
198
+ licenses:
199
+ - MIT
200
+ metadata: {}
201
+ post_install_message:
202
+ rdoc_options: []
203
+ require_paths:
204
+ - lib
205
+ required_ruby_version: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ">="
208
+ - !ruby/object:Gem::Version
209
+ version: '0'
210
+ required_rubygems_version: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: '0'
215
+ requirements: []
216
+ rubyforge_project:
217
+ rubygems_version: 2.2.2
218
+ signing_key:
219
+ specification_version: 4
220
+ summary: Provide theme helpers for Rails.
221
+ test_files: []