openstax_utilities 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,7 @@ module OpenStax::Utilities
4
4
  def osu
5
5
  @@osu_class ||= Class.new(ClassyHelper) do
6
6
  include OpenStax::Utilities::Helpers::Blocks
7
+ include OpenStax::Utilities::Helpers::ActionList
7
8
  end
8
9
 
9
10
  @@osu_class.new(self)
@@ -0,0 +1,37 @@
1
+ <%# Copyright 2011-2012 Rice University. Licensed under the Affero General Public
2
+ License version 3 or later. See the COPYRIGHT file for details. %>
3
+
4
+ <%
5
+ records ||= []
6
+ list = OpenStax::Utilities::ActionList.new(list)
7
+ %>
8
+
9
+ <% if list.num_columns > 0 %>
10
+ <table class="action-list" width="100%">
11
+ <% if list.has_headings? %>
12
+ <tr class="action-list-header-row">
13
+ <% for ii in 0..list.num_columns - 1 %>
14
+ <th class="action-list-col-<%= ii %>"><%= list.get_heading(ii) %></th>
15
+ <% end %>
16
+ </tr>
17
+ <% end %>
18
+
19
+ <% if records.empty? %>
20
+ <tr>
21
+ <td colspan="<%= list.num_columns %>">No results</td>
22
+ </tr>
23
+ <% else %>
24
+ <% records.all.each_with_index do |user, rr| %>
25
+ <tr class="action-list-data-row <%= cycle('even', 'odd') %>">
26
+ <% for cc in 0..list.num_columns - 1 %>
27
+ <% width = rr == 0 ? list.get_width(cc) : nil %>
28
+ <td class="action-list-col-<%= ii %>"
29
+ <%= "width=#{width}" if width %>>
30
+ <%= list.get_data(cc, user) %>
31
+ </td>
32
+ <% end %>
33
+ </tr>
34
+ <% end %>
35
+ <% end %>
36
+ </table>
37
+ <% end %>
@@ -0,0 +1,40 @@
1
+ module OpenStax::Utilities
2
+ class ActionList
3
+
4
+ def initialize(options={})
5
+ @options = options
6
+
7
+ raise IllegalArgument, "must supply data procs" if options[:data_procs].nil?
8
+
9
+ if options[:headings].present? && options[:data_procs].size != options[:headings].size
10
+ raise IllegalArgument, "if you supply headings, you must supply one for each column"
11
+ end
12
+
13
+ if options[:widths].present? && options[:data_procs].size != options[:widths].size
14
+ raise IllegalArgument, "if you supply widths, you must supply one for each column"
15
+ end
16
+
17
+ end
18
+
19
+ def num_columns
20
+ @options[:data_procs].size
21
+ end
22
+
23
+ def has_headings?
24
+ @options[:headings].present?
25
+ end
26
+
27
+ def get_heading(column)
28
+ @options[:headings].nil? ? nil : @options[:headings][column]
29
+ end
30
+
31
+ def get_width(column)
32
+ @options[:widths].nil? ? nil : @options[:widths][column]
33
+ end
34
+
35
+ def get_data(column, *args)
36
+ @options[:data_procs][column].call(*args)
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,13 @@
1
+ # Copyright 2011-2013 Rice University. Licensed under the Affero General Public
2
+ # License version 3 or later. See the COPYRIGHT file for details.
3
+
4
+ module OpenStax::Utilities::Helpers
5
+ module ActionList
6
+
7
+ def action_list(options={})
8
+ raise IllegalArgument if options[:records].nil? || options[:list].nil?
9
+ render(:partial => 'osu/shared/action_list', locals: options)
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module OpenStax::Utilities
2
+
3
+ def self.generate_url(url, params = {})
4
+ uri = URI(url)
5
+ uri.query = params.to_query
6
+ uri.to_s
7
+ end
8
+
9
+ end
@@ -1,5 +1,5 @@
1
1
  module OpenStax
2
2
  module Utilities
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
4
4
  end
5
5
  end
@@ -13,10 +13,13 @@ require "openstax/utilities/access"
13
13
  require "openstax/utilities/enum"
14
14
  require "openstax/utilities/ruby"
15
15
  require "openstax/utilities/text"
16
+ require "openstax/utilities/network"
17
+ require "openstax/utilities/action_list"
16
18
 
17
19
  require "openstax/utilities/classy_helper"
18
20
  require "openstax/utilities/helpers/blocks"
19
21
  require "openstax/utilities/helpers/partials"
22
+ require "openstax/utilities/helpers/action_list"
20
23
 
21
24
  require 'openstax/utilities/blocks/block_base'
22
25
  require 'openstax/utilities/blocks/section_block'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstax_utilities
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-02 00:00:00.000000000 Z
12
+ date: 2013-10-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -53,11 +53,13 @@ files:
53
53
  - app/assets/javascripts/openstax_utilities.js
54
54
  - app/assets/stylesheets/openstax_utilities.css
55
55
  - app/helpers/openstax/utilities/osu_helper.rb
56
+ - app/views/osu/shared/_action_list.html.erb
56
57
  - app/views/osu/shared/_section.html.erb
57
58
  - app/views/osu/shared/_table.html.erb
58
59
  - app/views/osu/shared/_table_cell.html.erb
59
60
  - app/views/osu/shared/_table_row.html.erb
60
61
  - lib/openstax/utilities/access.rb
62
+ - lib/openstax/utilities/action_list.rb
61
63
  - lib/openstax/utilities/blocks/block_base.rb
62
64
  - lib/openstax/utilities/blocks/section_block.rb
63
65
  - lib/openstax/utilities/blocks/table_block.rb
@@ -68,8 +70,10 @@ files:
68
70
  - lib/openstax/utilities/engine.rb
69
71
  - lib/openstax/utilities/enum.rb
70
72
  - lib/openstax/utilities/exceptions.rb
73
+ - lib/openstax/utilities/helpers/action_list.rb
71
74
  - lib/openstax/utilities/helpers/blocks.rb
72
75
  - lib/openstax/utilities/helpers/partials.rb
76
+ - lib/openstax/utilities/network.rb
73
77
  - lib/openstax/utilities/ruby.rb
74
78
  - lib/openstax/utilities/settings.rb
75
79
  - lib/openstax/utilities/text.rb
@@ -122,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
126
  version: '0'
123
127
  segments:
124
128
  - 0
125
- hash: -2885322738742251153
129
+ hash: -237788097343637860
126
130
  required_rubygems_version: !ruby/object:Gem::Requirement
127
131
  none: false
128
132
  requirements:
@@ -131,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
135
  version: '0'
132
136
  segments:
133
137
  - 0
134
- hash: -2885322738742251153
138
+ hash: -237788097343637860
135
139
  requirements: []
136
140
  rubyforge_project:
137
141
  rubygems_version: 1.8.24