mokio 0.0.9 → 0.0.10
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.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/backend/icons.css.scss +2 -2
- data/app/models/mokio/content.rb +2 -2
- data/app/views/mokio/articles/_form.html.slim +2 -2
- data/app/views/mokio/menus/_menu.html.slim +2 -2
- data/config/initializers/ckeditor.rb +1 -1
- data/config/locales/en.yml +4 -3
- data/config/locales/pl.yml +3 -2
- data/db/migrate/20141209072051_change_data_type_for_display_dates.rb +8 -0
- data/db/migrate/20141209101853_add_menu_css_options.rb +6 -0
- data/lib/generators/mokio/ga_script_generator.rb +26 -0
- data/lib/generators/mokio/positions_generator.rb +14 -0
- data/lib/generators/mokio/templates/_google_analytics.html.slim +3 -0
- data/lib/mokio.rb +1 -0
- data/lib/mokio/concerns/models/content.rb +17 -1
- data/lib/mokio/concerns/models/menu.rb +25 -8
- data/lib/mokio/engine.rb +1 -0
- data/lib/mokio/frontend_helpers.rb +1 -0
- data/lib/mokio/frontend_helpers/external_scripts_helper.rb +7 -10
- data/lib/mokio/frontend_helpers/langs_helper.rb +31 -0
- data/lib/mokio/frontend_helpers/menu_helper.rb +170 -1
- data/lib/mokio/slugged.rb +17 -0
- data/lib/mokio/version.rb +1 -1
- metadata +9 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8d9580cc7a530c2fa75974d77e5b22e972a83619
|
|
4
|
+
data.tar.gz: 720f18e51b6d58b2a7bb31e10bbb27e890b37a29
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2dc1cd4ff618b9bfc077e9cbb6ce05eaccf69024d7e39d2fd6ed139b1a7fa9bc4f5a896c93b6b0075bfe3f59d4d340ce4dd65355cd261fb0d973a489b1415478
|
|
7
|
+
data.tar.gz: fb8eeb931e6bb4195152c91147433e802223ecf47010b9e62ab7adc2ffbaebe73297154d7cd61618ced3c0084a386e98195f6c17d2cb57c0c176f9ce8dde094c
|
|
@@ -5699,7 +5699,7 @@
|
|
|
5699
5699
|
*margin-right: .3em;
|
|
5700
5700
|
line-height: 14px;
|
|
5701
5701
|
vertical-align: text-top;
|
|
5702
|
-
background-image: url("backend/glyphicons-halflings.png");
|
|
5702
|
+
background-image: image-url("backend/glyphicons-halflings.png");
|
|
5703
5703
|
background-position: 14px 14px;
|
|
5704
5704
|
background-repeat: no-repeat;
|
|
5705
5705
|
}
|
|
@@ -5713,7 +5713,7 @@
|
|
|
5713
5713
|
.dropdown-menu > li > a:hover > [class*=" icon-"],
|
|
5714
5714
|
.dropdown-menu > .active > a > [class^="icon-"],
|
|
5715
5715
|
.dropdown-menu > .active > a > [class*=" icon-"] {
|
|
5716
|
-
background-image: url("backend/glyphicons-halflings-white.png");
|
|
5716
|
+
background-image: image-url("backend/glyphicons-halflings-white.png");
|
|
5717
5717
|
}
|
|
5718
5718
|
|
|
5719
5719
|
.icon-glass {
|
data/app/models/mokio/content.rb
CHANGED
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
# gallery_type :string(255)
|
|
16
16
|
# editable :boolean default(TRUE)
|
|
17
17
|
# deletable :boolean default(TRUE)
|
|
18
|
-
# display_from :
|
|
19
|
-
# display_to :
|
|
18
|
+
# display_from :datetime
|
|
19
|
+
# display_to :datetime
|
|
20
20
|
# created_at :datetime
|
|
21
21
|
# updated_at :datetime
|
|
22
22
|
# meta_id :integer
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
= f.input :title, disabled: !obj.display_editable_field?('title')
|
|
6
6
|
= f.input :intro, :wrapper => :ckeditor, :as => :ckeditor, :input_html => { :ckeditor => {:toolbar => 'Mini', :height => 150} }, disabled: !obj.display_editable_field?('intro')
|
|
7
7
|
= f.input :content, :wrapper => :ckeditor, :as => :ckeditor, :input_html => { :ckeditor => {:toolbar => 'Medium', :height => 400} }, disabled: !obj.display_editable_field?('content')
|
|
8
|
-
= f.input :display_from, :wrapper => :date, :as => :string, :input_html => { :class => "mask-date display_from", :value => (localize(f.object.display_from) if f.object.display_from) }, disabled: !obj.display_editable_field?('display_from')
|
|
9
|
-
= f.input :display_to, :wrapper => :date, :as => :string, :input_html => { :class => "mask-date display_to", :value => (localize(f.object.display_to) if f.object.display_to) }, disabled: !obj.display_editable_field?('display_to')
|
|
8
|
+
= f.input :display_from, :wrapper => :date, :as => :string, :input_html => { :class => "mask-date display_from", :value => (localize(f.object.display_from, :format => :datepicker) if f.object.display_from) }, disabled: !obj.display_editable_field?('display_from')
|
|
9
|
+
= f.input :display_to, :wrapper => :date, :as => :string, :input_html => { :class => "mask-date display_to", :value => (localize(f.object.display_to, :format => :datepicker) if f.object.display_to) }, disabled: !obj.display_editable_field?('display_to')
|
|
10
10
|
.row-fluid
|
|
11
11
|
label.form-label.span2
|
|
12
12
|
= t('menus.content_assoc')
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
div class=("menu_div active_#{menu.active} visible_#{menu.visible} fake_#{menu.fake}")
|
|
3
3
|
- if menu.fake
|
|
4
4
|
span.menu_name
|
|
5
|
-
= menu.name
|
|
5
|
+
= "#{menu.name} (ID: #{menu.id})"
|
|
6
6
|
- else
|
|
7
7
|
- if menu.invisible_content
|
|
8
8
|
span.warning
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
span.blank
|
|
12
12
|
| !
|
|
13
13
|
span.menu_name
|
|
14
|
-
= link_to menu.name, edit_url(menu.class, menu)
|
|
14
|
+
= link_to "#{menu.name} (ID: #{menu.id})", edit_url(menu.class, menu)
|
|
15
15
|
span.menu_details
|
|
16
16
|
span.content_type
|
|
17
17
|
= menu.content_type
|
|
@@ -8,7 +8,7 @@ Ckeditor.setup do |config|
|
|
|
8
8
|
|
|
9
9
|
# Allowed image file types for upload.
|
|
10
10
|
# Set to nil or [] (empty array) for all file types
|
|
11
|
-
|
|
11
|
+
config.image_file_types = ["jpg", "jpeg", "png", "gif", "tiff", "svg"]
|
|
12
12
|
|
|
13
13
|
# Allowed attachment file types for upload.
|
|
14
14
|
# Set to nil or [] (empty array) for all file types
|
data/config/locales/en.yml
CHANGED
|
@@ -23,6 +23,7 @@ en:
|
|
|
23
23
|
time:
|
|
24
24
|
formats:
|
|
25
25
|
default: "%d-%m-%Y"
|
|
26
|
+
datepicker: "%d-%m-%Y %H:%M"
|
|
26
27
|
date:
|
|
27
28
|
formats:
|
|
28
29
|
default: "%d-%m-%Y"
|
|
@@ -575,9 +576,8 @@ en:
|
|
|
575
576
|
dayNamesShort: "Sun,Mon,Tue,Wed,Thu,Fri,Sat"
|
|
576
577
|
dayNamesMin: "Su,Mo,Tu,We,Th,Fr,Sa"
|
|
577
578
|
weekHeader: "Wk"
|
|
578
|
-
mask: "99/99/9999"
|
|
579
|
-
|
|
580
|
-
dateFormat: "mm/dd/yy"
|
|
579
|
+
mask: "99/99/9999 99:99"
|
|
580
|
+
dateFormat: "dd/mm/yy"
|
|
581
581
|
firstDay: "0"
|
|
582
582
|
isRTL: "0"
|
|
583
583
|
showMonthAfterYear: "0"
|
|
@@ -652,6 +652,7 @@ en:
|
|
|
652
652
|
password_confirmation:
|
|
653
653
|
confirmation: Passwords do not match
|
|
654
654
|
email:
|
|
655
|
+
taken: Given e-mail address is taken
|
|
655
656
|
blank: Email cannot be empty
|
|
656
657
|
invalid: Provided an incorrect e-mail address
|
|
657
658
|
editable:
|
data/config/locales/pl.yml
CHANGED
|
@@ -23,6 +23,7 @@ pl:
|
|
|
23
23
|
time:
|
|
24
24
|
formats:
|
|
25
25
|
default: "%d-%m-%Y"
|
|
26
|
+
datepicker: "%d-%m-%Y %H:%M"
|
|
26
27
|
date:
|
|
27
28
|
formats:
|
|
28
29
|
default: "%d-%m-%Y"
|
|
@@ -575,8 +576,7 @@ pl:
|
|
|
575
576
|
dayNamesShort: "Nie,Pn,Wt,Śr,Czw,Pt,So"
|
|
576
577
|
dayNamesMin: "N,Pn,Wt,Śr,Cz,Pt,So"
|
|
577
578
|
weekHeader: "Tydz"
|
|
578
|
-
mask: 99-99-9999
|
|
579
|
-
maskFormat: dd-MM-yyyy
|
|
579
|
+
mask: 99-99-9999 99:99
|
|
580
580
|
dateFormat: "dd-mm-yy"
|
|
581
581
|
firstDay: "1"
|
|
582
582
|
isRTL: "0"
|
|
@@ -652,6 +652,7 @@ pl:
|
|
|
652
652
|
password_confirmation:
|
|
653
653
|
confirmation: Hasła się nie zgadzają
|
|
654
654
|
email:
|
|
655
|
+
taken: Podany adres e-mail jest już zajęty
|
|
655
656
|
blank: Proszę wpisać adres email
|
|
656
657
|
invalid: Podano nieprawidłowy adres e-mail
|
|
657
658
|
editable:
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Mokio
|
|
2
|
+
class GaScriptGenerator < Rails::Generators::Base #:nodoc:
|
|
3
|
+
source_root File.expand_path("../templates", __FILE__)
|
|
4
|
+
argument :uid, :type => :string
|
|
5
|
+
desc "Creates Google Analytics script and partial view"
|
|
6
|
+
|
|
7
|
+
def create_script
|
|
8
|
+
script = <<TEXT
|
|
9
|
+
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
|
10
|
+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
|
11
|
+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
|
12
|
+
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
|
13
|
+
|
|
14
|
+
ga('create', '#{uid}', 'auto');
|
|
15
|
+
ga('send', 'pageview');
|
|
16
|
+
TEXT
|
|
17
|
+
Mokio::ExternalScript.create(:name => "Google Analytics", :script =>script)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def create_view
|
|
21
|
+
puts "Paste it into your layout body: " + "= render :partial => 'frontend/layout_elements/google_analytics'".green
|
|
22
|
+
template "_google_analytics.html.slim", "app/views/frontend/layout_elements/_google_analytics.html.slim"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Mokio
|
|
2
|
+
class PositionsGenerator < Rails::Generators::Base #:nodoc:
|
|
3
|
+
argument :names, :type => :array
|
|
4
|
+
|
|
5
|
+
desc "Creates module positions"
|
|
6
|
+
def create_positions
|
|
7
|
+
names.each do |name|
|
|
8
|
+
Mokio::ModulePosition.create(:name => name)
|
|
9
|
+
puts "Successfully created #{name.green} position."
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
end
|
data/lib/mokio.rb
CHANGED
|
@@ -10,7 +10,7 @@ module Mokio
|
|
|
10
10
|
included do
|
|
11
11
|
include Mokio::Concerns::Models::Common
|
|
12
12
|
|
|
13
|
-
has_many :content_links
|
|
13
|
+
has_many :content_links, :dependent => :destroy
|
|
14
14
|
has_many :data_files, :dependent => :destroy
|
|
15
15
|
has_many :menus, :through => :content_links
|
|
16
16
|
|
|
@@ -30,8 +30,13 @@ module Mokio
|
|
|
30
30
|
scope :lang, -> (lang_id) { where('lang_id = ? or lang_id is null', lang_id) }
|
|
31
31
|
scope :order_default, -> { order("seq asc") }
|
|
32
32
|
scope :active, -> { where(active: true) }
|
|
33
|
+
scope :_displayed_from, -> { where("display_from < ? OR display_from IS NULL", Time.zone.now) }
|
|
34
|
+
scope :_displayed_to, -> { where("display_to > ? OR display_to IS NULL", Time.zone.now) }
|
|
35
|
+
scope :displayed, -> { active._displayed_from._displayed_to}
|
|
36
|
+
|
|
33
37
|
scope :order_created, -> { reorder(nil).order('created_at DESC') }
|
|
34
38
|
|
|
39
|
+
before_save :update_display_to
|
|
35
40
|
after_save :update_etag
|
|
36
41
|
|
|
37
42
|
self.per_page = 15
|
|
@@ -53,6 +58,17 @@ module Mokio
|
|
|
53
58
|
self.touch(:etag)
|
|
54
59
|
end
|
|
55
60
|
|
|
61
|
+
|
|
62
|
+
#
|
|
63
|
+
# Update display_to field: set time to 23:59:59 if time is set to 00:00:00
|
|
64
|
+
#
|
|
65
|
+
def update_display_to
|
|
66
|
+
if self.display_to && self.display_to.time.strftime("%H:%M") == "00:00"
|
|
67
|
+
updated = self.display_to.end_of_day
|
|
68
|
+
self.display_to = updated
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
56
72
|
#
|
|
57
73
|
# Output for title field
|
|
58
74
|
#
|
|
@@ -53,6 +53,16 @@ module Mokio
|
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
+
module ClassMethods
|
|
57
|
+
#
|
|
58
|
+
# Columns for table - needed for coping a menu
|
|
59
|
+
#
|
|
60
|
+
def columns_for_table
|
|
61
|
+
%w(name active updated_at lang_id)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
|
|
56
66
|
#
|
|
57
67
|
# Friendly_id slug_candidates (<b>gem 'friendly_id'</b>)
|
|
58
68
|
#
|
|
@@ -65,7 +75,7 @@ module Mokio
|
|
|
65
75
|
|
|
66
76
|
def build_slug
|
|
67
77
|
if parent.nil?
|
|
68
|
-
|
|
78
|
+
''
|
|
69
79
|
elsif !parent.fake
|
|
70
80
|
parent.slug
|
|
71
81
|
else
|
|
@@ -88,7 +98,7 @@ module Mokio
|
|
|
88
98
|
# Returns list of contents available for assignment to given menu element (based on lang_id) ordered by title
|
|
89
99
|
#
|
|
90
100
|
def available_contents
|
|
91
|
-
if
|
|
101
|
+
if lang_id.nil? || lang_id == 0
|
|
92
102
|
Mokio::Content.lang(Mokio::Lang.first.id).order(:title) - contents
|
|
93
103
|
else
|
|
94
104
|
Mokio::Content.lang(lang_id).order(:title) - contents
|
|
@@ -124,7 +134,7 @@ module Mokio
|
|
|
124
134
|
#
|
|
125
135
|
def available_modules_by_pos
|
|
126
136
|
menu_id = (self.id.nil? ? -1 : self.id)
|
|
127
|
-
if
|
|
137
|
+
if lang_id.nil? || lang_id == 0
|
|
128
138
|
Mokio::AvailableModule.not_selected_for_menu(menu_id).for_lang(Mokio::Lang.first.id).group_by(&:module_position_id)
|
|
129
139
|
else
|
|
130
140
|
Mokio::AvailableModule.not_selected_for_menu(menu_id).for_lang(lang_id).group_by(&:module_position_id)
|
|
@@ -164,11 +174,11 @@ module Mokio
|
|
|
164
174
|
end
|
|
165
175
|
|
|
166
176
|
def content_type
|
|
167
|
-
if
|
|
177
|
+
if contents.length > 1
|
|
168
178
|
I18n.t('menus.list').titleize
|
|
169
|
-
elsif
|
|
179
|
+
elsif contents.length == 1
|
|
170
180
|
I18n.t(contents[0].type.underscore).titleize
|
|
171
|
-
elsif
|
|
181
|
+
elsif !external_link.blank?
|
|
172
182
|
I18n.t('external_link', Menu).titleize
|
|
173
183
|
else
|
|
174
184
|
''
|
|
@@ -176,7 +186,7 @@ module Mokio
|
|
|
176
186
|
end
|
|
177
187
|
|
|
178
188
|
#
|
|
179
|
-
#
|
|
189
|
+
# Returns always editable fields
|
|
180
190
|
#
|
|
181
191
|
def always_editable_fields
|
|
182
192
|
@always = %w(active seq visible always_displayed ancestry)
|
|
@@ -191,13 +201,20 @@ module Mokio
|
|
|
191
201
|
def full_slug
|
|
192
202
|
m = self
|
|
193
203
|
slug = m.slug
|
|
194
|
-
unless m.parent.nil?
|
|
204
|
+
unless m.parent.nil? || slug.nil?
|
|
195
205
|
while !m.parent.fake
|
|
196
206
|
slug = m.parent.slug + "/" + slug
|
|
197
207
|
m = m.parent
|
|
198
208
|
end
|
|
199
209
|
slug
|
|
200
210
|
end
|
|
211
|
+
slug
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
# Real slug - menu slug hierarchical or not, with lang prefix or not
|
|
215
|
+
|
|
216
|
+
def real_slug (hierarchical)
|
|
217
|
+
"/#{hierarchical ? full_slug : slug}"
|
|
201
218
|
end
|
|
202
219
|
|
|
203
220
|
#
|
data/lib/mokio/engine.rb
CHANGED
|
@@ -35,6 +35,7 @@ module Mokio
|
|
|
35
35
|
ActionView::Base.send :include, Mokio::FrontendHelpers::StaticModulesHelper
|
|
36
36
|
ActionView::Base.send :include, Mokio::FrontendHelpers::ContentHelper
|
|
37
37
|
ActionView::Base.send :include, Mokio::FrontendHelpers::ExternalScriptsHelper
|
|
38
|
+
ActionView::Base.send :include, Mokio::FrontendHelpers::LangsHelper
|
|
38
39
|
end
|
|
39
40
|
end
|
|
40
41
|
|
|
@@ -13,11 +13,8 @@ module Mokio
|
|
|
13
13
|
# * +script_name+ - external script name from mokio_external_scripts
|
|
14
14
|
|
|
15
15
|
def build_external_script(script_name)
|
|
16
|
-
html = "";
|
|
17
16
|
result = Mokio::ExternalScript.find_by(name:script_name)
|
|
18
|
-
|
|
19
|
-
html = build_common(result)
|
|
20
|
-
end
|
|
17
|
+
html = result.blank? ? "" : build_common(result)
|
|
21
18
|
html.html_safe
|
|
22
19
|
end
|
|
23
20
|
|
|
@@ -29,9 +26,9 @@ module Mokio
|
|
|
29
26
|
# * +result+ - all external scripts from mokio_external_scripts
|
|
30
27
|
|
|
31
28
|
def build_all_external_scripts
|
|
32
|
-
html = ""
|
|
29
|
+
html = ""
|
|
33
30
|
result = Mokio::ExternalScript.all
|
|
34
|
-
|
|
31
|
+
unless result.blank?
|
|
35
32
|
result.each do |position|
|
|
36
33
|
html = build_common(position)
|
|
37
34
|
end
|
|
@@ -50,12 +47,12 @@ module Mokio
|
|
|
50
47
|
# * +obj.script+ - external script content from mokio_external_scripts
|
|
51
48
|
# * +obj.name+ - external script name from mokio_external_scripts
|
|
52
49
|
|
|
53
|
-
def build_common(obj)
|
|
50
|
+
def build_common(obj, html_comments = false)
|
|
54
51
|
html = ""
|
|
55
|
-
|
|
56
|
-
html << "<!--#{obj.name} - EXTERNAL SCRIPT START-->\n"
|
|
52
|
+
unless obj.blank?
|
|
53
|
+
html << "<!--#{obj.name} - EXTERNAL SCRIPT START-->\n" if html_comments
|
|
57
54
|
html << obj.script + "\n"
|
|
58
|
-
html << "<!--#{obj.name} END -->\n"
|
|
55
|
+
html << "<!--#{obj.name} END -->\n" if html_comments
|
|
59
56
|
html.html_safe
|
|
60
57
|
end
|
|
61
58
|
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module Mokio
|
|
2
|
+
module FrontendHelpers
|
|
3
|
+
#
|
|
4
|
+
# Frontend helper methods used with Mokio::Lang objects
|
|
5
|
+
#
|
|
6
|
+
module LangsHelper
|
|
7
|
+
#
|
|
8
|
+
# Builds forms with buttons to choose site language
|
|
9
|
+
# Pass your controller action path and check params[:lang_code]
|
|
10
|
+
#
|
|
11
|
+
# ==== Attributes
|
|
12
|
+
#
|
|
13
|
+
# * +controller_action+ - your controller action path (e.g. "content_home_path")
|
|
14
|
+
# * +image_folder+ - folder where helper will search country flag images (default: "langs" - searched in app/assets/images/langs)
|
|
15
|
+
# * +submit_class+ - submit buttons css class (defaut: "btn-lang-submit")
|
|
16
|
+
# * +image_ext+ - language flag image extension(defaut: "png")
|
|
17
|
+
#
|
|
18
|
+
def build_lang_menu(controller_action, image_folder = "langs", submit_class = "btn-lang-submit", image_ext = "png")
|
|
19
|
+
html = ""
|
|
20
|
+
Mokio::Lang.active.each do |lang|
|
|
21
|
+
lang_form = form_tag(controller_action, :id => "#{lang.shortname}_lang_form") do
|
|
22
|
+
hidden_field_tag("lang_code", lang.shortname) +
|
|
23
|
+
image_submit_tag("#{image_folder}/#{lang.shortname}.#{image_ext}", :class => submit_class)
|
|
24
|
+
end
|
|
25
|
+
html << lang_form
|
|
26
|
+
end
|
|
27
|
+
html.html_safe
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -6,7 +6,7 @@ module Mokio
|
|
|
6
6
|
module MenuHelper
|
|
7
7
|
|
|
8
8
|
#
|
|
9
|
-
# Builds menu tree for specified arguments, returns html
|
|
9
|
+
# Builds menu tree for specified arguments, returns html. Left for backward compatibility. Use build_menu_extended instead.
|
|
10
10
|
#
|
|
11
11
|
# ==== Attributes
|
|
12
12
|
#
|
|
@@ -70,6 +70,7 @@ module Mokio
|
|
|
70
70
|
# * +limit+ - how deep should builder look for children
|
|
71
71
|
# * +index+ - how deep is function already
|
|
72
72
|
#
|
|
73
|
+
|
|
73
74
|
def build_items(item, limit, index, hierarchical = false, root_path = "")
|
|
74
75
|
return "" if index > limit || !item.children.present?
|
|
75
76
|
|
|
@@ -98,6 +99,174 @@ module Mokio
|
|
|
98
99
|
|
|
99
100
|
alias_method :create_menu, :build_menu
|
|
100
101
|
|
|
102
|
+
#
|
|
103
|
+
# Finds proper menu element - based on lang and menu position and calls build_menu_extended for this menu element
|
|
104
|
+
#
|
|
105
|
+
|
|
106
|
+
def build_menu_extended_lang(menu_position_name, lang_code, limit = 999999, include_menu_parent = false, options = {hierarchical: true, with_nav: true, nav_class: "nav_menu", active_class: "active", item_class: nil, item_with_children_class: nil, item_without_children_class: nil, ul_class: nil, ul_wrapper_class: nil, ul_nested_class:nil, ul_nested_wrapper_class:nil, a_class: nil})
|
|
107
|
+
lang = Mokio::Lang.find_by_shortname(lang_code)
|
|
108
|
+
menu_parent = Mokio::Menu.where(lang_id: lang.id, name: menu_position_name) unless lang.blank?
|
|
109
|
+
build_menu_extended(menu_parent.first.id, limit, include_menu_parent, options) unless menu_parent.blank?
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
#
|
|
114
|
+
# Builds menu tree for specified arguments, returns html. Allows specifying css classes and start from any menu element.
|
|
115
|
+
# Menu structure:
|
|
116
|
+
# <nav> (optional)
|
|
117
|
+
# <div class='#{ul_wrapper_class}'>
|
|
118
|
+
# <ul class='#{ul_class}'>
|
|
119
|
+
# <div class='#{item_wrapper_class}'> (optional)
|
|
120
|
+
# <li class='#{item_class} #{item_with_children_class} #{active_class}'>
|
|
121
|
+
# <a>item.slug or item.full_slug</a>
|
|
122
|
+
# <div class='#{ul_nested_wrapper_class}'>
|
|
123
|
+
# <ul class="#{ul_nested_class}">
|
|
124
|
+
# <li class='#{item_class}#{item without_children_class}'>
|
|
125
|
+
# <a class='#{active_class}'>item.slug or item.full_slug</a>
|
|
126
|
+
# </li>
|
|
127
|
+
# <li class='#{item_class}#{item without_children_class}'
|
|
128
|
+
# <a class='#{active_class}'>item.slug or item.full_slug</a>
|
|
129
|
+
# </li>
|
|
130
|
+
# </ul>
|
|
131
|
+
# </div>
|
|
132
|
+
# </li>
|
|
133
|
+
# </div>
|
|
134
|
+
# <li class='#{item_class}#{item without_children_class}'>
|
|
135
|
+
# <a class='#{active_class}'>item.slug or item.full_slug</a>
|
|
136
|
+
# <li>
|
|
137
|
+
# </ul>
|
|
138
|
+
# </div>
|
|
139
|
+
# </nav>
|
|
140
|
+
#
|
|
141
|
+
# ==== Attributes
|
|
142
|
+
#
|
|
143
|
+
# * +menu_parent_id+ - starting menu element's id - this element will be displayed or not and all its children will be displayed
|
|
144
|
+
# * +include_menu_parent+ - whether parent menu element should be displayed or not
|
|
145
|
+
# * +limit+ - how deep should builder look for children, count starts from 1
|
|
146
|
+
# * +options+ - hash with following options:
|
|
147
|
+
# * +hierarchical+ - specifies if you want to use hierarchical links or not
|
|
148
|
+
# * +with_nav+ - whether nav element should be generated
|
|
149
|
+
# * +nav_class+ - css class of the nav element
|
|
150
|
+
# * +active_class+ - css class of the active items
|
|
151
|
+
# * +item_class+ - css class of the items
|
|
152
|
+
# * +item_with_children_class+ - css class of the items that have children
|
|
153
|
+
# * +item_without_children_class+ - css class of the items without children
|
|
154
|
+
# * +ul_class+ - css class of the ul element
|
|
155
|
+
# * +ul_wrapper_class+ - css class of the ul wrapper class, if nil then wrapper for ul will not be generated
|
|
156
|
+
# * +ul_nested_class+ - css class of the nested ul element
|
|
157
|
+
# * +ul_nested_wrapper_class+ - css class of the ul wrapper class, generated only for nested uls, if nil then wrapper for nested ul will not be generated
|
|
158
|
+
# * +a_class+ - css class of the a element
|
|
159
|
+
#* +content_type+ - content types for which we'll build menu items(string or array e.g. "Mokio::Article" OR ["Mokio::Article", "Mokio::PicGallery"])
|
|
160
|
+
#* +content_item_class+ - css class of the content items (not Mokio::Menu, specified above)
|
|
161
|
+
|
|
162
|
+
# if you need hierarchical links in your frontend, add following route to your routes.rb
|
|
163
|
+
|
|
164
|
+
# get "/*menu_path/:menu_id" => "content#show"
|
|
165
|
+
# get "/:menu_id" => "content#show"
|
|
166
|
+
|
|
167
|
+
def build_menu_extended(menu_parent_id, limit = 999999, include_menu_parent = false, options = {})
|
|
168
|
+
|
|
169
|
+
set_options_defaults(options)
|
|
170
|
+
|
|
171
|
+
html = ""
|
|
172
|
+
html = "<nav #{"class='#{options[:nav_class]}'" if options[:nav_class]} id='menuMain'>" if options[:with_nav]
|
|
173
|
+
html << "<div class='#{options[:ul_wrapper_class]}'>" unless options[:ul_wrapper_class].nil?
|
|
174
|
+
html << "<ul #{"class='#{options[:ul_class]}'" if options[:ul_class]}>"
|
|
175
|
+
begin
|
|
176
|
+
menu_parent = Mokio::Menu.find(menu_parent_id)
|
|
177
|
+
if include_menu_parent
|
|
178
|
+
html << build_menu_items_extended(menu_parent, limit, 1, menu_parent.ancestor_ids, options)
|
|
179
|
+
else
|
|
180
|
+
menu_parent.children.order_default.each do |i|
|
|
181
|
+
html << build_menu_items_extended(i, limit, 1, i.ancestor_ids, options)
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
rescue => e
|
|
186
|
+
MOKIO_LOG.error "BUILD MENU ERROR: #{e}"
|
|
187
|
+
end
|
|
188
|
+
html << "</ul>"
|
|
189
|
+
html << "</div>" unless options[:ul_wrapper_class].nil?
|
|
190
|
+
html << "</nav>" if options[:with_nav]
|
|
191
|
+
html.html_safe
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
# Builds menu starting from given menu element (real menu only)
|
|
195
|
+
# - displays all its children
|
|
196
|
+
|
|
197
|
+
def build_menu_items_extended (i, limit, index, active_ids = [], options)
|
|
198
|
+
|
|
199
|
+
return "" if index > limit
|
|
200
|
+
|
|
201
|
+
html = ""
|
|
202
|
+
if i.visible && i.active
|
|
203
|
+
item_class = build_item_class(i, options, active_ids)
|
|
204
|
+
html << "<li #{"class='#{item_class}'" unless item_class.blank?}>"
|
|
205
|
+
|
|
206
|
+
if i.external_link.blank?
|
|
207
|
+
html << "<a #{"class='#{options[:a_class]}'" if options[:a_class]} href='#{i.real_slug(options[:hierarchical])}'>#{i.name}</a>"
|
|
208
|
+
else
|
|
209
|
+
html << "<a #{"class='#{options[:a_class]}'" if options[:a_class]} href='#{i.external_link}' #{"rel='nofollow'" unless i.follow || i.follow.nil?} #{"target='#{i.target}'" unless (i.target.blank? || i.target == '_self') }>#{i.name}</a>"
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
items_html = ""
|
|
213
|
+
|
|
214
|
+
i.children.order_default.each do |item_child|
|
|
215
|
+
items_html << build_menu_items_extended(item_child, limit, index + 1, active_ids, options)
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
content_item_class = [item_class, options[:content_item_class]].compact.join(" ")
|
|
219
|
+
i.contents.displayed.order_default.each do |content|
|
|
220
|
+
next if options[:content_type].blank? || options[:content_type].exclude?(content.type.to_s)
|
|
221
|
+
items_html << "<li #{"class='#{content_item_class}'" unless content_item_class.blank?}>"
|
|
222
|
+
items_html << "<a #{"class='#{options[:a_class]}'" if options[:a_class]} href='#{content.slug}'>#{content.title}</a>" if content.respond_to?("slug")
|
|
223
|
+
items_html << "</li>"
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
unless items_html.empty?
|
|
227
|
+
html << "<div class='#{options[:ul_nested_wrapper_class]}'>" unless options[:ul_nested_wrapper_class].nil?
|
|
228
|
+
html << "<ul #{"class='#{options[:ul_nested_class]}'" if options[:ul_nested_class]}>"
|
|
229
|
+
html << items_html
|
|
230
|
+
html << "</ul>"
|
|
231
|
+
html << "</div>" unless options[:ul_nested_wrapper_class].nil?
|
|
232
|
+
end
|
|
233
|
+
html << "</li>"
|
|
234
|
+
end
|
|
235
|
+
html.html_safe
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
# Builds css class fot one menu item
|
|
240
|
+
|
|
241
|
+
def build_item_class(i, options, active_ids)
|
|
242
|
+
|
|
243
|
+
item_class = []
|
|
244
|
+
|
|
245
|
+
item_class << options[:item_class]
|
|
246
|
+
item_class << i.css_class
|
|
247
|
+
|
|
248
|
+
if i.has_children?
|
|
249
|
+
item_class << options[:item_with_children_class]
|
|
250
|
+
else
|
|
251
|
+
item_class << options[:item_without_children_class]
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
item_class << options[:active_class] if i.slug == params[:menu_id] || i.slug == request.original_fullpath.match(/(\D+\/{1}|\D+)/)[0].gsub('/', '') || active_ids.include?(i.id)
|
|
255
|
+
item_class.compact.join(" ")
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
# Sets default values for build_menu_extended
|
|
260
|
+
|
|
261
|
+
def set_options_defaults(options)
|
|
262
|
+
options[:hierarchical] = true unless options.has_key? :hierarchical
|
|
263
|
+
options[:with_nav] = true unless options.has_key? :with_nav
|
|
264
|
+
options[:nav_class] = "nav_menu" unless options.has_key? :nav_class
|
|
265
|
+
options[:active_class] = "active" unless options.has_key? :active_class
|
|
266
|
+
options[:content_type] = "" unless options.has_key? :content_type
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
|
|
101
270
|
#
|
|
102
271
|
# Raises IsNotAMokioMenuErrorr if obj isn't a Mokio::Menu object
|
|
103
272
|
#
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Mokio
|
|
2
|
+
module Slugged
|
|
3
|
+
def slug
|
|
4
|
+
"/#{slug_prefix}/#{id}/#{slug_candidate.parameterize}"
|
|
5
|
+
end
|
|
6
|
+
def print_slug
|
|
7
|
+
"#{slug}/print"
|
|
8
|
+
end
|
|
9
|
+
protected
|
|
10
|
+
def slug_prefix
|
|
11
|
+
"content"
|
|
12
|
+
end
|
|
13
|
+
def slug_candidate
|
|
14
|
+
title
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/mokio/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mokio
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- versoft
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-
|
|
11
|
+
date: 2014-12-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
@@ -1466,9 +1466,14 @@ files:
|
|
|
1466
1466
|
- db/migrate/20140731061227_create_mokio_external_scripts.rb
|
|
1467
1467
|
- db/migrate/20141009125027_alter_external_scripts.rb
|
|
1468
1468
|
- db/migrate/20141024131942_migrate_external_codes_to_external_scripts.rb
|
|
1469
|
+
- db/migrate/20141209072051_change_data_type_for_display_dates.rb
|
|
1470
|
+
- db/migrate/20141209101853_add_menu_css_options.rb
|
|
1469
1471
|
- lib/generators/mokio/copy/assets_generator.rb
|
|
1470
1472
|
- lib/generators/mokio/copy/views_generator.rb
|
|
1473
|
+
- lib/generators/mokio/ga_script_generator.rb
|
|
1471
1474
|
- lib/generators/mokio/install_generator.rb
|
|
1475
|
+
- lib/generators/mokio/positions_generator.rb
|
|
1476
|
+
- lib/generators/mokio/templates/_google_analytics.html.slim
|
|
1472
1477
|
- lib/generators/mokio/templates/mokio.rb
|
|
1473
1478
|
- lib/mokio.rb
|
|
1474
1479
|
- lib/mokio/common.rb
|
|
@@ -1523,11 +1528,13 @@ files:
|
|
|
1523
1528
|
- lib/mokio/frontend_helpers.rb
|
|
1524
1529
|
- lib/mokio/frontend_helpers/content_helper.rb
|
|
1525
1530
|
- lib/mokio/frontend_helpers/external_scripts_helper.rb
|
|
1531
|
+
- lib/mokio/frontend_helpers/langs_helper.rb
|
|
1526
1532
|
- lib/mokio/frontend_helpers/menu_helper.rb
|
|
1527
1533
|
- lib/mokio/frontend_helpers/static_modules_helper.rb
|
|
1528
1534
|
- lib/mokio/logger.rb
|
|
1529
1535
|
- lib/mokio/simple-form-wrappers.rb
|
|
1530
1536
|
- lib/mokio/site_helper.rb
|
|
1537
|
+
- lib/mokio/slugged.rb
|
|
1531
1538
|
- lib/mokio/solr_config.rb
|
|
1532
1539
|
- lib/mokio/template_renderer.rb
|
|
1533
1540
|
- lib/mokio/uploader.rb
|