hashbrowns 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. data/.document +5 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +17 -0
  4. data/Gemfile.lock +79 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.md +9 -0
  7. data/Rakefile +53 -0
  8. data/TODO +17 -0
  9. data/VERSION +1 -0
  10. data/example/.gitignore +15 -0
  11. data/example/.rvmrc +1 -0
  12. data/example/Gemfile +45 -0
  13. data/example/Gemfile.lock +143 -0
  14. data/example/README.rdoc +261 -0
  15. data/example/Rakefile +7 -0
  16. data/example/app/assets/images/rails.png +0 -0
  17. data/example/app/assets/javascripts/application.js +16 -0
  18. data/example/app/assets/javascripts/customers.js.coffee +3 -0
  19. data/example/app/assets/javascripts/destinations.js.coffee +3 -0
  20. data/example/app/assets/javascripts/orders.js.coffee +3 -0
  21. data/example/app/assets/stylesheets/application.css.scss +25 -0
  22. data/example/app/assets/stylesheets/bootstrap_and_overrides.css.scss +3 -0
  23. data/example/app/assets/stylesheets/customers.css.scss +3 -0
  24. data/example/app/assets/stylesheets/destinations.css.scss +3 -0
  25. data/example/app/assets/stylesheets/orders.css.scss +3 -0
  26. data/example/app/assets/stylesheets/scaffolds.css.scss +69 -0
  27. data/example/app/controllers/application_controller.rb +3 -0
  28. data/example/app/controllers/customers_controller.rb +90 -0
  29. data/example/app/controllers/destinations_controller.rb +89 -0
  30. data/example/app/controllers/orders_controller.rb +88 -0
  31. data/example/app/helpers/application_helper.rb +2 -0
  32. data/example/app/helpers/customers_helper.rb +2 -0
  33. data/example/app/helpers/destinations_helper.rb +2 -0
  34. data/example/app/helpers/orders_helper.rb +2 -0
  35. data/example/app/mailers/.gitkeep +0 -0
  36. data/example/app/models/.gitkeep +0 -0
  37. data/example/app/models/customer.rb +5 -0
  38. data/example/app/models/destination.rb +4 -0
  39. data/example/app/models/order.rb +5 -0
  40. data/example/app/views/customers/_form.html.erb +33 -0
  41. data/example/app/views/customers/edit.html.erb +6 -0
  42. data/example/app/views/customers/full.rabl +2 -0
  43. data/example/app/views/customers/index.html.erb +10 -0
  44. data/example/app/views/customers/index.rabl +5 -0
  45. data/example/app/views/customers/new.html.erb +5 -0
  46. data/example/app/views/customers/show.html.erb +25 -0
  47. data/example/app/views/customers/show.rabl +5 -0
  48. data/example/app/views/destinations/_form.html.erb +41 -0
  49. data/example/app/views/destinations/edit.html.erb +6 -0
  50. data/example/app/views/destinations/full.rabl +2 -0
  51. data/example/app/views/destinations/index.html.erb +10 -0
  52. data/example/app/views/destinations/index.rabl +5 -0
  53. data/example/app/views/destinations/new.html.erb +5 -0
  54. data/example/app/views/destinations/show.html.erb +35 -0
  55. data/example/app/views/destinations/show.rabl +5 -0
  56. data/example/app/views/layouts/application.html.erb +14 -0
  57. data/example/app/views/orders/_form.html.erb +29 -0
  58. data/example/app/views/orders/edit.html.erb +6 -0
  59. data/example/app/views/orders/full.rabl +2 -0
  60. data/example/app/views/orders/index.html.erb +10 -0
  61. data/example/app/views/orders/index.rabl +5 -0
  62. data/example/app/views/orders/new.html.erb +5 -0
  63. data/example/app/views/orders/show.html.erb +20 -0
  64. data/example/app/views/orders/show.rabl +8 -0
  65. data/example/config/application.rb +62 -0
  66. data/example/config/boot.rb +6 -0
  67. data/example/config/database.yml +20 -0
  68. data/example/config/environment.rb +5 -0
  69. data/example/config/environments/development.rb +37 -0
  70. data/example/config/environments/production.rb +67 -0
  71. data/example/config/environments/test.rb +37 -0
  72. data/example/config/initializers/backtrace_silencers.rb +7 -0
  73. data/example/config/initializers/hashbrowns.rb +34 -0
  74. data/example/config/initializers/inflections.rb +15 -0
  75. data/example/config/initializers/mime_types.rb +5 -0
  76. data/example/config/initializers/secret_token.rb +7 -0
  77. data/example/config/initializers/session_store.rb +8 -0
  78. data/example/config/initializers/wrap_parameters.rb +14 -0
  79. data/example/config/locales/en.yml +5 -0
  80. data/example/config/routes.rb +64 -0
  81. data/example/config.ru +4 -0
  82. data/example/db/migrate/20121102164922_create_customers.rb +12 -0
  83. data/example/db/migrate/20121102165116_create_orders.rb +12 -0
  84. data/example/db/migrate/20121102165208_create_destinations.rb +15 -0
  85. data/example/db/schema.rb +45 -0
  86. data/example/db/seeds.rb +51 -0
  87. data/example/lib/assets/.gitkeep +0 -0
  88. data/example/lib/tasks/.gitkeep +0 -0
  89. data/example/log/.gitkeep +0 -0
  90. data/example/public/404.html +26 -0
  91. data/example/public/422.html +26 -0
  92. data/example/public/500.html +25 -0
  93. data/example/public/favicon.ico +0 -0
  94. data/example/public/index.html +241 -0
  95. data/example/public/robots.txt +5 -0
  96. data/example/script/rails +6 -0
  97. data/example/test/fixtures/.gitkeep +0 -0
  98. data/example/test/fixtures/customers.yml +13 -0
  99. data/example/test/fixtures/destinations.yml +17 -0
  100. data/example/test/fixtures/orders.yml +11 -0
  101. data/example/test/functional/.gitkeep +0 -0
  102. data/example/test/functional/customers_controller_test.rb +49 -0
  103. data/example/test/functional/destinations_controller_test.rb +49 -0
  104. data/example/test/functional/orders_controller_test.rb +49 -0
  105. data/example/test/integration/.gitkeep +0 -0
  106. data/example/test/performance/browsing_test.rb +12 -0
  107. data/example/test/test_helper.rb +13 -0
  108. data/example/test/unit/.gitkeep +0 -0
  109. data/example/test/unit/customer_test.rb +7 -0
  110. data/example/test/unit/destination_test.rb +7 -0
  111. data/example/test/unit/helpers/customers_helper_test.rb +4 -0
  112. data/example/test/unit/helpers/destinations_helper_test.rb +4 -0
  113. data/example/test/unit/helpers/orders_helper_test.rb +4 -0
  114. data/example/test/unit/order_test.rb +7 -0
  115. data/example/vendor/assets/javascripts/.gitkeep +0 -0
  116. data/example/vendor/assets/stylesheets/.gitkeep +0 -0
  117. data/example/vendor/plugins/.gitkeep +0 -0
  118. data/hashbrowns.gemspec +185 -0
  119. data/lib/hashbrowns/configuration.rb +129 -0
  120. data/lib/hashbrowns/helpers/display_helpers.rb +27 -0
  121. data/lib/hashbrowns/helpers/links_helpers.rb +24 -0
  122. data/lib/hashbrowns/helpers/overview_helpers.rb +20 -0
  123. data/lib/hashbrowns/helpers/relations_helpers.rb +9 -0
  124. data/lib/hashbrowns/helpers/renderer_helpers.rb +12 -0
  125. data/lib/hashbrowns/railtie.rb +17 -0
  126. data/lib/hashbrowns/views/hashbrowns/_overview.html.haml +20 -0
  127. data/lib/hashbrowns/views/hashbrowns/_recursive_hash_tabler.html.haml +27 -0
  128. data/lib/hashbrowns.rb +16 -0
  129. data/test/helper.rb +18 -0
  130. data/test/test_hash_tabler.rb +7 -0
  131. metadata +249 -0
