nanoc3 3.2.4 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. metadata +14 -313
  2. data/.gemtest +0 -0
  3. data/ChangeLog +0 -3
  4. data/Gemfile +0 -29
  5. data/LICENSE +0 -19
  6. data/NEWS.md +0 -449
  7. data/README.md +0 -108
  8. data/Rakefile +0 -14
  9. data/bin/nanoc3 +0 -12
  10. data/doc/yardoc_templates/default/layout/html/footer.erb +0 -10
  11. data/lib/nanoc3.rb +0 -28
  12. data/lib/nanoc3/base.rb +0 -49
  13. data/lib/nanoc3/base/compilation/checksum_store.rb +0 -57
  14. data/lib/nanoc3/base/compilation/compiled_content_cache.rb +0 -62
  15. data/lib/nanoc3/base/compilation/compiler.rb +0 -455
  16. data/lib/nanoc3/base/compilation/compiler_dsl.rb +0 -214
  17. data/lib/nanoc3/base/compilation/dependency_tracker.rb +0 -196
  18. data/lib/nanoc3/base/compilation/filter.rb +0 -165
  19. data/lib/nanoc3/base/compilation/item_rep_proxy.rb +0 -102
  20. data/lib/nanoc3/base/compilation/item_rep_recorder_proxy.rb +0 -88
  21. data/lib/nanoc3/base/compilation/outdatedness_checker.rb +0 -223
  22. data/lib/nanoc3/base/compilation/outdatedness_reasons.rb +0 -46
  23. data/lib/nanoc3/base/compilation/rule.rb +0 -73
  24. data/lib/nanoc3/base/compilation/rule_context.rb +0 -84
  25. data/lib/nanoc3/base/compilation/rule_memory_calculator.rb +0 -40
  26. data/lib/nanoc3/base/compilation/rule_memory_store.rb +0 -53
  27. data/lib/nanoc3/base/compilation/rules_collection.rb +0 -231
  28. data/lib/nanoc3/base/context.rb +0 -47
  29. data/lib/nanoc3/base/core_ext.rb +0 -6
  30. data/lib/nanoc3/base/core_ext/array.rb +0 -62
  31. data/lib/nanoc3/base/core_ext/hash.rb +0 -63
  32. data/lib/nanoc3/base/core_ext/pathname.rb +0 -26
  33. data/lib/nanoc3/base/core_ext/string.rb +0 -46
  34. data/lib/nanoc3/base/directed_graph.rb +0 -275
  35. data/lib/nanoc3/base/errors.rb +0 -174
  36. data/lib/nanoc3/base/memoization.rb +0 -67
  37. data/lib/nanoc3/base/notification_center.rb +0 -84
  38. data/lib/nanoc3/base/ordered_hash.rb +0 -200
  39. data/lib/nanoc3/base/plugin_registry.rb +0 -165
  40. data/lib/nanoc3/base/result_data/item_rep.rb +0 -488
  41. data/lib/nanoc3/base/source_data/code_snippet.rb +0 -58
  42. data/lib/nanoc3/base/source_data/configuration.rb +0 -24
  43. data/lib/nanoc3/base/source_data/data_source.rb +0 -234
  44. data/lib/nanoc3/base/source_data/item.rb +0 -301
  45. data/lib/nanoc3/base/source_data/layout.rb +0 -130
  46. data/lib/nanoc3/base/source_data/site.rb +0 -361
  47. data/lib/nanoc3/base/store.rb +0 -135
  48. data/lib/nanoc3/cli.rb +0 -133
  49. data/lib/nanoc3/cli/command.rb +0 -139
  50. data/lib/nanoc3/cli/commands/autocompile.rb +0 -60
  51. data/lib/nanoc3/cli/commands/compile.rb +0 -280
  52. data/lib/nanoc3/cli/commands/create_item.rb +0 -62
  53. data/lib/nanoc3/cli/commands/create_layout.rb +0 -75
  54. data/lib/nanoc3/cli/commands/create_site.rb +0 -410
  55. data/lib/nanoc3/cli/commands/debug.rb +0 -119
  56. data/lib/nanoc3/cli/commands/info.rb +0 -98
  57. data/lib/nanoc3/cli/commands/nanoc.rb +0 -37
  58. data/lib/nanoc3/cli/commands/update.rb +0 -72
  59. data/lib/nanoc3/cli/commands/view.rb +0 -84
  60. data/lib/nanoc3/cli/commands/watch.rb +0 -125
  61. data/lib/nanoc3/cli/error_handler.rb +0 -193
  62. data/lib/nanoc3/cli/logger.rb +0 -91
  63. data/lib/nanoc3/data_sources.rb +0 -29
  64. data/lib/nanoc3/data_sources/deprecated/delicious.rb +0 -42
  65. data/lib/nanoc3/data_sources/deprecated/last_fm.rb +0 -87
  66. data/lib/nanoc3/data_sources/deprecated/twitter.rb +0 -38
  67. data/lib/nanoc3/data_sources/filesystem.rb +0 -299
  68. data/lib/nanoc3/data_sources/filesystem_unified.rb +0 -116
  69. data/lib/nanoc3/data_sources/filesystem_verbose.rb +0 -86
  70. data/lib/nanoc3/extra.rb +0 -22
  71. data/lib/nanoc3/extra/auto_compiler.rb +0 -103
  72. data/lib/nanoc3/extra/chick.rb +0 -125
  73. data/lib/nanoc3/extra/core_ext.rb +0 -4
  74. data/lib/nanoc3/extra/core_ext/enumerable.rb +0 -33
  75. data/lib/nanoc3/extra/core_ext/time.rb +0 -19
  76. data/lib/nanoc3/extra/deployers.rb +0 -11
  77. data/lib/nanoc3/extra/deployers/rsync.rb +0 -114
  78. data/lib/nanoc3/extra/file_proxy.rb +0 -40
  79. data/lib/nanoc3/extra/validators.rb +0 -12
  80. data/lib/nanoc3/extra/validators/links.rb +0 -264
  81. data/lib/nanoc3/extra/validators/w3c.rb +0 -95
  82. data/lib/nanoc3/extra/vcs.rb +0 -66
  83. data/lib/nanoc3/extra/vcses.rb +0 -17
  84. data/lib/nanoc3/extra/vcses/bazaar.rb +0 -25
  85. data/lib/nanoc3/extra/vcses/dummy.rb +0 -24
  86. data/lib/nanoc3/extra/vcses/git.rb +0 -25
  87. data/lib/nanoc3/extra/vcses/mercurial.rb +0 -25
  88. data/lib/nanoc3/extra/vcses/subversion.rb +0 -25
  89. data/lib/nanoc3/filters.rb +0 -53
  90. data/lib/nanoc3/filters/asciidoc.rb +0 -38
  91. data/lib/nanoc3/filters/bluecloth.rb +0 -19
  92. data/lib/nanoc3/filters/coderay.rb +0 -21
  93. data/lib/nanoc3/filters/colorize_syntax.rb +0 -261
  94. data/lib/nanoc3/filters/erb.rb +0 -35
  95. data/lib/nanoc3/filters/erubis.rb +0 -27
  96. data/lib/nanoc3/filters/haml.rb +0 -27
  97. data/lib/nanoc3/filters/kramdown.rb +0 -20
  98. data/lib/nanoc3/filters/less.rb +0 -53
  99. data/lib/nanoc3/filters/markaby.rb +0 -20
  100. data/lib/nanoc3/filters/maruku.rb +0 -20
  101. data/lib/nanoc3/filters/mustache.rb +0 -24
  102. data/lib/nanoc3/filters/rainpress.rb +0 -19
  103. data/lib/nanoc3/filters/rdiscount.rb +0 -22
  104. data/lib/nanoc3/filters/rdoc.rb +0 -33
  105. data/lib/nanoc3/filters/redcarpet.rb +0 -27
  106. data/lib/nanoc3/filters/redcloth.rb +0 -47
  107. data/lib/nanoc3/filters/relativize_paths.rb +0 -45
  108. data/lib/nanoc3/filters/rubypants.rb +0 -20
  109. data/lib/nanoc3/filters/sass.rb +0 -66
  110. data/lib/nanoc3/filters/slim.rb +0 -25
  111. data/lib/nanoc3/filters/typogruby.rb +0 -23
  112. data/lib/nanoc3/filters/uglify_js.rb +0 -42
  113. data/lib/nanoc3/helpers.rb +0 -16
  114. data/lib/nanoc3/helpers/blogging.rb +0 -319
  115. data/lib/nanoc3/helpers/breadcrumbs.rb +0 -40
  116. data/lib/nanoc3/helpers/capturing.rb +0 -138
  117. data/lib/nanoc3/helpers/filtering.rb +0 -50
  118. data/lib/nanoc3/helpers/html_escape.rb +0 -55
  119. data/lib/nanoc3/helpers/link_to.rb +0 -151
  120. data/lib/nanoc3/helpers/rendering.rb +0 -140
  121. data/lib/nanoc3/helpers/tagging.rb +0 -71
  122. data/lib/nanoc3/helpers/text.rb +0 -44
  123. data/lib/nanoc3/helpers/xml_sitemap.rb +0 -76
  124. data/lib/nanoc3/tasks.rb +0 -10
  125. data/lib/nanoc3/tasks/clean.rake +0 -16
  126. data/lib/nanoc3/tasks/clean.rb +0 -29
  127. data/lib/nanoc3/tasks/deploy/rsync.rake +0 -14
  128. data/lib/nanoc3/tasks/validate.rake +0 -92
  129. data/nanoc3.gemspec +0 -49
  130. data/tasks/doc.rake +0 -16
  131. data/tasks/test.rake +0 -44
  132. data/test/base/core_ext/array_spec.rb +0 -73
  133. data/test/base/core_ext/hash_spec.rb +0 -98
  134. data/test/base/core_ext/pathname_spec.rb +0 -27
  135. data/test/base/core_ext/string_spec.rb +0 -37
  136. data/test/base/test_checksum_store.rb +0 -35
  137. data/test/base/test_code_snippet.rb +0 -31
  138. data/test/base/test_compiler.rb +0 -316
  139. data/test/base/test_compiler_dsl.rb +0 -161
  140. data/test/base/test_context.rb +0 -31
  141. data/test/base/test_data_source.rb +0 -46
  142. data/test/base/test_dependency_tracker.rb +0 -262
  143. data/test/base/test_directed_graph.rb +0 -283
  144. data/test/base/test_filter.rb +0 -83
  145. data/test/base/test_item.rb +0 -179
  146. data/test/base/test_item_rep.rb +0 -553
  147. data/test/base/test_layout.rb +0 -59
  148. data/test/base/test_memoization.rb +0 -90
  149. data/test/base/test_notification_center.rb +0 -34
  150. data/test/base/test_outdatedness_checker.rb +0 -394
  151. data/test/base/test_plugin.rb +0 -30
  152. data/test/base/test_rule.rb +0 -19
  153. data/test/base/test_rule_context.rb +0 -65
  154. data/test/base/test_site.rb +0 -190
  155. data/test/cli/commands/test_compile.rb +0 -33
  156. data/test/cli/commands/test_create_item.rb +0 -14
  157. data/test/cli/commands/test_create_layout.rb +0 -28
  158. data/test/cli/commands/test_create_site.rb +0 -24
  159. data/test/cli/commands/test_help.rb +0 -12
  160. data/test/cli/commands/test_info.rb +0 -11
  161. data/test/cli/commands/test_update.rb +0 -10
  162. data/test/cli/test_cli.rb +0 -102
  163. data/test/cli/test_error_handler.rb +0 -29
  164. data/test/cli/test_logger.rb +0 -10
  165. data/test/data_sources/test_filesystem.rb +0 -433
  166. data/test/data_sources/test_filesystem_unified.rb +0 -536
  167. data/test/data_sources/test_filesystem_verbose.rb +0 -357
  168. data/test/extra/core_ext/test_enumerable.rb +0 -30
  169. data/test/extra/core_ext/test_time.rb +0 -15
  170. data/test/extra/deployers/test_rsync.rb +0 -232
  171. data/test/extra/test_auto_compiler.rb +0 -417
  172. data/test/extra/test_file_proxy.rb +0 -19
  173. data/test/extra/test_vcs.rb +0 -22
  174. data/test/extra/validators/test_links.rb +0 -51
  175. data/test/extra/validators/test_w3c.rb +0 -47
  176. data/test/filters/test_asciidoc.rb +0 -22
  177. data/test/filters/test_bluecloth.rb +0 -18
  178. data/test/filters/test_coderay.rb +0 -44
  179. data/test/filters/test_colorize_syntax.rb +0 -283
  180. data/test/filters/test_erb.rb +0 -99
  181. data/test/filters/test_erubis.rb +0 -70
  182. data/test/filters/test_haml.rb +0 -96
  183. data/test/filters/test_kramdown.rb +0 -18
  184. data/test/filters/test_less.rb +0 -113
  185. data/test/filters/test_markaby.rb +0 -24
  186. data/test/filters/test_maruku.rb +0 -18
  187. data/test/filters/test_mustache.rb +0 -25
  188. data/test/filters/test_rainpress.rb +0 -29
  189. data/test/filters/test_rdiscount.rb +0 -31
  190. data/test/filters/test_rdoc.rb +0 -18
  191. data/test/filters/test_redcarpet.rb +0 -63
  192. data/test/filters/test_redcloth.rb +0 -33
  193. data/test/filters/test_relativize_paths.rb +0 -332
  194. data/test/filters/test_rubypants.rb +0 -18
  195. data/test/filters/test_sass.rb +0 -229
  196. data/test/filters/test_slim.rb +0 -35
  197. data/test/filters/test_typogruby.rb +0 -21
  198. data/test/filters/test_uglify_js.rb +0 -30
  199. data/test/gem_loader.rb +0 -11
  200. data/test/helper.rb +0 -179
  201. data/test/helpers/test_blogging.rb +0 -754
  202. data/test/helpers/test_breadcrumbs.rb +0 -81
  203. data/test/helpers/test_capturing.rb +0 -41
  204. data/test/helpers/test_filtering.rb +0 -106
  205. data/test/helpers/test_html_escape.rb +0 -32
  206. data/test/helpers/test_link_to.rb +0 -249
  207. data/test/helpers/test_rendering.rb +0 -89
  208. data/test/helpers/test_tagging.rb +0 -87
  209. data/test/helpers/test_text.rb +0 -24
  210. data/test/helpers/test_xml_sitemap.rb +0 -103
  211. data/test/tasks/test_clean.rb +0 -67
