rails_codebook 0.0.1.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +17 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +10 -0
  7. data/Gemfile +6 -0
  8. data/LICENSE.txt +22 -0
  9. data/MIT-LICENSE +22 -0
  10. data/README.md +31 -0
  11. data/Rakefile +1 -0
  12. data/app/assets/javascripts/rails_codebook/application.js +16 -0
  13. data/app/assets/javascripts/rails_codebook/bootstrap.js +5 -0
  14. data/app/assets/javascripts/rails_codebook/codebooks.js +27 -0
  15. data/app/assets/javascripts/rails_codebook/jquery.autosize.js +192 -0
  16. data/app/assets/stylesheets/rails_codebook/application.css +13 -0
  17. data/app/assets/stylesheets/rails_codebook/bootstrap_and_overrides.css +7 -0
  18. data/app/assets/stylesheets/rails_codebook/codebooks.css +44 -0
  19. data/app/controllers/rails_codebook/admin/codebooks_controller.rb +65 -0
  20. data/app/controllers/rails_codebook/api/codebooks_controller.rb +44 -0
  21. data/app/helpers/rails_codebook/admin/codebooks_helper.rb +43 -0
  22. data/app/models/rails_codebook/codebook.rb +44 -0
  23. data/app/views/layouts/rails_codebook/application.html.erb +35 -0
  24. data/app/views/rails_codebook/admin/codebooks/_codebook.html.erb +44 -0
  25. data/app/views/rails_codebook/admin/codebooks/create.js.erb +9 -0
  26. data/app/views/rails_codebook/admin/codebooks/destroy.js.erb +2 -0
  27. data/app/views/rails_codebook/admin/codebooks/index.html.erb +90 -0
  28. data/config/initializers/will_paginate.rb +3 -0
  29. data/config/locales/cs.yml +268 -0
  30. data/config/locales/en.yml +11 -0
  31. data/config/routes.rb +25 -0
  32. data/lib/generators/rails_codebook/install/USAGE +9 -0
  33. data/lib/generators/rails_codebook/install/install_generator.rb +21 -0
  34. data/lib/generators/rails_codebook/install/templates/seeds.rb.erb +271 -0
  35. data/lib/rails_codebook/acts_as_codebook.rb +88 -0
  36. data/lib/rails_codebook/controller/base.rb +27 -0
  37. data/lib/rails_codebook/engine.rb +6 -0
  38. data/lib/rails_codebook/has_codebooks.rb +115 -0
  39. data/lib/rails_codebook/model/base.rb +73 -0
  40. data/lib/rails_codebook/version.rb +3 -0
  41. data/lib/rails_codebook.rb +50 -0
  42. data/rails_codebook.gemspec +40 -0
  43. data/script/rails +8 -0
  44. data/test/test_helper.rb +45 -0
  45. metadata +326 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2fc2fcf3d2f09a26134018d70660d11aed589c70
