Commit d9620af256246be150d015390a6f2912c2bba1f9
1 parent
7eff9852
Exists in
master
and in
28 other branches
string-ext: convert class name to valid css class
Showing
8 changed files
with
23 additions
and
24 deletions
Show diff stats
app/helpers/boxes_helper.rb
@@ -227,15 +227,11 @@ module BoxesHelper | @@ -227,15 +227,11 @@ module BoxesHelper | ||
227 | 227 | ||
228 | # DEPRECATED. Do not use this. | 228 | # DEPRECATED. Do not use this. |
229 | def import_blocks_stylesheets(options = {}) | 229 | def import_blocks_stylesheets(options = {}) |
230 | - @blocks_css_files ||= current_blocks.map{|b|'blocks/' + block_css_class_name(b)}.uniq | 230 | + @blocks_css_files ||= current_blocks.map{|b|'blocks/' + block.class.name.to_css_class}.uniq |
231 | stylesheet_import(@blocks_css_files, options) | 231 | stylesheet_import(@blocks_css_files, options) |
232 | end | 232 | end |
233 | - | ||
234 | - def block_css_class_name(block) | ||
235 | - block.class.name.underscore.gsub('_', '-') | ||
236 | - end | ||
237 | def block_css_classes(block) | 233 | def block_css_classes(block) |
238 | - classes = block_css_class_name(block) | 234 | + classes = block.class.name.to_css_class |
239 | classes += ' invisible-block' if block.display == 'never' | 235 | classes += ' invisible-block' if block.display == 'never' |
240 | classes | 236 | classes |
241 | end | 237 | end |
app/models/article.rb
@@ -157,7 +157,7 @@ class Article < ActiveRecord::Base | @@ -157,7 +157,7 @@ class Article < ActiveRecord::Base | ||
157 | end | 157 | end |
158 | 158 | ||
159 | def css_class_list | 159 | def css_class_list |
160 | - [self.class.name.underscore.dasherize] | 160 | + [self.class.name.to_css_class] |
161 | end | 161 | end |
162 | 162 | ||
163 | def css_class_name | 163 | def css_class_name |
app/models/box.rb
@@ -78,7 +78,7 @@ class Box < ActiveRecord::Base | @@ -78,7 +78,7 @@ class Box < ActiveRecord::Base | ||
78 | private | 78 | private |
79 | 79 | ||
80 | def to_css_class_name(blocks) | 80 | def to_css_class_name(blocks) |
81 | - blocks.map{ |block| block.to_s.underscore.tr('_', '-') } | 81 | + blocks.map{ |block| block.class.name.to_css_class } |
82 | end | 82 | end |
83 | 83 | ||
84 | end | 84 | end |
lib/noosfero/core_ext/string.rb
@@ -80,6 +80,10 @@ class String | @@ -80,6 +80,10 @@ class String | ||
80 | transliterate.downcase.gsub(/[^\w~\s:;+=_."'`-]/, '').gsub(/[\s:;+=_"'`-]+/, '-').gsub(/-$/, '').gsub(/^-/, '').to_s | 80 | transliterate.downcase.gsub(/[^\w~\s:;+=_."'`-]/, '').gsub(/[\s:;+=_"'`-]+/, '-').gsub(/-$/, '').gsub(/^-/, '').to_s |
81 | end | 81 | end |
82 | 82 | ||
83 | + def to_css_class | ||
84 | + underscore.dasherize.gsub('/','_') | ||
85 | + end | ||
86 | + | ||
83 | def fix_i18n | 87 | def fix_i18n |
84 | self.sub('{fn} ', '') | 88 | self.sub('{fn} ', '') |
85 | end | 89 | end |
plugins/container_block/public/style.css
1 | -#content .boxes .container-block-plugin/container-block .container_block_child, .container-block-plugin/container-block .block-outer { | 1 | +#content .boxes .container-block-plugin_container-block .container_block_child, .container-block-plugin_container-block .block-outer { |
2 | display: inline-block; | 2 | display: inline-block; |
3 | vertical-align: top; | 3 | vertical-align: top; |
4 | margin-left: -2px; | 4 | margin-left: -2px; |
5 | margin-right: -2px; | 5 | margin-right: -2px; |
6 | } | 6 | } |
7 | 7 | ||
8 | -.container-block-plugin/container-block .block-target { | 8 | +.container-block-plugin_container-block .block-target { |
9 | clear: both; | 9 | clear: both; |
10 | } | 10 | } |
11 | 11 | ||
12 | -.container-block-plugin/container-block .block-target[id^='end-of-box-'] { | 12 | +.container-block-plugin_container-block .block-target[id^='end-of-box-'] { |
13 | display: none; | 13 | display: none; |
14 | } | 14 | } |
15 | 15 | ||
16 | -#content .boxes .container-block-plugin/container-block .block .icon-down, #content .boxes .container-block-plugin/container-block .block .icon-down-disabled { | 16 | +#content .boxes .container-block-plugin_container-block .block .icon-down, #content .boxes .container-block-plugin_container-block .block .icon-down-disabled { |
17 | background-image: url(/designs/icons/default/Tango/16x16/actions/go-next.png); | 17 | background-image: url(/designs/icons/default/Tango/16x16/actions/go-next.png); |
18 | } | 18 | } |
19 | 19 | ||
20 | -#content .boxes .container-block-plugin/container-block .block .icon-up, #content .boxes .container-block-plugin/container-block .block .icon-up-disabled { | 20 | +#content .boxes .container-block-plugin_container-block .block .icon-up, #content .boxes .container-block-plugin_container-block .block .icon-up-disabled { |
21 | background-image: url(/designs/icons/default/Tango/16x16/actions/go-previous.png); | 21 | background-image: url(/designs/icons/default/Tango/16x16/actions/go-previous.png); |
22 | } | 22 | } |
23 | 23 | ||
24 | -#content .boxes .container-block-plugin/container-block .block { | 24 | +#content .boxes .container-block-plugin_container-block .block { |
25 | outline-offset: -2px; | 25 | outline-offset: -2px; |
26 | } | 26 | } |
27 | 27 | ||
28 | -#content .boxes .container-block-plugin/container-block .block .ui-resizable-handle { | 28 | +#content .boxes .container-block-plugin_container-block .block .ui-resizable-handle { |
29 | width: 10px; | 29 | width: 10px; |
30 | height: 28px; | 30 | height: 28px; |
31 | z-index: 0; | 31 | z-index: 0; |
32 | } | 32 | } |
33 | 33 | ||
34 | -#content .boxes .container-block-plugin/container-block .block .ui-resizable-e { | 34 | +#content .boxes .container-block-plugin_container-block .block .ui-resizable-e { |
35 | right: -2px; | 35 | right: -2px; |
36 | background-image: url(/plugins/container_block/images/handle_e.png); | 36 | background-image: url(/plugins/container_block/images/handle_e.png); |
37 | } | 37 | } |
38 | 38 | ||
39 | -#content .boxes .container-block-plugin/container-block .block .ui-resizable-w { | 39 | +#content .boxes .container-block-plugin_container-block .block .ui-resizable-w { |
40 | left: -2px; | 40 | left: -2px; |
41 | background-image: url(/plugins/container_block/images/handle_w.png); | 41 | background-image: url(/plugins/container_block/images/handle_w.png); |
42 | } | 42 | } |
43 | 43 | ||
44 | -.container-block-plugin/container-block .button-bar .icon-resize { | 44 | +.container-block-plugin_container-block .button-bar .icon-resize { |
45 | background-image: url(/designs/icons/default/Tango/16x16/actions/view-fullscreen.png); | 45 | background-image: url(/designs/icons/default/Tango/16x16/actions/view-fullscreen.png); |
46 | } | 46 | } |
plugins/container_block/test/functional/container_block_home_controller_test.rb
@@ -28,7 +28,7 @@ class HomeControllerTest < ActionController::TestCase | @@ -28,7 +28,7 @@ class HomeControllerTest < ActionController::TestCase | ||
28 | 28 | ||
29 | should 'display ContainerBlock' do | 29 | should 'display ContainerBlock' do |
30 | get :index | 30 | get :index |
31 | - assert_tag :div, :attributes => { :class => 'block container-block-plugin/container-block' } | 31 | + assert_tag :div, :attributes => { :class => 'block container-block-plugin_container-block' } |
32 | end | 32 | end |
33 | 33 | ||
34 | should 'display container children' do | 34 | should 'display container children' do |
test/unit/boxes_helper_test.rb
@@ -96,11 +96,6 @@ class BoxesHelperTest < ActiveSupport::TestCase | @@ -96,11 +96,6 @@ class BoxesHelperTest < ActiveSupport::TestCase | ||
96 | assert_tag_in_string insert_boxes('main content'), :tag => "div", :attributes => { :id => 'profile-footer' }, :content => 'my custom footer' | 96 | assert_tag_in_string insert_boxes('main content'), :tag => "div", :attributes => { :id => 'profile-footer' }, :content => 'my custom footer' |
97 | end | 97 | end |
98 | 98 | ||
99 | - should 'calculate CSS class names correctly' do | ||
100 | - assert_equal 'slideshow-block', block_css_class_name(SlideshowBlock.new) | ||
101 | - assert_equal 'main-block', block_css_class_name(MainBlock.new) | ||
102 | - end | ||
103 | - | ||
104 | should 'add invisible CSS class name for invisible blocks' do | 99 | should 'add invisible CSS class name for invisible blocks' do |
105 | assert !block_css_classes(Block.new(:display => 'always')).split.any? { |item| item == 'invisible-block'} | 100 | assert !block_css_classes(Block.new(:display => 'always')).split.any? { |item| item == 'invisible-block'} |
106 | assert block_css_classes(Block.new(:display => 'never')).split.any? { |item| item == 'invisible-block'} | 101 | assert block_css_classes(Block.new(:display => 'never')).split.any? { |item| item == 'invisible-block'} |
test/unit/string_core_ext_test.rb
@@ -33,4 +33,8 @@ class StringCoreExtTest < ActiveSupport::TestCase | @@ -33,4 +33,8 @@ class StringCoreExtTest < ActiveSupport::TestCase | ||
33 | assert_equal 'aaaaaaAAAAAeeeeEEOOoocaaaiIIiuuyYnNcC', 'ªáàäâåÁÀÄÂÅéèëêÊËÖÔöôçäàâîÏÎïûüÿŸñÑçÇ'.transliterate | 33 | assert_equal 'aaaaaaAAAAAeeeeEEOOoocaaaiIIiuuyYnNcC', 'ªáàäâåÁÀÄÂÅéèëêÊËÖÔöôçäàâîÏÎïûüÿŸñÑçÇ'.transliterate |
34 | end | 34 | end |
35 | 35 | ||
36 | + should 'convert to css class' do | ||
37 | + assert_equal 'spaceship-propulsion_warp-core', "SpaceshipPropulsion::WarpCore".to_css_class | ||
38 | + end | ||
39 | + | ||
36 | end | 40 | end |