File without changes
@@ -0,0 +1,185 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "hashbrowns"
8
+ s.version = "0.1.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["crimsonknave"]
12
+ s.date = "2012-11-13"
13
+ s.description = "Provides a DSL and helpers to convert hashes into html tables. Allows you to create overviews with selected fields, define keys whose values link to a url and so on."
14
+ s.email = "crimsonknave@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md",
18
+ "TODO"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".rvmrc",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.md",
27
+ "Rakefile",
28
+ "TODO",
29
+ "VERSION",
30
+ "example/.gitignore",
31
+ "example/.rvmrc",
32
+ "example/Gemfile",
33
+ "example/Gemfile.lock",
34
+ "example/README.rdoc",
35
+ "example/Rakefile",
36
+ "example/app/assets/images/rails.png",
37
+ "example/app/assets/javascripts/application.js",
38
+ "example/app/assets/javascripts/customers.js.coffee",
39
+ "example/app/assets/javascripts/destinations.js.coffee",
40
+ "example/app/assets/javascripts/orders.js.coffee",
41
+ "example/app/assets/stylesheets/application.css.scss",
42
+ "example/app/assets/stylesheets/bootstrap_and_overrides.css.scss",
43
+ "example/app/assets/stylesheets/customers.css.scss",
44
+ "example/app/assets/stylesheets/destinations.css.scss",
45
+ "example/app/assets/stylesheets/orders.css.scss",
46
+ "example/app/assets/stylesheets/scaffolds.css.scss",
47
+ "example/app/controllers/application_controller.rb",
48
+ "example/app/controllers/customers_controller.rb",
49
+ "example/app/controllers/destinations_controller.rb",
50
+ "example/app/controllers/orders_controller.rb",
51
+ "example/app/helpers/application_helper.rb",
52
+ "example/app/helpers/customers_helper.rb",
53
+ "example/app/helpers/destinations_helper.rb",
54
+ "example/app/helpers/orders_helper.rb",
55
+ "example/app/mailers/.gitkeep",
56
+ "example/app/models/.gitkeep",
57
+ "example/app/models/customer.rb",
58
+ "example/app/models/destination.rb",
59
+ "example/app/models/order.rb",
60
+ "example/app/views/customers/_form.html.erb",
61
+ "example/app/views/customers/edit.html.erb",
62
+ "example/app/views/customers/full.rabl",
63
+ "example/app/views/customers/index.html.erb",
64
+ "example/app/views/customers/index.rabl",
65
+ "example/app/views/customers/new.html.erb",
66
+ "example/app/views/customers/show.html.erb",
67
+ "example/app/views/customers/show.rabl",
68
+ "example/app/views/destinations/_form.html.erb",
69
+ "example/app/views/destinations/edit.html.erb",
70
+ "example/app/views/destinations/full.rabl",
71
+ "example/app/views/destinations/index.html.erb",
72
+ "example/app/views/destinations/index.rabl",
73
+ "example/app/views/destinations/new.html.erb",
74
+ "example/app/views/destinations/show.html.erb",
75
+ "example/app/views/destinations/show.rabl",
76
+ "example/app/views/layouts/application.html.erb",
77
+ "example/app/views/orders/_form.html.erb",
78
+ "example/app/views/orders/edit.html.erb",
79
+ "example/app/views/orders/full.rabl",
80
+ "example/app/views/orders/index.html.erb",
81
+ "example/app/views/orders/index.rabl",
82
+ "example/app/views/orders/new.html.erb",
83
+ "example/app/views/orders/show.html.erb",
84
+ "example/app/views/orders/show.rabl",
85
+ "example/config.ru",
86
+ "example/config/application.rb",
87
+ "example/config/boot.rb",
88
+ "example/config/database.yml",
89
+ "example/config/environment.rb",
90
+ "example/config/environments/development.rb",
91
+ "example/config/environments/production.rb",
92
+ "example/config/environments/test.rb",
93
+ "example/config/initializers/backtrace_silencers.rb",
94
+ "example/config/initializers/hashbrowns.rb",
95
+ "example/config/initializers/inflections.rb",
96
+ "example/config/initializers/mime_types.rb",
97
+ "example/config/initializers/secret_token.rb",
98
+ "example/config/initializers/session_store.rb",
99
+ "example/config/initializers/wrap_parameters.rb",
100
+ "example/config/locales/en.yml",
101
+ "example/config/routes.rb",
102
+ "example/db/migrate/20121102164922_create_customers.rb",
103
+ "example/db/migrate/20121102165116_create_orders.rb",
104
+ "example/db/migrate/20121102165208_create_destinations.rb",
105
+ "example/db/schema.rb",
106
+ "example/db/seeds.rb",
107
+ "example/lib/assets/.gitkeep",
108
+ "example/lib/tasks/.gitkeep",
109
+ "example/log/.gitkeep",
110
+ "example/public/404.html",
111
+ "example/public/422.html",
112
+ "example/public/500.html",
113
+ "example/public/favicon.ico",
114
+ "example/public/index.html",
115
+ "example/public/robots.txt",
116
+ "example/script/rails",
117
+ "example/test/fixtures/.gitkeep",
118
+ "example/test/fixtures/customers.yml",
119
+ "example/test/fixtures/destinations.yml",
120
+ "example/test/fixtures/orders.yml",
121
+ "example/test/functional/.gitkeep",
122
+ "example/test/functional/customers_controller_test.rb",
123
+ "example/test/functional/destinations_controller_test.rb",
124
+ "example/test/functional/orders_controller_test.rb",
125
+ "example/test/integration/.gitkeep",
126
+ "example/test/performance/browsing_test.rb",
127
+ "example/test/test_helper.rb",
128
+ "example/test/unit/.gitkeep",
129
+ "example/test/unit/customer_test.rb",
130
+ "example/test/unit/destination_test.rb",
131
+ "example/test/unit/helpers/customers_helper_test.rb",
132
+ "example/test/unit/helpers/destinations_helper_test.rb",
133
+ "example/test/unit/helpers/orders_helper_test.rb",
134
+ "example/test/unit/order_test.rb",
135
+ "example/vendor/assets/javascripts/.gitkeep",
136
+ "example/vendor/assets/stylesheets/.gitkeep",
137
+ "example/vendor/plugins/.gitkeep",
138
+ "hashbrowns.gemspec",
139
+ "lib/hashbrowns.rb",
140
+ "lib/hashbrowns/configuration.rb",
141
+ "lib/hashbrowns/helpers/display_helpers.rb",
142
+ "lib/hashbrowns/helpers/links_helpers.rb",
143
+ "lib/hashbrowns/helpers/overview_helpers.rb",
144
+ "lib/hashbrowns/helpers/relations_helpers.rb",
145
+ "lib/hashbrowns/helpers/renderer_helpers.rb",
146
+ "lib/hashbrowns/railtie.rb",
147
+ "lib/hashbrowns/views/hashbrowns/_overview.html.haml",
148
+ "lib/hashbrowns/views/hashbrowns/_recursive_hash_tabler.html.haml",
149
+ "test/helper.rb",
150
+ "test/test_hash_tabler.rb"
151
+ ]
152
+ s.homepage = "http://github.com/crimsonknave/hashbrowns"
153
+ s.licenses = ["MIT"]
154
+ s.require_paths = ["lib"]
155
+ s.rubygems_version = "1.8.11"
156
+ s.summary = "Cooks your hashes into html"
157
+
158
+ if s.respond_to? :specification_version then
159
+ s.specification_version = 3
160
+
161
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
162
+ s.add_runtime_dependency(%q<haml-rails>, [">= 0"])
163
+ s.add_runtime_dependency(%q<rake>, ["= 0.8.7"])
164
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
165
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
166
+ s.add_development_dependency(%q<bundler>, [">= 0"])
167
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
168
+ else
169
+ s.add_dependency(%q<haml-rails>, [">= 0"])
170
+ s.add_dependency(%q<rake>, ["= 0.8.7"])
171
+ s.add_dependency(%q<shoulda>, [">= 0"])
172
+ s.add_dependency(%q<rdoc>, [">= 0"])
173
+ s.add_dependency(%q<bundler>, [">= 0"])
174
+ s.add_dependency(%q<jeweler>, [">= 0"])
175
+ end
176
+ else
177
+ s.add_dependency(%q<haml-rails>, [">= 0"])
178
+ s.add_dependency(%q<rake>, ["= 0.8.7"])
179
+ s.add_dependency(%q<shoulda>, [">= 0"])
180
+ s.add_dependency(%q<rdoc>, [">= 0"])
181
+ s.add_dependency(%q<bundler>, [">= 0"])
182
+ s.add_dependency(%q<jeweler>, [">= 0"])
183
+ end
184
+ end
185
+
@@ -0,0 +1,129 @@
1
+ module HashBrowns
2
+ class Configuration
3
+ attr_accessor :link_hash, :link_for_id, :links, :link_parents, :key_fields, :parent_overrides, :status_hash, :table_styles, :key_fields, :pretty_names, :important, :ignore_important_case
4
+
5
+ VALID_STATUSES = %w(success info warning error)
6
+
7
+ def initialize
8
+ @link_hash = Hash.new
9
+ @link_for_id = Hash.new
10
+ @links = Set.new
11
+ @link_parents = Hash.new
12
+ @pretty_names = Hash.new
13
+ @important = Hash.new
14
+ @ignore_important_case = false
15
+
16
+ @status_hash = {
17
+ "green" => "success",
18
+ "blue" => "info",
19
+ "red" => "error",
20
+ "yellow" => "warning"
21
+ }
22
+
23
+ @table_styles = Set.new
24
+ @key_fields = Hash.new
25
+ @parent_overrides = Set.new
26
+
27
+ end
28
+
29
+ def add_status_mapping(name, status)
30
+ raise "Unknown Status" unless VALID_STATUSES.include?(status)
31
+ @status_hash[name] = status
32
+ end
33
+
34
+ def add_table_style(style)
35
+ @table_styles.add(style)
36
+ end
37
+ def add_table_styles(*styles)
38
+ @table_styles.merge(styles)
39
+ end
40
+
41
+ def add_parent_overrides(*parents)
42
+ @parent_overrides.merge(parents)
43
+ end
44
+
45
+ def add_parent_override(parent)
46
+ @parent_overrides.add(parent)
47
+ end
48
+
49
+ def add_overview_field(type, value, *path)
50
+ type, value, path = type.to_s, value.to_s, path.map{|p| p.to_s}
51
+ @key_fields[type] = Hash.new unless @key_fields.has_key?(type)
52
+ insert_value(@key_fields[type], value, path)
53
+ end
54
+
55
+ def add_important_name(name, value, status)
56
+ name, value, status = name.to_s, value.to_s, status.to_s
57
+ value = value.downcase if @ignore_important_case && value.kind_of?(String)
58
+ status = @status_hash[status] if @status_hash.has_key?(status)
59
+ if value.kind_of?(Proc)
60
+ @important[name] = value
61
+ return
62
+ end
63
+
64
+ @important[name] = Hash.new unless @important.has_key?(name)
65
+ @important[name][value] = status
66
+ end
67
+
68
+ def add_formatted_name(real, formatted, source)
69
+ real, formatted, source = real.to_s, formatted.to_s, source.to_s
70
+ @pretty_names[real] = Hash.new unless @pretty_names.has_key?(real)
71
+ @pretty_names[real][source] = formatted
72
+ end
73
+
74
+ def add_external_links(*names)
75
+ @links.merge names.map{|x| x.to_s}
76
+ end
77
+
78
+ def add_external_link(name)
79
+ @links.add name.to_s
80
+ end
81
+
82
+ def add_link_for_id(key, parent)
83
+ key = key.to_s
84
+ @link_for_id[key] = Set.new if @link_for_id[key].nil?
85
+ @link_for_id[key].add(parent.to_s)
86
+ end
87
+
88
+ def add_links_for_id(key, parents)
89
+ key = key.to_s
90
+ @link_for_id[key] = Set.new if @link_for_id[key].nil?
91
+ @link_for_id[key].merge(parents.map(&:to_s))
92
+ end
93
+
94
+ def add_link_by_key(key, path)
95
+ @link_hash[key.to_s] = path.to_s
96
+ end
97
+
98
+ def add_link_by_parent(parent, key, path)
99
+ if @link_parents.has_key?(parent.to_s)
100
+ @link_parents[parent.to_s][key.to_s] = path.to_s
101
+ else
102
+ @link_parents[parent.to_s] = { key.to_s => path.to_s }
103
+ end
104
+ end
105
+
106
+ def add_link_by_parents(parents, key, path)
107
+ parents.each do |parent|
108
+ if @link_parents.has_key?(parent.to_s)
109
+ @link_parents[parent.to_s][key.to_s] = path.to_s
110
+ else
111
+ @link_parents[parent.to_s] = { key.to_s => path.to_s }
112
+ end
113
+ end
114
+ end
115
+
116
+ private
117
+ def insert_value(hash, value, path)
118
+ current = path.shift
119
+ if current.nil?
120
+ hash[:values] = Set.new unless hash.has_key?(:values)
121
+ hash[:values].add(value)
122
+ return true
123
+ end
124
+ hash[current] = Hash.new unless hash.has_key?(current)
125
+ return insert_value(hash[current], value, path)
126
+ end
127
+
128
+ end
129
+ end
@@ -0,0 +1,27 @@
1
+ module HashBrowns
2
+ module DisplayHelpers
3
+
4
+ def table_styles
5
+ return HashBrowns.conf.table_styles.to_a.join(" ")
6
+ end
7
+
8
+ def importantize(key, value)
9
+ value = value.downcase if HashBrowns.conf.ignore_important_case && value.kind_of?(String)
10
+ #puts "k: #{key}, v: #{value}"
11
+ return "nil key" if key.nil?
12
+ return "nil value" if value.nil?
13
+ return "#{key} not important" unless HashBrowns.conf.important.has_key?(key)
14
+ return "#{HashBrowns.conf.important[key].call(value)}" if HashBrowns.conf.important[key].kind_of?(Proc)
15
+ return "#{value} not important for #{key}" unless HashBrowns.conf.important[key].has_key?(value)
16
+ return "#{HashBrowns.conf.important[key][value]}"
17
+ end
18
+
19
+ def display_name(name, table)
20
+ names = HashBrowns.conf.pretty_names[name]
21
+ return name unless names
22
+ return names[table] ? names[table] : name
23
+ return names["all"] if names.has_key?("all")
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ module HashBrowns
2
+ module LinksHelpers
3
+ def linkify(key, value, parent = false, id = false, text = false)
4
+ return "" if value.nil? or key.nil?
5
+ key, value, parent, id, text = key.to_s, value.to_s, parent.to_s, id.to_s, text.to_s
6
+ text = value if text
7
+ puts "k #{key}, v #{value}, p #{parent} i #{id} t #{text}"
8
+ return link_to(text, HashBrowns.conf.link_parents[parent][key]+value).html_safe if parent && HashBrowns.conf.link_parents.has_key?(parent) && HashBrowns.conf.link_parents[parent].has_key?(key)
9
+ return link_to(text, HashBrowns.conf.link_hash[key]+value).html_safe if HashBrowns.conf.link_hash.has_key?(key)
10
+ return link_to(text, value).html_safe if HashBrowns.conf.links.include?(key)
11
+ return link_to(text, HashBrowns.conf.link_parents[parent]["id"]+id).html_safe if id && parent && HashBrowns.conf.link_for_id.has_key?(key) && HashBrowns.conf.link_for_id[key].include?(parent)
12
+ return value
13
+ end
14
+
15
+ def get_value_and_id(object, path)
16
+ #puts "o #{object.inspect} p #{p.inspect}"
17
+ value = object[path.shift.to_s]
18
+ value = "false" if value.nil?
19
+ #puts "value is '#{value}'"
20
+ return value.to_s, object["id"] if path.empty? or value.nil?
21
+ return get_value_and_id(value, path)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ module HashBrowns
2
+ module OverviewHelpers
3
+
4
+ def overview_fields(type)
5
+ type = type.to_s
6
+ fields = HashBrowns.conf.key_fields[type]
7
+ return [] unless fields
8
+ puts "calling field parser now"
9
+ return field_parser(type, fields, [])
10
+ end
11
+
12
+ def field_parser(k, v, path)
13
+ k, path = k.to_s, path.map{|p| p.to_s}
14
+ return "#{k} had nil value at #{path.inspect}" if v.nil?
15
+ return v.map{|i| [display_name(i, path.last), path + [i]] } if k == "values"
16
+ return v.map{|ki, vi| field_parser(ki, vi, path + [k]) }.inject(:+)
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ module HashBrowns
2
+ module RelationsHelpers
3
+
4
+ def parent_setter(child, parent)
5
+ return parent if HashBrowns.conf.parent_overrides.include?(parent)
6
+ return child
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ module HashBrowns
2
+ module RendererHelpers
3
+ def render_hash_to_overview(type, object)
4
+ #We don't pass in overview_fields here once because we shift the path and that messes up the case the overview is an array
5
+ render :partial => "hashbrowns/overview", :locals => { :object => object, :type => type }
6
+ end
7
+
8
+ def render_hash_to_table(object, parent = "")
9
+ render :partial => "hashbrowns/recursive_hash_tabler", :locals => {:object => object, :parent => parent}
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ require 'hashbrowns/helpers/display_helpers'
2
+ require 'hashbrowns/helpers/overview_helpers'
3
+ require 'hashbrowns/helpers/links_helpers'
4
+ require 'hashbrowns/helpers/relations_helpers'
5
+ require 'hashbrowns/helpers/renderer_helpers'
6
+ module HashBrowns
7
+ class Railtie < Rails::Engine
8
+ initializer "hashbrowns.view_helpers" do
9
+ ActionView::Base.send :include, DisplayHelpers
10
+ ActionView::Base.send :include, OverviewHelpers
11
+ ActionView::Base.send :include, LinksHelpers
12
+ ActionView::Base.send :include, RelationsHelpers
13
+ ActionView::Base.send :include, RendererHelpers
14
+ end
15
+ paths["app/views"] = "lib/hashbrowns/views"
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ %table{:class => table_styles}
2
+ - if object.kind_of?(Array)
3
+ %tr
4
+ - overview_fields(type).each do |k, path|
5
+ %th= k.to_s.humanize
6
+ - object.each do |o|
7
+ %tr
8
+ - overview_fields(type).each do |k, path|
9
+ - parent = path.empty? ? type : path[-2]
10
+ - path.shift
11
+ - value, id = get_value_and_id(o, path)
12
+ %td{:class => importantize(k, value)}= linkify(k, value, parent, id)
13
+ - else
14
+ - overview_fields(type).each do |k, path|
15
+ - parent = path.empty? ? type : path[-2]
16
+ - path.shift
17
+ - value, id = get_value_and_id(object, path)
18
+ %tr{ :class => importantize(k, value)}
19
+ %td= k.to_s.humanize
20
+ %td= linkify(k, value, parent, id)
@@ -0,0 +1,27 @@
1
+ - if object.kind_of?(Array)
2
+ - object.each do |i|
3
+ = render :partial => "hashbrowns/recursive_hash_tabler", :locals => { :object => i, :parent => parent }
4
+ - elsif
5
+ %table{:class => table_styles}
6
+ - object.each_pair do |k,v|
7
+ - if v.kind_of?(Hash)
8
+ %tr
9
+ %td= k
10
+ %td= render :partial => "hashbrowns/recursive_hash_tabler", :locals => { :object => v, :parent => parent_setter(k,parent) } unless v.blank?
11
+ - elsif v.kind_of?(Array)
12
+ %tr
13
+ %td= k
14
+ %td
15
+ - v.each do |i|
16
+ - if i.kind_of?(Hash)
17
+ = render :partial => "hashbrowns/recursive_hash_tabler", :locals => { :object => i, :parent => parent_setter(k, parent) } unless i.blank?
18
+ - else
19
+ %tr{ :class => importantize(k, v) }
20
+ %td= k
21
+ %td
22
+ - if defined?(parent)
23
+ = linkify(k,v,parent)
24
+ - else
25
+ = linkify(k,v)
26
+ - else
27
+ = object
data/lib/hashbrowns.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'hashbrowns/railtie' if defined?(Rails)
2
+ require 'haml'
3
+ require 'hashbrowns/configuration'
4
+
5
+ module HashBrowns
6
+ class << self
7
+ def configure(&block)
8
+ yield(conf)
9
+ conf
10
+ end
11
+
12
+ def conf
13
+ @_configuration ||= Configuration.new
14
+ end
15
+ end
16
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'hashbrowns'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestHashTabler < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end