4
+ data.tar.gz: 944b3f2bef30b08ce56395f29b87c5b91767f8fa
5
+ SHA512:
6
+ metadata.gz: 44343fbf17dd49ab0f6916543d2d99b52bc14e01da1444e8c109363152f57eda7b85fd84c6f7b1986dfd23a9f6fe317b9cf5fe9b9c31884c5b80cc90babc0a15
7
+ data.tar.gz: 2c76436aee0de6df53e5f6c5df181726946aaf1debda27ef64ecb9e0df2a1a89e303c1d63a0bffef146c7240e99af72c056ad540cdba3ecfdb4b9a923b629ff6
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ repo_token: 1Mbc3qlzLlMppltPNFppyygKkcukKhFOs
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ rails_codebook
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p247
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.0.0
5
+
6
+ gemfile:
7
+ - Gemfile
8
+
9
+ services:
10
+ - redis-server
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails_codebook.gemspec
4
+ gemspec
5
+
6
+ gem "redis_orm", github: 'redrick/redis_orm'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andrej Antas
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andrej Antas
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # WORK in PROGRESS
2
+
3
+ # RailsCodebook
4
+
5
+ TODO: Write a gem description
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'rails_codebook'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rails_codebook
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,16 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require twitter/bootstrap
16
+ //= require_tree .
@@ -0,0 +1,5 @@
1
+ jQuery(function() {
2
+ $("a[rel=popover]").popover();
3
+ $(".tooltip").tooltip();
4
+ return $("a[rel=tooltip]").tooltip();
5
+ });
@@ -0,0 +1,27 @@
1
+ jQuery( function() {
2
+ $('#cb_name').change(function() {
3
+ $('#search-form').submit();
4
+ })
5
+ });
6
+
7
+ jQuery(function() {
8
+ $('#form-codebook textarea').autosize();
9
+ $('#add-codebook-link').click(function(event) {
10
+ event.preventDefault();
11
+ $('#form-codebook #codebook_value').val('');
12
+ $('#form-codebook #codebook_name').val('');
13
+ $('#form-codebook #codebook_cb_name').val('');
14
+ $('#form-codebook #codebook_sequence').val('100');
15
+ $('#form-codebook #codebook_deleted').val('0');
16
+ $('#form-codebook #codebook_id').val('');
17
+ });
18
+ return $('.edit-codebook').click(function(event) {
19
+ event.preventDefault();
20
+ $('#form-codebook #codebook_value').val($(this).data('value'));
21
+ $('#form-codebook #codebook_name').val($(this).data('name'));
22
+ $('#form-codebook #codebook_cb_name').val($(this).data('cb-name'));
23
+ $('#form-codebook #codebook_sequence').val($(this).data('sequence'));
24
+ $('#form-codebook #codebook_deleted').val($(this).data('deleted'));
25
+ $('#form-codebook #codebook_id').val($(this).data('id'));
26
+ });
27
+ });
@@ -0,0 +1,192 @@
1
+ /*!
2
+ jQuery Autosize v1.16.7
3
+ (c) 2013 Jack Moore - jacklmoore.com
4
+ updated: 2013-03-20
5
+ license: http://www.opensource.org/licenses/mit-license.php
6
+ */
7
+
8
+
9
+ (function ($) {
10
+ var
11
+ defaults = {
12
+ className: 'autosizejs',
13
+ append: '',
14
+ callback: false
15
+ },
16
+ hidden = 'hidden',
17
+ borderBox = 'border-box',
18
+ lineHeight = 'lineHeight',
19
+ supportsScrollHeight,
20
+
21
+ // border:0 is unnecessary, but avoids a bug in FireFox on OSX (http://www.jacklmoore.com/autosize#comment-851)
22
+ copy = '<textarea tabindex="-1" style="position:absolute; top:-999px; left:0; right:auto; bottom:auto; border:0; -moz-box-sizing:content-box; -webkit-box-sizing:content-box; box-sizing:content-box; word-wrap:break-word; height:0 !important; min-height:0 !important; width: 0; overflow:hidden;"/>',
23
+
24
+ // line-height is conditionally included because IE7/IE8/old Opera do not return the correct value.
25
+ copyStyle = [
26
+ 'fontFamily',
27
+ 'fontSize',
28
+ 'fontWeight',
29
+ 'fontStyle',
30
+ 'letterSpacing',
31
+ 'textTransform',
32
+ 'wordSpacing',
33
+ 'textIndent'
34
+ ],
35
+ oninput = 'oninput',
36
+ onpropertychange = 'onpropertychange',
37
+
38
+ // to keep track which textarea is being mirrored when adjust() is called.
39
+ mirrored,
40
+
41
+ // the mirror element, which is used to calculate what size the mirrored element should be.
42
+ mirror = $(copy).data('autosize', true)[0];
43
+
44
+ // test that line-height can be accurately copied.
45
+ mirror.style.lineHeight = '99px';
46
+ if ($(mirror).css(lineHeight) === '99px') {
47
+ copyStyle.push(lineHeight);
48
+ }
49
+ mirror.style.lineHeight = '';
50
+
51
+ $.fn.autosize = function (options) {
52
+ options = $.extend({}, defaults, options || {});
53
+
54
+ if (mirror.parentNode !== document.body) {
55
+ $(document.body).append(mirror);
56
+
57
+ mirror.value = "\n\n\n";
58
+ mirror.scrollTop = 9e4;
59
+ supportsScrollHeight = mirror.scrollHeight === mirror.scrollTop + mirror.clientHeight;
60
+ }
61
+
62
+ return this.each(function () {
63
+ var
64
+ ta = this,
65
+ $ta = $(ta),
66
+ minHeight,
67
+ active,
68
+ resize,
69
+ boxOffset = 0,
70
+ callback = $.isFunction(options.callback);
71
+
72
+ if ($ta.data('autosize')) {
73
+ // exit if autosize has already been applied, or if the textarea is the mirror element.
74
+ return;
75
+ }
76
+
77
+ if ($ta.css('box-sizing') === borderBox || $ta.css('-moz-box-sizing') === borderBox || $ta.css('-webkit-box-sizing') === borderBox){
78
+ boxOffset = $ta.outerHeight() - $ta.height();
79
+ }
80
+
81
+ minHeight = Math.max(parseInt($ta.css('minHeight'), 10) - boxOffset, $ta.height());
82
+
83
+ resize = ($ta.css('resize') === 'none' || $ta.css('resize') === 'vertical') ? 'none' : 'horizontal';
84
+
85
+ $ta.css({
86
+ overflow: hidden,
87
+ overflowY: hidden,
88
+ wordWrap: 'break-word',
89
+ resize: resize
90
+ }).data('autosize', true);
91
+
92
+ function initMirror() {
93
+ mirrored = ta;
94
+ mirror.className = options.className;
95
+
96
+ // mirror is a duplicate textarea located off-screen that
97
+ // is automatically updated to contain the same text as the
98
+ // original textarea. mirror always has a height of 0.
99
+ // This gives a cross-browser supported way getting the actual
100
+ // height of the text, through the scrollTop property.
101
+ $.each(copyStyle, function(i, val){
102
+ mirror.style[val] = $ta.css(val);
103
+ });
104
+ }
105
+
106
+ // Using mainly bare JS in this function because it is going
107
+ // to fire very often while typing, and needs to very efficient.
108
+ function adjust() {
109
+ var height, overflow, original;
110
+
111
+ if (mirrored !== ta) {
112
+ initMirror();
113
+ }
114
+
115
+ // the active flag keeps IE from tripping all over itself. Otherwise
116
+ // actions in the adjust function will cause IE to call adjust again.
117
+ if (!active) {
118
+ active = true;
119
+ mirror.value = ta.value + options.append;
120
+ mirror.style.overflowY = ta.style.overflowY;
121
+ original = parseInt(ta.style.height,10);
122
+
123
+ // Update the width in case the original textarea width has changed
124
+ // A floor of 0 is needed because IE8 returns a negative value for hidden textareas, raising an error.
125
+ mirror.style.width = Math.max($ta.width(), 0) + 'px';
126
+
127
+ if (supportsScrollHeight) {
128
+ height = mirror.scrollHeight;
129
+ } else { // IE6 & IE7
130
+ mirror.scrollTop = 0;
131
+ mirror.scrollTop = 9e4;
132
+ height = mirror.scrollTop;
133
+ }
134
+
135
+ var maxHeight = parseInt($ta.css('maxHeight'), 10);
136
+ // Opera returns '-1px' when max-height is set to 'none'.
137
+ maxHeight = maxHeight && maxHeight > 0 ? maxHeight : 9e4;
138
+ if (height > maxHeight) {
139
+ height = maxHeight;
140
+ overflow = 'scroll';
141
+ } else if (height < minHeight) {
142
+ height = minHeight;
143
+ }
144
+ height += boxOffset;
145
+ ta.style.overflowY = overflow || hidden;
146
+
147
+ if (original !== height) {
148
+ ta.style.height = height + 'px';
149
+ if (callback) {
150
+ options.callback.call(ta,ta);
151
+ }
152
+ }
153
+
154
+ // This small timeout gives IE a chance to draw it's scrollbar
155
+ // before adjust can be run again (prevents an infinite loop).
156
+ setTimeout(function () {
157
+ active = false;
158
+ }, 1);
159
+ }
160
+ }
161
+
162
+ if (onpropertychange in ta) {
163
+ if (oninput in ta) {
164
+ // Detects IE9. IE9 does not fire onpropertychange or oninput for deletions,
165
+ // so binding to onkeyup to catch most of those occassions. There is no way that I
166
+ // know of to detect something like 'cut' in IE9.
167
+ ta[oninput] = ta.onkeyup = adjust;
168
+ } else {
169
+ // IE7 / IE8
170
+ ta[onpropertychange] = adjust;
171
+ }
172
+ } else {
173
+ // Modern Browsers
174
+ ta[oninput] = adjust;
175
+ }
176
+
177
+ $(window).on('resize', function(){
178
+ active = false;
179
+ adjust();
180
+ });
181
+
182
+ // Allow for manual triggering if needed.
183
+ $ta.on('autosize', function(){
184
+ active = false;
185
+ adjust();
186
+ });
187
+
188
+ // Call adjust in case the textarea already contains text.
189
+ adjust();
190
+ });
191
+ };
192
+ }(window.jQuery || window.Zepto));
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,7 @@
1
+ /*
2
+ =require twitter-bootstrap-static/bootstrap
3
+
4
+ Use Font Awesome icons (default)
5
+ To use Glyphicons sprites instead of Font Awesome, replace with "require twitter-bootstrap-static/sprites"
6
+ =require twitter-bootstrap-static/fontawesome
7
+ */
@@ -0,0 +1,44 @@
1
+ .left_panel {width: 30%;float: left;padding-right: 10px;}
2
+ .left_panel .navbar #search-form {padding-top: 15px;}
3
+ .left_panel .navbar #cb_name {width:95%;}
4
+ .left_panel .navbar .clear_button { float: left;padding-right: 10px;padding-bottom: 20px; }
5
+ .left_panel .navbar .new_button {width: 59px;float: left;}
6
+
7
+ .right_panel {width: 65%;float: left;}
8
+ .right_panel .btn.btn-primary.dropdown-toggle {height:20px;}
9
+
10
+ .red {color:red;}
11
+
12
+ .apple_pagination {
13
+ width: 99%;
14
+ background: #f1f1f1;
15
+ border: 1px solid #e5e5e5;
16
+ text-align: center;
17
+ padding: 1em;
18
+ cursor: default; }
19
+ .apple_pagination a, .apple_pagination span {
20
+ padding: 0.2em 0.3em; }
21
+ .apple_pagination .disabled {
22
+ color: #aaaaaa; }
23
+ .apple_pagination .current {
24
+ font-style: normal;
25
+ font-weight: bold;
26
+ background-color: #bebebe;
27
+ display: inline-block;
28
+ width: 1.4em;
29
+ height: 1.4em;
30
+ line-height: 1.5;
31
+ -moz-border-radius: 1em;
32
+ -webkit-border-radius: 1em;
33
+ border-radius: 1em;
34
+ text-shadow: rgba(255, 255, 255, 0.8) 1px 1px 1px; }
35
+ .apple_pagination a {
36
+ text-decoration: none;
37
+ color: black; }
38
+ .apple_pagination a:hover, .apple_pagination a:focus {
39
+ text-decoration: underline; }
40
+
41
+
42
+ .flr {
43
+ float:right;
44
+ }
@@ -0,0 +1,65 @@
1
+ module RailsCodebook
2
+ module Admin
3
+ class CodebooksController < RailsCodebook::Controller::Base
4
+ respond_to :html, :js
5
+ layout 'rails_codebook/application'
6
+
7
+ def index
8
+ unless params[:cb_name].blank?
9
+ @codebooks = RailsCodebook::Codebook.search(params[:page], 'cb_name', params[:cb_name], true)
10
+ else
11
+ @codebooks = RailsCodebook::Codebook.search(params[:page])
12
+ end
13
+
14
+ unless params[:query].blank?
15
+ @codebooks = (params[:query] == '*') ? \
16
+ @codebooks = RailsCodebook::Codebook.search(params[:page], 'name', params[:query], true, @codebooks) : \
17
+ @codebooks = RailsCodebook::Codebook.search(params[:page], 'name', params[:query], false, @codebooks)
18
+ end
19
+
20
+ respond_to do |format|
21
+ format.html {
22
+ render 'index', layout: true
23
+ }
24
+ end
25
+ end
26
+
27
+ def create
28
+ unless params[:codebook][:id].blank?
29
+ @codebook = RailsCodebook::Codebook.find(params[:codebook][:id])
30
+ @codebook.update_attributes(params[:codebook])
31
+ else
32
+ @codebook = RailsCodebook::Codebook.create(params[:codebook])
33
+ end
34
+
35
+ respond_to do |format|
36
+ format.js
37
+ format.html{
38
+ redirect_to admin_codebooks_path
39
+ }
40
+ end
41
+
42
+ end
43
+
44
+ def destroy
45
+ codebook.find(params[:id]).destroy
46
+ respond_to do |format|
47
+ format.js
48
+ format.html{
49
+ redirect_to admin_codebooks_path
50
+ }
51
+ end
52
+
53
+ end
54
+
55
+
56
+ private
57
+
58
+ # Never trust parameters from the scary internet, only allow the white list through.
59
+ def codebook_params
60
+ params.require(:codebook).permit(:name, :value, :cb_name, :sequence, :deleted)
61
+ end
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,44 @@
1
+ module RailsCodebook
2
+ module Api
3
+ class CodebooksController < RailsCodebook::Controller::Base
4
+
5
+ # index for all codebooks
6
+ # /codebooks
7
+ def index
8
+ @codebooks = codebook.all.paginate(page: params[:page])
9
+ if params[:q]
10
+ search
11
+ else
12
+ render json: @codebooks.cb_serialize(params[:format])
13
+ end
14
+ end
15
+
16
+ # index showing only one codebook
17
+ # /codebooks/cb_name
18
+ def codebook_index
19
+ @codebooks = RailsCodebook::Codebook.search(params[:page], 'cb_name', params[:cb_name], true)
20
+ if params[:q]
21
+ search
22
+ else
23
+ render json: @codebooks.cb_serialize(params[:format])
24
+ end
25
+ end
26
+
27
+ # showing one codebook line
28
+ # /codebooks/cb_name/value
29
+ def show
30
+ @codebook = codebook.find(params[:id])
31
+ render json: @codebook.cb_serialize(params[:format])
32
+ end
33
+
34
+ # searching one of the codebooks
35
+ # /codebooks?q=something
36
+ # /codebooks/cb_name?q=something
37
+ def search
38
+ @codebooks = RailsCodebook::Codebook.search(params[:page], 'name', params[:q], false, @codebooks)
39
+ render json: @codebooks.cb_serialize(params[:format])
40
+ end
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,43 @@
1
+ module RailsCodebook
2
+ module Admin
3
+ module CodebooksHelper
4
+ def title(page_title, show_title = true)
5
+ @show_title = show_title
6
+ if @show_title
7
+ content_for(:title) { h(page_title.to_s) }
8
+ end
9
+ end
10
+
11
+ def show_title?
12
+ @show_title
13
+ end
14
+
15
+ def humanize_key(key)
16
+ key.split('.').last.gsub('_', ' ').gsub(/\b('?[a-z])/) { $1.capitalize }
17
+ end
18
+
19
+ # Can search for named routes directly in the main app, omitting
20
+ # the "main_app." prefix
21
+ def method_missing method, *args, &block
22
+ if main_app_url_helper?(method)
23
+ main_app.send(method, *args)
24
+ else
25
+ super
26
+ end
27
+ end
28
+
29
+ def all_codebooks
30
+ RailsCodebook::Codebook.all.uniq(&:cb_name)
31
+ end
32
+
33
+ private
34
+
35
+ def main_app_url_helper?(method)
36
+ RedisDictionary::configuration.inline_main_app_named_routes and
37
+ (method.to_s.end_with?('_path') or method.to_s.end_with?('_url')) and
38
+ main_app.respond_to?(method)
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,44 @@
1
+ module RailsCodebook
2
+
3
+ class Codebook < RailsCodebook::Model::Base
4
+ before_create :set_created_at
5
+ before_save :set_updated_at
6
+
7
+
8
+ # defining default attributes of codebook
9
+ # name -> i18n hook for name that is being displayed
10
+ property :name, String
11
+ # value -> parametrized name or some string that can identifie it and alse can be put in url
12
+ property :value, String
13
+ # cb_name -> name of actual codebook !important!
14
+ property :cb_name, String
15
+ # created_at -> sets when the row is created
16
+ property :created_at, DateTime
17
+ # updated_at -> updates everytime you move with row
18
+ property :updated_at, DateTime
19
+ # sequence -> used for sorting
20
+ property :sequence, Integer, default: 100
21
+ # deleted -> only those set to 0 are shown (thers are "deleted")
22
+ property :deleted, Integer, default: 0
23
+
24
+ # defining indeces for search
25
+ index :name
26
+ index :value
27
+ index :cb_name
28
+ index :created_at
29
+ index :updated_at
30
+ index :sequence
31
+ index :deleted
32
+
33
+ private
34
+
35
+ def set_created_at
36
+ self.created_at = Time.now.to_s(:db)
37
+ end
38
+
39
+ def set_updated_at
40
+ self.updated_at = Time.now.to_s(:db)
41
+ end
42
+ end
43
+
44
+ end