openstax_utilities 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,19 +3,19 @@
3
3
 
4
4
  module BlockHelper
5
5
 
6
- def section_block(heading=nil, &block)
6
+ def osu_section_block(heading=nil, &block)
7
7
  presenter = OpenStax::Utilities::Blocks::SectionBlock.new(self, heading, block)
8
8
  end
9
9
 
10
- def table_block(&block)
10
+ def osu_table_block(&block)
11
11
  presenter = TableBlock.new(self, block)
12
12
  end
13
13
 
14
- def table_row_block(&block)
14
+ def osu_table_row_block(&block)
15
15
  presenter = TableRowBlock.new(self, block)
16
16
  end
17
17
 
18
- def table_cell_block(&block)
18
+ def osu_table_cell_block(&block)
19
19
  presenter = TableCellBlock.new(self, block)
20
20
  end
21
21
 
@@ -1,6 +1,6 @@
1
1
  module PartialHelper
2
2
 
3
- def block_to_partial(partial_name, options={}, &block)
3
+ def osu_block_to_partial(partial_name, options={}, &block)
4
4
  options.merge!(:body => capture(&block))
5
5
  render(:partial => partial_name, :locals => options)
6
6
  end
@@ -1,3 +1,7 @@
1
+ ActiveSupport::Inflector.inflections do |inflect|
2
+ inflect.acronym 'OpenStax'
3
+ end
4
+
1
5
  module OpenStax
2
6
  module Utilities
3
7
  class Engine < ::Rails::Engine
@@ -6,6 +10,13 @@ module OpenStax
6
10
  initializer "openstax_utilities.assets.precompile" do |app|
7
11
  app.config.assets.precompile += %w(openstax_utilities.css openstax_utilities.js)
8
12
  end
13
+
14
+ initializer 'openstax_utilities.action_controller' do |app|
15
+ ActiveSupport.on_load :action_controller do
16
+ helper BlockHelper
17
+ helper PartialHelper
18
+ end
19
+ end
9
20
  end
10
21
  end
11
22
  end
@@ -0,0 +1,45 @@
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
+ # A class for enum values
5
+ #
6
+ # Usage:
7
+ # class SomeClass < OpenStax::Utilities::Enum
8
+ # SOME_CONSTANT = 0
9
+ # ANOTHER_CONSTANT = 1
10
+ # end
11
+ #
12
+ # Note: do not use the same value more than once,
13
+ # or else only the last occurrence will be used
14
+ # when searching by value.
15
+
16
+ module OpenStax
17
+ module Utilities
18
+ class Enum
19
+ # When given a numeric value, returns the constant name
20
+ # When given a name, returns the constant value
21
+ def self.[](val)
22
+ return self.constants.select{|c| self.const_get(c) == val}.last if val.is_a?(Numeric)
23
+ val_sym = val.to_s.gsub(" ", "_").to_sym.upcase
24
+ self.const_defined?(val_sym) ? self.const_get(val_sym) : \
25
+ (self.const_defined?(val_sym.capitalize) ? self.const_get(val_sym.capitalize) : \
26
+ raise(NameError.new("wrong enum name #{val.to_s}")))
27
+ end
28
+
29
+ # Humanized list of constants
30
+ def self.list
31
+ self.constants.collect{|c| c.to_s.humanize}
32
+ end
33
+
34
+ # List of constant values
35
+ def self.values
36
+ self.constants.collect{|c| self.const_get(c)}
37
+ end
38
+
39
+ # Options ready to be used in a select tag
40
+ def self.options
41
+ self.constants.collect{|c| [c.to_s.humanize, self.const_get(c)]}
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,8 @@
1
+ # http://stackoverflow.com/a/1328093/1664216
2
+ module Kernel
3
+ def eigenclass
4
+ class << self
5
+ self
6
+ end
7
+ end
8
+ end
@@ -1,5 +1,5 @@
1
1
  module OpenStax
2
2
  module Utilities
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
@@ -3,6 +3,8 @@ require "openstax/utilities/version"
3
3
  require "openstax/utilities/exceptions"
4
4
  require "openstax/utilities/settings"
5
5
  require "openstax/utilities/access"
6
+ require "openstax/utilities/enum"
7
+ require "openstax/utilities/ruby"
6
8
 
7
9
  require 'openstax/utilities/blocks/block_base'
8
10
  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: 0.0.6
4
+ version: 0.0.7
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-06-30 00:00:00.000000000 Z
12
+ date: 2013-09-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -66,7 +66,9 @@ files:
66
66
  - lib/openstax/utilities/blocks/table_row_block.rb
67
67
  - lib/openstax/utilities/development.rb
68
68
  - lib/openstax/utilities/engine.rb
69
+ - lib/openstax/utilities/enum.rb
69
70
  - lib/openstax/utilities/exceptions.rb
71
+ - lib/openstax/utilities/ruby.rb
70
72
  - lib/openstax/utilities/settings.rb
71
73
  - lib/openstax/utilities/version.rb
72
74
  - lib/openstax_utilities.rb
@@ -116,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
118
  version: '0'
117
119
  segments:
118
120
  - 0
119
- hash: 3071181377175490331
121
+ hash: -491942878868703970
120
122
  required_rubygems_version: !ruby/object:Gem::Requirement
121
123
  none: false
122
124
  requirements:
@@ -125,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
127
  version: '0'
126
128
  segments:
127
129
  - 0
128
- hash: 3071181377175490331
130
+ hash: -491942878868703970
129
131
  requirements: []
130
132
  rubyforge_project:
131
133
  rubygems_version: 1.8.24