@@ -1,174 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Nanoc3
4
-
5
- # Module that contains all nanoc-specific errors.
6
- module Errors
7
-
8
- # Generic error. Superclass for all nanoc-specific errors.
9
- class Generic < ::StandardError
10
- end
11
-
12
- # Error that is raised when a site is loaded that uses a data source with
13
- # an unknown identifier.
14
- class UnknownDataSource < Generic
15
-
16
- # @param [String] data_source_name The data source name for which no
17
- # data source could be found
18
- def initialize(data_source_name)
19
- super("The data source specified in the site’s configuration file, “#{data_source_name}”, does not exist.".make_compatible_with_env)
20
- end
21
-
22
- end
23
-
24
- # Error that is raised during site compilation when an item uses a layout
25
- # that is not present in the site.
26
- class UnknownLayout < Generic
27
-
28
- # @param [String] layout_identifier The layout identifier for which no
29
- # layout could be found
30
- def initialize(layout_identifier)
31
- super("The site does not have a layout with identifier “#{layout_identifier}”.".make_compatible_with_env)
32
- end
33
-
34
- end
35
-
36
- # Error that is raised during site compilation when an item uses a filter
37
- # that is not known.
38
- class UnknownFilter < Generic
39
-
40
- # @param [Symbol] filter_name The filter name for which no filter could
41
- # be found
42
- def initialize(filter_name)
43
- super("The requested filter, “#{filter_name}”, does not exist.".make_compatible_with_env)
44
- end
45
-
46
- end
47
-
48
- # Error that is raised during site compilation when a layout is compiled
49
- # for which the filter cannot be determined. This is similar to the
50
- # {UnknownFilter} error, but specific for filters for layouts.
51
- class CannotDetermineFilter < Generic
52
-
53
- # @param [String] layout_identifier The identifier of the layout for
54
- # which the filter could not be determined
55
- def initialize(layout_identifier)
56
- super("The filter to be used for the “#{layout_identifier}” layout could not be determined. Make sure the layout does have a filter.".make_compatible_with_env)
57
- end
58
-
59
- end
60
-
61
- # Error that is raised during site compilation when an item (directly or
62
- # indirectly) includes its own item content, leading to endless recursion.
63
- class RecursiveCompilation < Generic
64
-
65
- # @param [Array<Nanoc3::ItemRep>] reps A list of item representations
66
- # that mutually depend on each other
67
- def initialize(reps)
68
- super("The site cannot be compiled because the following items mutually depend on each other: #{reps.inspect}.".make_compatible_with_env)
69
- end
70
-
71
- end
72
-
73
- # Error that is raised when no rules file can be found in the current
74
- # working directory.
75
- class NoRulesFileFound < Generic
76
-
77
- def initialize
78
- super("This site does not have a rules file, which is required for nanoc sites.".make_compatible_with_env)
79
- end
80
-
81
- end
82
-
83
- # Error that is raised when no compilation rule that can be applied to the
84
- # current item can be found.
85
- class NoMatchingCompilationRuleFound < Generic
86
-
87
- # @param [Nanoc3::Item] item The item for which no compilation rule
88
- # could be found
89
- def initialize(item)
90
- super("No compilation rules were found for the “#{item.identifier}” item.".make_compatible_with_env)
91
- end
92
-
93
- end
94
-
95
- # Error that is raised when no routing rule that can be applied to the
96
- # current item can be found.
97
- class NoMatchingRoutingRuleFound < Generic
98
-
99
- # @param [Nanoc3::Item] item The item for which no routing rule could be
100
- # found
101
- def initialize(rep)
102
- super("No routing rules were found for the “#{rep.item.identifier}” item (rep “#{rep.name}”).".make_compatible_with_env)
103
- end
104
-
105
- end
106
-
107
- # Error that is raised when an rep cannot be compiled because it depends
108
- # on other representations.
109
- class UnmetDependency < Generic
110
-
111
- # @return [Nanoc3::ItemRep] The item representation that cannot yet be
112
- # compiled
113
- attr_reader :rep
114
-
115
- # @param [Nanoc3::ItemRep] The item representation that cannot yet be
116
- # compiled
117
- def initialize(rep)
118
- @rep = rep
119
- super("The current item cannot be compiled yet because of an unmet dependency on the “#{rep.item.identifier}” item (rep “#{rep.name}”).".make_compatible_with_env)
120
- end
121
-
122
- end
123
-
124
- # Error that is raised when a binary item is attempted to be laid out.
125
- class CannotLayoutBinaryItem < Generic
126
-
127
- # @param [Nanoc3::ItemRep] The item representation that was attempted to
128
- # be laid out
129
- def initialize(rep)
130
- super("The “{rep.item.identifier}” item (rep “#{rep.name}”) cannot be laid out because it is a binary item. If you are getting this error for an item that should be textual instead of binary, make sure that its extension is included in the text_extensions array in the site configuration.".make_compatible_with_env)
131
- end
132
-
133
- end
134
-
135
- # Error that is raised when a textual filter is attempted to be applied to
136
- # a binary item representation.
137
- class CannotUseTextualFilter < Generic
138
-
139
- # @param [Nanoc3::ItemRep] rep The item representation that was
140
- # attempted to be filtered
141
- #
142
- # @param [Class] filter_class The filter class that was used
143
- def initialize(rep, filter_class)
144
- super("The “#{filter_class.inspect}” filter cannot be used to filter the “#{rep.item.identifier}” item (rep “#{rep.name}”), because textual filters cannot be used on binary items.".make_compatible_with_env)
145
- end
146
-
147
- end
148
-
149
- # Error that is raised when a binary filter is attempted to be applied to
150
- # a textual item representation.
151
- class CannotUseBinaryFilter < Generic
152
-
153
- # @param [Nanoc3::ItemRep] rep The item representation that was
154
- # attempted to be filtered
155
- #
156
- # @param [Class] filter_class The filter class that was used
157
- def initialize(rep, filter_class)
158
- super("The “#{filter_class.inspect}” filter cannot be used to filter the “#{rep.item.identifier}” item (rep “#{rep.name}”), because binary filters cannot be used on textual items. If you are getting this error for an item that should be textual instead of binary, make sure that its extension is included in the text_extensions array in the site configuration.".make_compatible_with_env)
159
- end
160
-
161
- end
162
-
163
- # @deprecated No longer necessary, but kept for backwards compatibility.
164
- class DataNotYetAvailable < Generic
165
-
166
- def initialize(type, plural)
167
- super("#{type} #{plural ? 'are' : 'is'} not available yet. You may be missing a Nanoc3::Site#load_data call.".make_compatible_with_env)
168
- end
169
-
170
- end
171
-
172
- end
173
-
174
- end
@@ -1,67 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Nanoc3
4
-
5
- # Adds support for memoizing functions.
6
- #
7
- # @since 3.2.0
8
- module Memoization
9
-
10
- # Memoizes the method with the given name. The modified method will cache
11
- # the results of the original method, so that calling a method twice with
12
- # the same arguments will short-circuit and return the cached results
13
- # immediately.
14
- #
15
- # Memoization assumes that the current object as well as the function
16
- # arguments are immutable. Mutating the object or the arguments will not
17
- # cause memoized methods to recalculate their results. There is no way to
18
- # un-memoize a result, and calculation results will remain in memory even
19
- # if they are no longer needed.
20
- #
21
- # @example A fast fib function due to memoization
22
- #
23
- # class FibFast
24
- #
25
- # extend Nanoc3::Memoization
26
- #
27
- # def run(n)
28
- # if n == 0
29
- # 0
30
- # elsif n == 1
31
- # 1
32
- # else
33
- # run(n-1) + run(n-2)
34
- # end
35
- # end
36
- # memoize :run
37
- #
38
- # end
39
- #
40
- # @param [Symbol, String] method_name The name of the method to memoize
41
- #
42
- # @return [void]
43
- def memoize(method_name)
44
- # Alias
45
- original_method_name = '__nonmemoized_' + method_name.to_s
46
- alias_method original_method_name, method_name
47
-
48
- # Redefine
49
- define_method(method_name) do |*args|
50
- # Get cache
51
- @__memoization_cache ||= {}
52
- @__memoization_cache[method_name] ||= {}
53
-
54
- # Recalculate if necessary
55
- if !@__memoization_cache[method_name].has_key?(args)
56
- result = send(original_method_name, *args)
57
- @__memoization_cache[method_name][args] = result
58
- end
59
-
60
- # Done
61
- @__memoization_cache[method_name][args]
62
- end
63
- end
64
-
65
- end
66
-
67
- end
@@ -1,84 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Nanoc3
4
-
5
- # Provides a way to send notifications between objects. It allows blocks
6
- # associated with a certain notification name to be registered; these blocks
7
- # will be called when the notification with the given name is posted.
8
- #
9
- # It is a slightly different implementation of the Observer pattern; the
10
- # table of subscribers is not stored in the observable object itself, but in
11
- # the notification center.
12
- class NotificationCenter
13
-
14
- class << self
15
-
16
- # Adds the given block to the list of blocks that should be called when
17
- # the notification with the given name is received.
18
- #
19
- # @param [String, Symbol] name The name of the notification that will
20
- # cause the given block to be called.
21
- #
22
- # @param [String, Symbol, nil] id An identifier for the block. This is
23
- # only used to be able to remove the block (using the remove method)
24
- # later. Can be nil, but this is not recommended because it prevents
25
- # the given notification block from being unregistered.
26
- #
27
- # @yield [*args] Will be executed with the arguments passed to {.post}
28
- #
29
- # @return [void]
30
- def on(name, id=nil, &block)
31
- initialize_if_necessary(name)
32
-
33
- # Add observer
34
- @notifications[name] << { :id => id, :block => block }
35
- end
36
-
37
- # Posts a notification with the given name and the given arguments.
38
- #
39
- # @param [String, Symbol] name The name of the notification that should
40
- # be posted.
41
- #
42
- # @param args Arguments that wil be passed to the blocks handling the
43
- # notification.
44
- #
45
- # @return [void]
46
- def post(name, *args)
47
- initialize_if_necessary(name)
48
-
49
- # Notify all observers
50
- @notifications[name].each do |observer|
51
- observer[:block].call(*args)
52
- end
53
- end
54
-
55
- # Removes the block with the given identifier from the list of blocks
56
- # that should be called when the notification with the given name is
57
- # posted.
58
- #
59
- # @param [String, Symbol] name The name of the notification that should
60
- # no longer be registered.
61
- #
62
- # @param [String, Symbol] id The identifier of the block that should be
63
- # removed.
64
- #
65
- # @return [void]
66
- def remove(name, id)
67
- initialize_if_necessary(name)
68
-
69
- # Remove relevant observers
70
- @notifications[name].reject! { |i| i[:id] == id }
71
- end
72
-
73
- private
74
-
75
- def initialize_if_necessary(name)
76
- @notifications ||= {} # name => observers dictionary
77
- @notifications[name] ||= [] # list of observers
78
- end
79
-
80
- end
81
-
82
- end
83
-
84
- end
@@ -1,200 +0,0 @@
1
-
2
- # AUTHOR
3
- # jan molic /mig/at/1984/dot/cz/
4
- #
5
- # DESCRIPTION
6
- # Hash with preserved order and some array-like extensions
7
- # Public domain.
8
- #
9
- # THANKS
10
- # Andrew Johnson for his suggestions and fixes of Hash[],
11
- # merge, to_a, inspect and shift
12
- class OrderedHash < ::Hash
13
- attr_accessor :order
14
-
15
- class << self
16
- def [] *args
17
- hsh = OrderedHash.new
18
- if Hash === args[0]
19
- hsh.replace args[0]
20
- elsif (args.size % 2) != 0
21
- raise ArgumentError, "odd number of elements for Hash"
22
- else
23
- 0.step(args.size - 1, 2) do |a|
24
- b = a + 1
25
- hsh[args[a]] = args[b]
26
- end
27
- end
28
- hsh
29
- end
30
- end
31
- def initialize(*a, &b)
32
- super
33
- @order = []
34
- end
35
- def store_only a,b
36
- store a,b
37
- end
38
- alias orig_store store
39
- def store a,b
40
- @order.push a unless has_key? a
41
- super a,b
42
- end
43
- alias []= store
44
- def == hsh2
45
- return false if @order != hsh2.order
46
- super hsh2
47
- end
48
- def clear
49
- @order = []
50
- super
51
- end
52
- def delete key
53
- @order.delete key
54
- super
55
- end
56
- def each_key
57
- @order.each { |k| yield k }
58
- self
59
- end
60
- def each_value
61
- @order.each { |k| yield self[k] }
62
- self
63
- end
64
- def each
65
- @order.each { |k| yield k,self[k] }
66
- self
67
- end
68
- alias each_pair each
69
- def delete_if
70
- @order.clone.each { |k|
71
- delete k if yield(k)
72
- }
73
- self
74
- end
75
- def values
76
- ary = []
77
- @order.each { |k| ary.push self[k] }
78
- ary
79
- end
80
- def keys
81
- @order
82
- end
83
- def first
84
- {@order.first => self[@order.first]}
85
- end
86
- def last
87
- {@order.last => self[@order.last]}
88
- end
89
- def invert
90
- hsh2 = Hash.new
91
- @order.each { |k| hsh2[self[k]] = k }
92
- hsh2
93
- end
94
- def reject &block
95
- self.dup.delete_if &block
96
- end
97
- def reject! &block
98
- hsh2 = reject &block
99
- self == hsh2 ? nil : hsh2
100
- end
101
- def replace hsh2
102
- @order = hsh2.keys
103
- super hsh2
104
- end
105
- def shift
106
- key = @order.first
107
- key ? [key,delete(key)] : super
108
- end
109
- def unshift k,v
110
- unless self.include? k
111
- @order.unshift k
112
- orig_store(k,v)
113
- true
114
- else
115
- false
116
- end
117
- end
118
- def push k,v
119
- unless self.include? k
120
- @order.push k
121
- orig_store(k,v)
122
- true
123
- else
124
- false
125
- end
126
- end
127
- def pop
128
- key = @order.last
129
- key ? [key,delete(key)] : nil
130
- end
131
- def to_a
132
- ary = []
133
- each { |k,v| ary << [k,v] }
134
- ary
135
- end
136
- def to_s
137
- self.to_a.to_s
138
- end
139
- def inspect
140
- ary = []
141
- each {|k,v| ary << k.inspect + "=>" + v.inspect}
142
- '{' + ary.join(", ") + '}'
143
- end
144
- def update hsh2
145
- hsh2.each { |k,v| self[k] = v }
146
- self
147
- end
148
- alias :merge! update
149
- def merge hsh2
150
- self.dup update(hsh2)
151
- end
152
- def select
153
- ary = []
154
- each { |k,v| ary << [k,v] if yield k,v }
155
- ary
156
- end
157
- def class
158
- Hash
159
- end
160
- def __class__
161
- OrderedHash
162
- end
163
-
164
- attr_accessor "to_yaml_style"
165
- def yaml_inline= bool
166
- if respond_to?("to_yaml_style")
167
- self.to_yaml_style = :inline
168
- else
169
- unless defined? @__yaml_inline_meth
170
- @__yaml_inline_meth =
171
- lambda {|opts|
172
- YAML::quick_emit(object_id, opts) {|emitter|
173
- emitter << '{ ' << map{|kv| kv.join ': '}.join(', ') << ' }'
174
- }
175
- }
176
- class << self
177
- def to_yaml opts = {}
178
- begin
179
- @__yaml_inline ? @__yaml_inline_meth[ opts ] : super
180
- rescue
181
- @to_yaml_style = :inline
182
- super
183
- end
184
- end
185
- end
186
- end
187
- end
188
- @__yaml_inline = bool
189
- end
190
- def yaml_inline!() self.yaml_inline = true end
191
-
192
- def each_with_index
193
- @order.each_with_index { |k, index| yield k, self[k], index }
194
- self
195
- end
196
- end # class OrderedHash
197
-
198
- def OrderedHash(*a, &b)
199
- OrderedHash.new(*a, &b)
200
- end