openstax_utilities 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -1
- data/app/assets/javascripts/openstax_utilities.js +0 -0
- data/app/assets/stylesheets/openstax_utilities.css +4 -0
- data/app/assets/stylesheets/section_block.css.scss +33 -0
- data/app/helpers/block_helper.rb +22 -0
- data/app/helpers/partial_helper.rb +9 -0
- data/app/views/osu/shared/_section.html.erb +17 -0
- data/app/views/osu/shared/_table.html.erb +22 -0
- data/app/views/osu/shared/_table_cell.html.erb +6 -0
- data/app/views/osu/shared/_table_row.html.erb +8 -0
- data/lib/openstax/utilities/blocks/block_base.rb +36 -0
- data/lib/openstax/utilities/blocks/section_block.rb +60 -0
- data/lib/openstax/utilities/blocks/table_block.rb +74 -0
- data/lib/openstax/utilities/blocks/table_cell_block.rb +26 -0
- data/lib/openstax/utilities/blocks/table_row_block.rb +49 -0
- data/lib/openstax/utilities/engine.rb +7 -0
- data/lib/openstax/utilities/version.rb +1 -1
- data/lib/openstax_utilities.rb +54 -1
- metadata +39 -3
data/README.md
CHANGED
@@ -3,4 +3,6 @@ OpenstaxUtilities
|
|
3
3
|
|
4
4
|
A set of common utilities for the various OpenStax projects.
|
5
5
|
|
6
|
-
Documentation available on [rdoc.info](http://rdoc.info/github/openstax/openstax_utilities/master/frames).
|
6
|
+
Documentation available on [rdoc.info](http://rdoc.info/github/openstax/openstax_utilities/master/frames).
|
7
|
+
|
8
|
+
To use this utility engine, include it in your Gemfile.
|
File without changes
|
@@ -0,0 +1,33 @@
|
|
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
|
+
@mixin section-block-base($heading_font_size:16px, $heading_color:black, $body_indent:0px, $body_top_margin:8px) {
|
5
|
+
margin: 10px 0px;
|
6
|
+
|
7
|
+
.section-block-heading {
|
8
|
+
|
9
|
+
color: $heading_color;
|
10
|
+
font-size: $heading_font_size;
|
11
|
+
|
12
|
+
a {
|
13
|
+
font-size: $heading_font_size;
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
.section-block-body {
|
18
|
+
margin: $body_top_margin 0px 0px;
|
19
|
+
padding: 0px 0px 0px $body_indent;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
.section-block-section {
|
24
|
+
@include section-block-base(16px);
|
25
|
+
}
|
26
|
+
|
27
|
+
.section-block-section.nesting-2 {
|
28
|
+
@include section-block-base(14px);
|
29
|
+
|
30
|
+
.section-block-heading {
|
31
|
+
font-style: italic;
|
32
|
+
}
|
33
|
+
}
|
@@ -0,0 +1,22 @@
|
|
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 BlockHelper
|
5
|
+
|
6
|
+
def section_block(heading=nil, &block)
|
7
|
+
presenter = OpenStax::Utilities::Blocks::SectionBlock.new(self, heading, block)
|
8
|
+
end
|
9
|
+
|
10
|
+
def table_block(&block)
|
11
|
+
presenter = TableBlock.new(self, block)
|
12
|
+
end
|
13
|
+
|
14
|
+
def table_row_block(&block)
|
15
|
+
presenter = TableRowBlock.new(self, block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def table_cell_block(&block)
|
19
|
+
presenter = TableCellBlock.new(self, block)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
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
|
+
<div <%= block.section_id_attr %> <%= block.section_class_attr %> >
|
5
|
+
|
6
|
+
<% if block.show_heading? %>
|
7
|
+
<div <%= block.heading_class_attr %> >
|
8
|
+
<%= block.heading %>
|
9
|
+
</div>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<div <%= block.body_class_attr %> >
|
13
|
+
<%= block.captured_block %>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
</div>
|
17
|
+
|
@@ -0,0 +1,22 @@
|
|
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
|
+
<table <%= block.table_id_attr %> <%= block.table_class_attr %> >
|
5
|
+
<% if block.show_caption? %>
|
6
|
+
<caption <%= block.caption_class_attr %> >
|
7
|
+
<%= block.title %>
|
8
|
+
</caption>
|
9
|
+
<% end %>
|
10
|
+
|
11
|
+
<tr <%= block.heading_row_class_attr %> >
|
12
|
+
<% block.column_names.each do |column_name| %>
|
13
|
+
<th <%= block.heading_cell_class_attr %> >
|
14
|
+
<%= column_name %>
|
15
|
+
</th>
|
16
|
+
<% end %>
|
17
|
+
</tr>
|
18
|
+
|
19
|
+
<% block.row_blocks.each do |row_block| %>
|
20
|
+
<%= row_block %>
|
21
|
+
<% end %>
|
22
|
+
</table>
|
@@ -0,0 +1,6 @@
|
|
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
|
+
<td <%= block.td_id_attr %> <%= block.td_class_attr %> <%= block.td_colspan_attr %> >
|
5
|
+
<%= block.captured_block %>
|
6
|
+
</td>
|
@@ -0,0 +1,36 @@
|
|
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::Blocks
|
5
|
+
class BlockBase
|
6
|
+
include Attribeautiful
|
7
|
+
|
8
|
+
attr_accessor :captured_block
|
9
|
+
|
10
|
+
def initialize(template, partial, passed_block)
|
11
|
+
self.h = template
|
12
|
+
self.passed_block = passed_block
|
13
|
+
self.partial = partial
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
render_passed_block
|
18
|
+
render_partial
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
attr_accessor :h
|
24
|
+
attr_accessor :passed_block
|
25
|
+
attr_accessor :partial
|
26
|
+
|
27
|
+
def render_passed_block
|
28
|
+
self.captured_block ||= h.capture self, &passed_block
|
29
|
+
end
|
30
|
+
|
31
|
+
def render_partial
|
32
|
+
h.render :partial => "osu/shared/#{partial}", :locals => { :block => self }
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,60 @@
|
|
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::Blocks
|
5
|
+
class SectionBlock < BlockBase
|
6
|
+
|
7
|
+
html_element :section
|
8
|
+
html_element :heading
|
9
|
+
html_element :body
|
10
|
+
|
11
|
+
attr_accessor :heading
|
12
|
+
attr_accessor :nesting
|
13
|
+
attr_accessor :top_bar
|
14
|
+
|
15
|
+
def initialize(template, heading, block)
|
16
|
+
super(template, "section", block)
|
17
|
+
|
18
|
+
set_heading(heading) if !heading.blank?
|
19
|
+
section_class_add "section-block-section"
|
20
|
+
heading_class_add "section-block-heading"
|
21
|
+
body_class_add "section-block-body"
|
22
|
+
end
|
23
|
+
|
24
|
+
def set_heading(string)
|
25
|
+
self.heading = string
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def set_nesting(depth)
|
30
|
+
self.nesting = depth
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def set_top_bar
|
35
|
+
raise "SectionBlock top bar cannot be changed once initialized" \
|
36
|
+
if @top_bar
|
37
|
+
section_class_add "bar-top"
|
38
|
+
self.top_bar = true
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
def heading=(string)
|
43
|
+
raise "SectionBlock heading cannot be changed once initialized" \
|
44
|
+
if @heading
|
45
|
+
@heading = string
|
46
|
+
end
|
47
|
+
|
48
|
+
def nesting=(depth)
|
49
|
+
raise "SectionBlock nesting cannot be changed once initialized" \
|
50
|
+
if @nesting
|
51
|
+
section_class_add "nesting-#{depth}"
|
52
|
+
@nesting = depth
|
53
|
+
end
|
54
|
+
|
55
|
+
def show_heading?
|
56
|
+
heading.present?
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,74 @@
|
|
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::Blocks
|
5
|
+
class TableBlock < BlockBase
|
6
|
+
|
7
|
+
html_element :table
|
8
|
+
html_element :caption
|
9
|
+
html_element :heading_row
|
10
|
+
html_element :heading_cell
|
11
|
+
|
12
|
+
attr_reader :column_names
|
13
|
+
attr_reader :row_blocks
|
14
|
+
attr_reader :title
|
15
|
+
|
16
|
+
def initialize(template, block)
|
17
|
+
super(template, "table", block)
|
18
|
+
self.column_names = []
|
19
|
+
self.row_blocks = []
|
20
|
+
|
21
|
+
self.table_class_add "table-block-table"
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_title(table_title)
|
26
|
+
self.title = table_title
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def title=(table_title)
|
31
|
+
raise "TableBlock title cannot be changed once initialized" \
|
32
|
+
if @title
|
33
|
+
@title = table_title
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_column(column_name)
|
37
|
+
self.column_names << column_name
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_row_block(&block)
|
42
|
+
self.row_blocks << h.table_row_block(&block)
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
46
|
+
def add_row(*args)
|
47
|
+
trb = h.table_row_block do |rb|
|
48
|
+
args.each do |arg|
|
49
|
+
rb.add_cell(arg)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
self.row_blocks << trb
|
53
|
+
self
|
54
|
+
end
|
55
|
+
|
56
|
+
def add_section_heading(heading)
|
57
|
+
trb = h.table_row_block do |rb|
|
58
|
+
rb.set_section_heading(heading, column_names.count)
|
59
|
+
end
|
60
|
+
self.row_blocks << trb
|
61
|
+
self
|
62
|
+
end
|
63
|
+
|
64
|
+
def show_caption?
|
65
|
+
title.present?
|
66
|
+
end
|
67
|
+
|
68
|
+
protected
|
69
|
+
|
70
|
+
attr_writer :column_names
|
71
|
+
attr_writer :row_blocks
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,26 @@
|
|
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::Blocks
|
5
|
+
class TableCellBlock < BlockBase
|
6
|
+
|
7
|
+
html_element :td
|
8
|
+
|
9
|
+
def initialize(template, block)
|
10
|
+
super(template, "table_cell", block)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.from_value(template, value)
|
14
|
+
tcb = TableCellBlock.new(template, Proc.new {})
|
15
|
+
tcb.captured_block = value
|
16
|
+
tcb
|
17
|
+
end
|
18
|
+
|
19
|
+
def set_section_heading(colspan)
|
20
|
+
self.td_class_add "section-heading"
|
21
|
+
self.td_colspan_add colspan
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,49 @@
|
|
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::Blocks
|
5
|
+
class TableRowBlock < BlockBase
|
6
|
+
|
7
|
+
attr_reader :cell_blocks
|
8
|
+
attr_reader :section_heading
|
9
|
+
|
10
|
+
def initialize(template, block)
|
11
|
+
super(template, "table_row", block)
|
12
|
+
self.cell_blocks = []
|
13
|
+
self.section_heading = false
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_cell_block(&block)
|
17
|
+
self.cell_blocks << h.table_cell_block(&block)
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_cell(value)
|
22
|
+
self.cell_blocks << TableCellBlock.from_value(h, value)
|
23
|
+
end
|
24
|
+
|
25
|
+
def section_heading?
|
26
|
+
section_heading
|
27
|
+
end
|
28
|
+
|
29
|
+
def set_section_heading(heading, colspan)
|
30
|
+
raise "TableRowBlock cannot be a table section heading if it contains cells" \
|
31
|
+
if cell_blocks.any?
|
32
|
+
raise "TableRowBlock section heading cannot be changed once initialized" \
|
33
|
+
if section_heading?
|
34
|
+
|
35
|
+
tcb = TableCellBlock.from_value(h, heading)
|
36
|
+
tcb.set_section_heading(colspan)
|
37
|
+
self.cell_blocks << tcb
|
38
|
+
|
39
|
+
self.section_heading = true
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
attr_writer :cell_blocks
|
46
|
+
attr_writer :section_heading
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -1,6 +1,13 @@
|
|
1
1
|
module OpenStax
|
2
2
|
module Utilities
|
3
3
|
class Engine < ::Rails::Engine
|
4
|
+
# isolate_namespace OpenStax::Utilities
|
5
|
+
|
6
|
+
initializer "openstax_utilities.assets.precompile" do |app|
|
7
|
+
app.config.assets.precompile += %w(openstax_utilities.css openstax_utilities.js)
|
8
|
+
end
|
4
9
|
end
|
5
10
|
end
|
6
11
|
end
|
12
|
+
|
13
|
+
OSU = OpenStax::Utilities
|
data/lib/openstax_utilities.rb
CHANGED
@@ -2,4 +2,57 @@ require "openstax/utilities/engine"
|
|
2
2
|
require "openstax/utilities/version"
|
3
3
|
require "openstax/utilities/exceptions"
|
4
4
|
require "openstax/utilities/settings"
|
5
|
-
require "openstax/utilities/access"
|
5
|
+
require "openstax/utilities/access"
|
6
|
+
|
7
|
+
require 'openstax/utilities/blocks/block_base'
|
8
|
+
require 'openstax/utilities/blocks/section_block'
|
9
|
+
require 'openstax/utilities/blocks/table_block'
|
10
|
+
require 'openstax/utilities/blocks/table_cell_block'
|
11
|
+
require 'openstax/utilities/blocks/table_row_block'
|
12
|
+
|
13
|
+
module OpenStax
|
14
|
+
module Utilities
|
15
|
+
|
16
|
+
# ASSET_FILES = %w(openstax_utilities.css openstax_utilities.js)
|
17
|
+
|
18
|
+
# ActiveSupport.on_load(:before_initialize) do
|
19
|
+
# Rails.configuration.assets.precompile += OpenStax::Utilities::ASSET_FILES
|
20
|
+
# end
|
21
|
+
|
22
|
+
class << self
|
23
|
+
|
24
|
+
###########################################################################
|
25
|
+
#
|
26
|
+
# Configuration machinery.
|
27
|
+
#
|
28
|
+
# To configure OpenStax Utilities, put the following code in your applications
|
29
|
+
# initialization logic (eg. in the config/initializers in a Rails app)
|
30
|
+
#
|
31
|
+
# OpenStax::Utilities.configure do |config|
|
32
|
+
# config.<parameter name> = <parameter value>
|
33
|
+
# ...
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
|
37
|
+
def configure
|
38
|
+
yield configuration
|
39
|
+
end
|
40
|
+
|
41
|
+
def configuration
|
42
|
+
@configuration ||= Configuration.new
|
43
|
+
end
|
44
|
+
|
45
|
+
class Configuration
|
46
|
+
# attr_accessor :some_parameter_name_here
|
47
|
+
|
48
|
+
def initialize
|
49
|
+
# @some_parameter_name_here = some value here
|
50
|
+
super
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
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: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
-
dependencies:
|
12
|
+
date: 2013-06-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.1'
|
14
30
|
description: Utilities for OpenStax web sites
|
15
31
|
email:
|
16
32
|
- jps@kindlinglabs.com
|
@@ -18,7 +34,21 @@ executables: []
|
|
18
34
|
extensions: []
|
19
35
|
extra_rdoc_files: []
|
20
36
|
files:
|
37
|
+
- app/assets/javascripts/openstax_utilities.js
|
38
|
+
- app/assets/stylesheets/openstax_utilities.css
|
39
|
+
- app/assets/stylesheets/section_block.css.scss
|
40
|
+
- app/helpers/block_helper.rb
|
41
|
+
- app/helpers/partial_helper.rb
|
42
|
+
- app/views/osu/shared/_section.html.erb
|
43
|
+
- app/views/osu/shared/_table.html.erb
|
44
|
+
- app/views/osu/shared/_table_cell.html.erb
|
45
|
+
- app/views/osu/shared/_table_row.html.erb
|
21
46
|
- lib/openstax/utilities/access.rb
|
47
|
+
- lib/openstax/utilities/blocks/block_base.rb
|
48
|
+
- lib/openstax/utilities/blocks/section_block.rb
|
49
|
+
- lib/openstax/utilities/blocks/table_block.rb
|
50
|
+
- lib/openstax/utilities/blocks/table_cell_block.rb
|
51
|
+
- lib/openstax/utilities/blocks/table_row_block.rb
|
22
52
|
- lib/openstax/utilities/development.rb
|
23
53
|
- lib/openstax/utilities/engine.rb
|
24
54
|
- lib/openstax/utilities/exceptions.rb
|
@@ -69,12 +99,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
99
|
- - ! '>='
|
70
100
|
- !ruby/object:Gem::Version
|
71
101
|
version: '0'
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
hash: -4255439280706106682
|
72
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
106
|
none: false
|
74
107
|
requirements:
|
75
108
|
- - ! '>='
|
76
109
|
- !ruby/object:Gem::Version
|
77
110
|
version: '0'
|
111
|
+
segments:
|
112
|
+
- 0
|
113
|
+
hash: -4255439280706106682
|
78
114
|
requirements: []
|
79
115
|
rubyforge_project:
|
80
116
|
rubygems_version: 1.8.24
|