stable-rails 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -14,3 +14,4 @@ spec/reports
14
14
  test/tmp
15
15
  test/version_tmp
16
16
  tmp
17
+ .sass-cache
@@ -39,6 +39,8 @@ GEM
39
39
  rack (1.4.1)
40
40
  rack-cache (1.2)
41
41
  rack (>= 0.4)
42
+ rack-protection (1.3.2)
43
+ rack
42
44
  rack-ssl (1.3.2)
43
45
  rack
44
46
  rack-test (0.6.2)
@@ -53,6 +55,11 @@ GEM
53
55
  rake (10.0.3)
54
56
  rdoc (3.12)
55
57
  json (~> 1.4)
58
+ sass (3.2.5)
59
+ sinatra (1.3.3)
60
+ rack (~> 1.3, >= 1.3.6)
61
+ rack-protection (~> 1.2)
62
+ tilt (~> 1.3, >= 1.3.3)
56
63
  sprockets (2.2.2)
57
64
  hike (~> 1.2)
58
65
  multi_json (~> 1.0)
@@ -65,4 +72,6 @@ PLATFORMS
65
72
  ruby
66
73
 
67
74
  DEPENDENCIES
75
+ sass
76
+ sinatra
68
77
  stable-rails!
@@ -1,41 +1,43 @@
1
1
  (function($) {
2
2
 
3
3
  $.fn.stable = function() {
4
- var stable = $(this);
5
- var top_left_cell = $('.top_left', stable);
4
+ return this.each(function() {
5
+ var stable = $(this);
6
+ var top_left_cell = $('.c-left .t-header', stable);
6
7
 
7
- $('#scroll-vertical div', stable).height($('.c-right', stable).height());
8
- $('#scroll-horizontal div', stable).width($('.c-right', stable).width());
8
+ $('.scroll-vertical div', stable).height($('.c-right', stable).height());
9
+ $('.scroll-horizontal div', stable).width($('.c-right', stable).width()+$('.c-left', stable).width()+15);
9
10
 
10
- stable.css('padding-bottom', top_left_cell.outerHeight());
11
- stable.css('padding-right', top_left_cell.outerWidth());
11
+ stable.css('padding-bottom', top_left_cell.outerHeight());
12
+ stable.css('padding-right', top_left_cell.outerWidth()+15);
12
13
 
13
- stable.addClass('on');
14
+ stable.addClass('on');
14
15
 
15
- // Para el Scroll VERTICAL
16
- $('#scroll-vertical', stable).scroll(function(){
17
- $('.vertical', stable).scrollTop($(this).scrollTop());
18
- });
16
+ // Para el Scroll VERTICAL
17
+ $('.scroll-vertical', stable).scroll(function(){
18
+ $('.vertical', stable).scrollTop($(this).scrollTop());
19
+ });
19
20
 
20
- // Para el Scroll HORIZONTAL
21
- $('#scroll-horizontal', stable).scroll(function(){
22
- $('.horizontal', stable).scrollLeft($(this).scrollLeft());
23
- });
21
+ // Para el Scroll HORIZONTAL
22
+ $('.scroll-horizontal', stable).scroll(function(){
23
+ $('.horizontal', stable).scrollLeft($(this).scrollLeft());
24
+ });
24
25
 
25
- // Para la tabla
26
- $('#mask', stable).mousewheel(function(event, delta, deltaX, deltaY) {
27
- if (!stable.hasClass('on')) return;
26
+ // Para la tabla
27
+ $('.mask', stable).mousewheel(function(event, delta, deltaX, deltaY) {
28
+ if (!stable.hasClass('on')) return;
28
29
 
29
- var newLeft = $('.horizontal', stable).scrollLeft() + 25 * deltaX;
30
- var newTop = $('.vertical', stable).scrollTop() - 25 * deltaY;
30
+ var newLeft = $('.horizontal', stable).scrollLeft() + 25 * deltaX;
31
+ var newTop = $('.vertical', stable).scrollTop() - 25 * deltaY;
31
32
 
32
- $('.horizontal', stable).scrollLeft(newLeft);
33
- $('.vertical', stable).scrollTop(newTop);
33
+ $('.horizontal', stable).scrollLeft(newLeft);
34
+ $('.vertical', stable).scrollTop(newTop);
34
35
 
35
- $('#scroll-horizontal', stable).scrollLeft(newLeft);
36
- $('#scroll-vertical', stable).scrollTop(newTop);
36
+ $('.scroll-horizontal', stable).scrollLeft(newLeft);
37
+ $('.scroll-vertical', stable).scrollTop(newTop);
37
38
 
38
- event.preventDefault();
39
+ event.preventDefault();
40
+ });
39
41
  });
40
42
  };
41
43
 
@@ -0,0 +1,33 @@
1
+ /* -- TABLA CON SCROLL APAGADO -- */
2
+ .table-scroll {
3
+ position:relative;
4
+ margin-bottom:30px;
5
+ }
6
+ .table-scroll .scroll-vertical { display:none }
7
+ .table-scroll .scroll-horizontal { display:none }
8
+
9
+ /* -- TABLA CON SCROLL ENCENDIDO -- */
10
+ .table-scroll.on {
11
+ position:relative;
12
+ margin-bottom:30px;
13
+ }
14
+
15
+ .table-scroll.on .mask { height:inherit; width:100%; overflow:hidden; white-space:nowrap; font-size:0; padding-bottom:inherit; padding-right:inherit }
16
+ .table-scroll .mask { white-space:nowrap; font-size:0; }
17
+
18
+ .table-scroll.on .scrollbars { position:relative; width:100%; height:inherit; padding-bottom:inherit; padding-right:inherit }
19
+ .table-scroll.on .scroll-vertical { position:absolute; height:100%; width:18px; right:-2px; z-index:100; overflow-y:scroll; display:block }
20
+ .table-scroll.on .scroll-horizontal { position:absolute; height:18px; width:100%; left:0px; bottom:-17px; z-index:100; overflow-x:scroll; display:block }
21
+ .table-scroll.on .scroll-horizontal div { height:1px }
22
+
23
+
24
+ /* -- ESTRUCTURA GRAL DE LA TABLA-- */
25
+ .c-left, .c-right { display:inline-block; vertical-align:top; height:inherit }
26
+ .c-right { width:inherit }
27
+
28
+ .t-body { height:inherit; overflow:hidden }
29
+ .t-row { font-size:0; line-height:0 }
30
+ .t-header { overflow:hidden }
31
+ .t-row div { display:inline-block; overflow:hidden }
32
+
33
+
@@ -1,41 +1,17 @@
1
- /* -- TABLA CON SCROLL APAGADO -- */
2
- .table-scroll {
3
- position:relative;
4
- margin:0 auto; /*-- tabla centrada --*/
5
- margin-bottom:30px;
1
+ /*
2
+ *= require stable/common
3
+ *= require_self
4
+ */
5
+
6
+ .t-header {
7
+ background:#333333;
8
+ color:#FFFFFF
6
9
  }
7
- .table-scroll #scroll-vertical { display:none }
8
- .table-scroll #scroll-horizontal { display:none }
9
-
10
- /* -- TABLA CON SCROLL ENCENDIDO -- */
11
- .table-scroll.on {
12
- position:relative;
13
- margin-bottom:30px;
14
- width:80%; height:200px /*-- aplicados para este ejemplo en particular --*/;
15
- }
16
-
17
- .table-scroll.on #mask { height:inherit; width:100%; overflow:hidden; white-space:nowrap; font-size:0; padding-bottom:inherit; padding-right:inherit }
18
- .table-scroll #mask { white-space:nowrap; font-size:0; }
19
-
20
- .table-scroll.on #scrollbars { position:relative; width:100%; height:inherit; padding-bottom:inherit; padding-right:inherit }
21
- .table-scroll.on #scroll-vertical { position:absolute; height:100%; width:18px; right:-17px; z-index:100; overflow-y:scroll; display:block }
22
- .table-scroll.on #scroll-horizontal { position:absolute; height:18px; width:100%; left:0px; bottom:-17px; z-index:100; overflow-x:scroll; display:block }
23
- .table-scroll.on #scroll-horizontal div { height:1px }
24
-
25
-
26
- /* -- ESTRUCTURA GRAL DE LA TABLA-- */
27
- .c-left, .c-right { display:inline-block; vertical-align:top; height:inherit }
28
- .c-right { width:inherit }
29
-
30
- .t-header { background:#333333; color:#FFFFFF; overflow:hidden }
31
- .t-body { height:inherit; overflow:hidden }
32
- .t-row { font-size:0 }
33
- .t-row div { border:1px solid #999; font-size:11pt; display:inline-block; height:20px; overflow:hidden }
34
-
35
- /* ----- ANCHO de CELDAS para este ejemplo ----- */
36
- .table-scroll.w120 .t-row div { width:120px; padding:5px }
37
-
38
- /* ----- ANCHO PARTICULAR de celdas a modo de ejemplo ----- */
39
- .w200 { width:200px !important; }
40
-
41
10
 
11
+ .t-row div {
12
+ border-bottom:1px solid #ededed;
13
+ font-size:11pt;
14
+ line-height:11pt;
15
+ height:20px;
16
+ padding: 5px;
17
+ }
@@ -0,0 +1,7 @@
1
+ /*
2
+ *= require stable/common
3
+ *= require_self
4
+ */
5
+
6
+ .t-header { background:#cccccc; color: darkred; overflow:hidden }
7
+ .t-row div { border:1px solid #999; font-size:12pt; display:inline-block; height:20px; overflow:hidden }
@@ -1,15 +1,15 @@
1
1
  module StableHelper
2
2
 
3
- def stable(html_options = nil)
4
- @builder = STableBuilder.new(self)
5
- @builder.table(html_options) do
3
+ def stable(options = {})
4
+ @builder = STableBuilder.new(self, '/stable/stable')
5
+ @builder.table(options) do
6
6
  yield
7
7
  end
8
8
  end
9
9
 
10
- def table(html_options = nil)
11
- @builder = TableBuilder.new(self)
12
- @builder.table(html_options) do
10
+ def table(options = {})
11
+ @builder = STableBuilder.new(self, '/stable/table')
12
+ @builder.table(options) do
13
13
  yield
14
14
  end
15
15
  end
@@ -20,75 +20,77 @@ module StableHelper
20
20
  end
21
21
  end
22
22
 
23
- def td(content, options = {})
24
- @builder.td content, options
23
+ def td(content, html_options = {})
24
+ @builder.td content, html_options
25
25
  end
26
26
 
27
27
  end
28
28
 
29
- class TableBuilder
30
-
31
- def initialize(context)
32
- @context = context
33
- @row_index = -1
34
- @column_html_options = []
35
- end
36
-
37
- def table(html_options)
38
- @context.haml_tag :table, html_options do
39
- yield
40
- end
41
- end
42
-
43
- def tr
44
- @row_index += 1
45
- @col_index = -1
46
-
47
- @context.haml_tag :tr do
48
- yield
29
+ module Enumerable
30
+ def enum_drop_with_index(count)
31
+ self.each_with_index do |e, index|
32
+ next if index < count
33
+ yield e, index
49
34
  end
50
35
  end
51
36
 
52
- def td(content, options)
53
- @col_index += 1
54
-
55
- if @row_index == 0
56
- @column_html_options << (options.delete(:column) || {})
57
- end
58
-
59
- @context.haml_tag :td, options.merge(@column_html_options[@col_index]) do
60
- @context.haml_concat content
37
+ def enum_drop(count)
38
+ self.enum_drop_with_index(count) do |e, index|
39
+ yield e
61
40
  end
62
41
  end
63
42
  end
64
43
 
65
44
  class STableBuilder
66
45
 
67
- def initialize(context)
46
+ def initialize(context, partial_view)
47
+ @partial_view = partial_view
68
48
  @context = context
69
49
  @data = []
70
50
  @column_html_options = []
51
+ @row_index = -1
71
52
  end
72
53
 
73
- def table(html_options)
54
+ def table(options)
55
+ options.reverse_merge!({ fixed_rows: 1 })
56
+ html_options = options.clone
57
+ html_options.delete :fixed_rows
58
+
74
59
  yield
75
60
 
76
- @context.haml_concat @context.render(:partial => '/stable/stable',
61
+ @context.haml_concat @context.render(:partial => @partial_view,
77
62
  :locals => {
78
63
  :data => @data,
79
- :html_options => html_options,
80
- :column_html_options => @column_html_options
64
+ :options => options,
65
+ :html_options => html_options
81
66
  }
82
67
  )
83
68
  end
84
69
 
85
70
  def tr
71
+ @row_index += 1
72
+ @col_index = -1
73
+
86
74
  @data << []
87
75
  yield
88
76
  end
89
77
 
90
- def td(content, options)
91
- @column_html_options << (options[:column] || {})
92
- @data.last << content
78
+ def td(content, html_options)
79
+ @col_index += 1
80
+
81
+ # ensure slot for @column_html_options[@col_index]
82
+ if @col_index >= @column_html_options.size
83
+ @column_html_options << {}
84
+ end
85
+
86
+ # if html_options define style for column, override it
87
+ if c = html_options.delete(:column)
88
+ @column_html_options[@col_index] = c
89
+ end
90
+
91
+ # merge html_options with column html_options
92
+ html_options.merge!(@column_html_options[@col_index])
93
+
94
+ @data.last << { value: content, html_options: html_options }
93
95
  end
94
96
  end
@@ -1,36 +1,31 @@
1
- .stable.table-scroll.w120{ html_options }
2
- #scrollbars
3
- #scroll-vertical
1
+ .stable.table-scroll{ html_options }
2
+ .scrollbars
3
+ .scroll-vertical
4
4
  %div
5
- #scroll-horizontal
5
+ .scroll-horizontal
6
6
  %div
7
- #mask
7
+ .mask
8
8
  .c-left
9
9
  .t-header
10
- .t-row
11
- %div.top_left{column_html_options[0]}
12
- = data[0][0]
10
+ - (0..options[:fixed_rows]-1).each do |row|
11
+ .t-row
12
+ %div{data[row][0][:html_options]}
13
+ = data[row][0][:value]
13
14
  .t-body.vertical
14
- - data.each_with_index do |row, index|
15
- - next if index == 0
15
+ - data.enum_drop(options[:fixed_rows]) do |row|
16
16
  .t-row
17
- %div{column_html_options[0]}
18
- = row[0]
17
+ %div{row[0][:html_options]}
18
+ = row[0][:value]
19
19
  .c-right
20
20
  .t-header.horizontal
21
- .t-row
22
- - data[0].each_with_index do |cell, index|
23
- - next if index == 0
24
- %div{column_html_options[index]}
25
- = cell
21
+ - (0..options[:fixed_rows]-1).each do |row|
22
+ .t-row
23
+ - data[row].enum_drop(1) do |cell|
24
+ %div{cell[:html_options]}
25
+ = cell[:value]
26
26
  .t-body.vertical.horizontal
27
- - data.each_with_index do |row, index|
28
- - next if index == 0
27
+ - data.enum_drop(options[:fixed_rows]) do |row|
29
28
  .t-row
30
- - row.each_with_index do |cell, index|
31
- - next if index == 0
32
- %div{column_html_options[index]}
33
- = cell
34
-
35
-
36
-
29
+ - row.enum_drop(1) do |cell|
30
+ %div{cell[:html_options]}
31
+ = cell[:value]
@@ -0,0 +1,6 @@
1
+ %table{ html_options }
2
+ - data.each do |row|
3
+ %tr
4
+ - row.each do |cell|
5
+ %td{ cell[:html_options] }
6
+ = cell[:value]
@@ -1,5 +1,5 @@
1
1
  module Stable
2
2
  module Rails
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -0,0 +1,44 @@
1
+ require 'sinatra'
2
+ require 'haml'
3
+ require 'sass'
4
+ require 'action_view'
5
+ require 'sprockets'
6
+ require_relative '../../app/helpers/stable_helper'
7
+ include StableHelper
8
+
9
+ set :assets, Sprockets::Environment.new
10
+ settings.assets.append_path File.join(File.dirname(__FILE__), "../../app/assets/javascripts")
11
+ settings.assets.append_path File.join(File.dirname(__FILE__), "../../app/assets/stylesheets")
12
+
13
+ helpers do
14
+ def render(*args)
15
+ # HACK to load gem partial view
16
+ if args.first.is_a?(Hash) && args.first.keys.include?(:partial)
17
+ partial = args.first[:partial]
18
+ location = File.join("../../../app/views", File.split(partial)[0], "_#{File.split(partial)[1]}")
19
+ options = { :locals => args.last[:locals] }
20
+ return haml location.to_sym, options
21
+ else
22
+ super
23
+ end
24
+ end
25
+ end
26
+
27
+ get '/' do
28
+ haml :index
29
+ end
30
+
31
+ get "/javascripts/:file.js" do
32
+ content_type "application/javascript"
33
+ settings.assets["#{params[:file]}.js"]
34
+ end
35
+
36
+ get "/stylesheets/:file.css" do
37
+ content_type "text/css"
38
+ settings.assets["#{params[:file]}.css"]
39
+ end
40
+
41
+ get "/stylesheets/:part/:file.css" do
42
+ content_type "text/css"
43
+ settings.assets["#{params[:part]}/#{params[:file]}.css"]
44
+ end
@@ -0,0 +1,54 @@
1
+ - stable class: 'w120' do
2
+ - tr do
3
+ - td 'L\N'
4
+ - td 'Title 1'
5
+ - td 'Title 2'
6
+ - td 'Title 3'
7
+ - td 'Title 4'
8
+ - td 'Title 5'
9
+ - ('a'..'z').each do |c|
10
+ - tr do
11
+ - td "Title #{c}"
12
+ - td "#{c}1"
13
+ - td "#{c}2"
14
+ - td "#{c}3"
15
+ - td "#{c}4"
16
+ - td "#{c}5"
17
+
18
+ - stable class: 'w120', fixed_rows: 2 do
19
+ - tr do
20
+ - td 'L\N'
21
+ - td 'Title 1'
22
+ - td 'Title 2'
23
+ - td 'Title 3', column: { class: 'red' }
24
+ - td 'Title 4'
25
+ - td 'Title 5'
26
+ - td 'Title 6'
27
+ - td 'Title 7'
28
+ - ('a'..'z').each do |c|
29
+ - tr do
30
+ - td "Title #{c}"
31
+ - td "#{c}1"
32
+ - td "#{c}2"
33
+ - td "#{c}3"
34
+ - td "#{c}4"
35
+ - td "#{c}5", column: { class: 'blue' }
36
+ - td "#{c}6"
37
+ - td "#{c}7"
38
+
39
+ - stable class: 'w120', fixed_rows: 2 do
40
+ - tr do
41
+ - td 'L\N'
42
+ - td 'Title 1', style: 'width: 252px; text-align: center'
43
+ - td 'Title 3', style: 'width: 252px; text-align: center'
44
+ - td 'Title 5', style: 'width: 384px; text-align: center'
45
+ - ('a'..'z').each do |c|
46
+ - tr do
47
+ - td "Title #{c}"
48
+ - td "#{c}1"
49
+ - td "#{c}2"
50
+ - td "#{c}3"
51
+ - td "#{c}4"
52
+ - td "#{c}5"
53
+ - td "#{c}6"
54
+ - td "#{c}7"
@@ -0,0 +1,22 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %title stable-rails sample
5
+ %link(href="/stylesheets/stable.css" media="all" rel="stylesheet" type="text/css")
6
+ :css
7
+ .table-scroll {
8
+ height: 200px;
9
+ width: 70%;
10
+ }
11
+
12
+ .table-scroll.w120 .t-row div {
13
+ width: 120px;
14
+ }
15
+
16
+ .red { background-color: red !important; }
17
+ .blue { background-color: blue !important; }
18
+ %script(src="http://code.jquery.com/jquery-1.8.3.min.js" type="text/javascript")
19
+ %script(src="/javascripts/stable.js" type="text/javascript")
20
+ %body
21
+ %h1 stable-rails sample
22
+ =yield
@@ -18,4 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_runtime_dependency 'haml-rails'
21
+
22
+ gem.add_development_dependency 'sinatra'
23
+ gem.add_development_dependency 'sass'
21
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stable-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-04 00:00:00.000000000 Z
13
+ date: 2013-01-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: haml-rails
17
- requirement: &70259525148200 !ruby/object:Gem::Requirement
17
+ requirement: &70120944830020 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,7 +22,29 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70259525148200
25
+ version_requirements: *70120944830020
26
+ - !ruby/object:Gem::Dependency
27
+ name: sinatra
28
+ requirement: &70120944828760 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *70120944828760
37
+ - !ruby/object:Gem::Dependency
38
+ name: sass
39
+ requirement: &70120944827440 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *70120944827440
26
48
  description: Scrollable table with fixed first row and column.
27
49
  email:
28
50
  - mscebba@manas.com.ar
@@ -41,11 +63,17 @@ files:
41
63
  - app/assets/javascripts/stable/index.js
42
64
  - app/assets/javascripts/stable/jquery.mousewheel.js
43
65
  - app/assets/javascripts/stable/stable.js
66
+ - app/assets/stylesheets/stable/common.scss
44
67
  - app/assets/stylesheets/stable/index.scss
68
+ - app/assets/stylesheets/stable/theme-gray.scss
45
69
  - app/helpers/stable_helper.rb
46
70
  - app/views/stable/_stable.haml
71
+ - app/views/stable/_table.haml
47
72
  - lib/stable-rails.rb
48
73
  - lib/stable-rails/version.rb
74
+ - spec/sinatra-app/app.rb
75
+ - spec/sinatra-app/views/index.haml
76
+ - spec/sinatra-app/views/layout.haml
49
77
  - stable-rails.gemspec
50
78
  homepage: https://github.com/manastech/stable-rails
51
79
  licenses: []
@@ -71,4 +99,7 @@ rubygems_version: 1.8.10
71
99
  signing_key:
72
100
  specification_version: 3
73
101
  summary: Rails gem that allows to easily include scrollable tables.
74
- test_files: []
102
+ test_files:
103
+ - spec/sinatra-app/app.rb
104
+ - spec/sinatra-app/views/index.haml
105
+ - spec/sinatra-app/views/layout.haml