enju_barcode 0.0.1

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 (78) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +45 -0
  4. data/app/assets/javascripts/barcodes.js +2 -0
  5. data/app/assets/stylesheets/barcodes.css +4 -0
  6. data/app/assets/stylesheets/scaffold.css +56 -0
  7. data/app/controllers/barcodes_controller.rb +89 -0
  8. data/app/helpers/barcodes_helper.rb +2 -0
  9. data/app/models/barcode.rb +24 -0
  10. data/app/views/barcodes/_form.html.erb +14 -0
  11. data/app/views/barcodes/barcode.html.erb +32 -0
  12. data/app/views/barcodes/edit.html.erb +13 -0
  13. data/app/views/barcodes/index.html.erb +32 -0
  14. data/app/views/barcodes/new.html.erb +12 -0
  15. data/app/views/barcodes/show.html.erb +27 -0
  16. data/app/views/barcodes/show.png.erb +1 -0
  17. data/config/locales/translation_en.yml +9 -0
  18. data/config/locales/translation_ja.yml +9 -0
  19. data/config/routes.rb +3 -0
  20. data/db/migrate/20081108112016_create_barcodes.rb +14 -0
  21. data/lib/enju_barcode.rb +4 -0
  22. data/lib/enju_barcode/engine.rb +8 -0
  23. data/lib/enju_barcode/version.rb +3 -0
  24. data/lib/tasks/enju_barcode_tasks.rake +4 -0
  25. data/spec/controllers/barcodes_controller_spec.rb +479 -0
  26. data/spec/dummy/Rakefile +7 -0
  27. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  28. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  29. data/spec/dummy/app/controllers/application_controller.rb +62 -0
  30. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  31. data/spec/dummy/app/models/ability.rb +18 -0
  32. data/spec/dummy/app/models/role.rb +5 -0
  33. data/spec/dummy/app/models/user.rb +28 -0
  34. data/spec/dummy/app/models/user_has_role.rb +4 -0
  35. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  36. data/spec/dummy/app/views/page/403.html.erb +9 -0
  37. data/spec/dummy/app/views/page/403.xml.erb +4 -0
  38. data/spec/dummy/app/views/page/404.html.erb +9 -0
  39. data/spec/dummy/app/views/page/404.xml.erb +4 -0
  40. data/spec/dummy/config.ru +4 -0
  41. data/spec/dummy/config/application.rb +45 -0
  42. data/spec/dummy/config/boot.rb +10 -0
  43. data/spec/dummy/config/database.yml +25 -0
  44. data/spec/dummy/config/environment.rb +5 -0
  45. data/spec/dummy/config/environments/development.rb +30 -0
  46. data/spec/dummy/config/environments/production.rb +60 -0
  47. data/spec/dummy/config/environments/test.rb +39 -0
  48. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  49. data/spec/dummy/config/initializers/devise.rb +209 -0
  50. data/spec/dummy/config/initializers/inflections.rb +10 -0
  51. data/spec/dummy/config/initializers/mime_types.rb +6 -0
  52. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  53. data/spec/dummy/config/initializers/session_store.rb +8 -0
  54. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  55. data/spec/dummy/config/locales/en.yml +5 -0
  56. data/spec/dummy/config/routes.rb +60 -0
  57. data/spec/dummy/db/migrate/20111201121844_create_roles.rb +12 -0
  58. data/spec/dummy/db/migrate/20111201155456_create_users.rb +13 -0
  59. data/spec/dummy/db/migrate/20111201155513_add_devise_to_users.rb +31 -0
  60. data/spec/dummy/db/migrate/20111201163718_create_user_has_roles.rb +10 -0
  61. data/spec/dummy/db/schema.rb +62 -0
  62. data/spec/dummy/db/test.sqlite3 +0 -0
  63. data/spec/dummy/log/development.log +0 -0
  64. data/spec/dummy/log/test.log +6623 -0
  65. data/spec/dummy/public/404.html +26 -0
  66. data/spec/dummy/public/422.html +26 -0
  67. data/spec/dummy/public/500.html +26 -0
  68. data/spec/dummy/public/favicon.ico +0 -0
  69. data/spec/dummy/script/rails +6 -0
  70. data/spec/factories/barcode.rb +5 -0
  71. data/spec/factories/user.rb +31 -0
  72. data/spec/fixtures/roles.yml +21 -0
  73. data/spec/fixtures/user_has_roles.yml +41 -0
  74. data/spec/fixtures/users.yml +69 -0
  75. data/spec/spec_helper.rb +32 -0
  76. data/spec/support/controller_macros.rb +48 -0
  77. data/spec/support/devise.rb +4 -0
  78. metadata +263 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = EnjuBarcode
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'EnjuPurchaseRequest'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+ Bundler::GemHelper.install_tasks
28
+
29
+ require 'rake/testtask'
30
+
31
+ Rake::TestTask.new(:test) do |t|
32
+ t.libs << 'lib'
33
+ t.libs << 'test'
34
+ t.pattern = 'test/**/*_test.rb'
35
+ t.verbose = false
36
+ end
37
+
38
+ require 'rspec/core'
39
+ require 'rspec/core/rake_task'
40
+
41
+ RSpec::Core::RakeTask.new(:spec) do |spec|
42
+ spec.pattern = FileList['spec/**/*_spec.rb']
43
+ end
44
+
45
+ task :default => :spec
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,89 @@
1
+ class BarcodesController < ApplicationController
2
+ load_and_authorize_resource
3
+
4
+ # GET /barcodes
5
+ # GET /barcodes.json
6
+ def index
7
+ @barcodes = Barcode.page(params[:page])
8
+ @start_rows = params[:start_rows]
9
+ @start_cols = params[:start_cols]
10
+
11
+ if params[:mode] == 'barcode'
12
+ render :action => 'barcode', :layout => false
13
+ return
14
+ end
15
+
16
+ respond_to do |format|
17
+ format.html # index.html.erb
18
+ format.json { render :json => @barcodes }
19
+ end
20
+ end
21
+
22
+ # GET /barcodes/1
23
+ # GET /barcodes/1.json
24
+ def show
25
+ respond_to do |format|
26
+ format.html # show.html.erb
27
+ format.json { render :json => @barcode }
28
+ format.svg { send_data @barcode.data, :type => 'image/svg+json', :disposition => 'inline' }
29
+ end
30
+ end
31
+
32
+ # GET /barcodes/new
33
+ # GET /barcodes/new.json
34
+ def new
35
+ @barcode = Barcode.new
36
+
37
+ respond_to do |format|
38
+ format.html # new.html.erb
39
+ format.json { render :json => @barcode }
40
+ end
41
+ end
42
+
43
+ # GET /barcodes/1/edit
44
+ def edit
45
+ end
46
+
47
+ # POST /barcodes
48
+ # POST /barcodes.json
49
+ def create
50
+ @barcode = Barcode.new(params[:barcode])
51
+
52
+ respond_to do |format|
53
+ if @barcode.save
54
+ flash[:notice] = t('controller.successfully_created', :model => t('activerecord.models.barcode'))
55
+ format.html { redirect_to(@barcode) }
56
+ format.json { render :json => @barcode, :status => :created, :location => @barcode }
57
+ else
58
+ format.html { render :action => "new" }
59
+ format.json { render :json => @barcode.errors, :status => :unprocessable_entity }
60
+ end
61
+ end
62
+ end
63
+
64
+ # PUT /barcodes/1
65
+ # PUT /barcodes/1.json
66
+ def update
67
+ respond_to do |format|
68
+ if @barcode.update_attributes(params[:barcode])
69
+ flash[:notice] = t('controller.successfully_updated', :model => t('activerecord.models.barcode'))
70
+ format.html { redirect_to(@barcode) }
71
+ format.json { head :ok }
72
+ else
73
+ format.html { render :action => "edit" }
74
+ format.json { render :json => @barcode.errors, :status => :unprocessable_entity }
75
+ end
76
+ end
77
+ end
78
+
79
+ # DELETE /barcodes/1
80
+ # DELETE /barcodes/1.json
81
+ def destroy
82
+ @barcode.destroy
83
+
84
+ respond_to do |format|
85
+ format.html { redirect_to(barcodes_url) }
86
+ format.json { head :ok }
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,2 @@
1
+ module BarcodesHelper
2
+ end
@@ -0,0 +1,24 @@
1
+ # TODO: Codarbar support
2
+ require 'barby/barcode/code_39'
3
+ require 'barby/outputter/svg_outputter'
4
+
5
+ class Barcode < ActiveRecord::Base
6
+ belongs_to :barcodable, :polymorphic => true
7
+
8
+ validates_presence_of :code_word
9
+ before_save :generate_barcode
10
+
11
+ attr_accessor :start_rows, :start_cols
12
+
13
+ def self.per_page
14
+ 10
15
+ end
16
+
17
+ def generate_barcode
18
+ self.data = Barby::Code39.new(code_word).to_svg(:width => 150, :height => 70)
19
+ end
20
+
21
+ def is_readable_by(user, parent = nil)
22
+ true
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ <%- form_for(@barcode) do |f| -%>
2
+ <%= f.error_messages -%>
3
+
4
+ <p>
5
+ <%= f.label t('activerecord.attributes.barcode.code_word') -%><br />
6
+ <%= f.text_field :code_word -%>
7
+ <%= javascript_tag("$('#barcode_code_word').focus()") -%>
8
+ </p>
9
+ <p>
10
+ <%= f.submit -%>
11
+ </p>
12
+ <%- end -%>
13
+
14
+
@@ -0,0 +1,32 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <title><%= t('activerecord.models.barcode') -%> - <%= @library_group.display_name.localize -%></title>
6
+ </head>
7
+
8
+ <body style="width: 210mm; padding-left: 5mm; padding-right: 5mm">
9
+ <table>
10
+ <%- @barcodes.each_with_index do |barcode, i| -%>
11
+ <%- if i == 0 or i % 4 == 0 -%>
12
+ <tr>
13
+ <%- end -%>
14
+ <td style="text-align: center; width: 50mm; height: 30mm">
15
+ <div style="font-size: 10pt; line-height: 0" -%>
16
+ <%- unless barcode.code_word.blank? -%>
17
+ <%= image_tag(barcode_path(barcode, :format => :png), :alt => barcode.code_word) -%>
18
+ <%- end -%>
19
+ <br />
20
+ <%= barcode.code_word -%>
21
+ </div>
22
+ <div style="font-size: 10pt" -%>
23
+ <%= @library_group.display_name.localize -%>
24
+ </div>
25
+ </td>
26
+ <%- if i != 0 and (i + 1) % 4 == 0 -%>
27
+ </tr>
28
+ <%- end -%>
29
+ <%- end -%>
30
+ </table>
31
+ </body>
32
+ </html>
@@ -0,0 +1,13 @@
1
+ <div id="content_detail" class="ui-corner-all">
2
+ <h1 class="title"><%= t('page.editing', :model => t('activerecord.models.barcode')) -%></h1>
3
+ <div id="content_list">
4
+ <%= render 'form' %>
5
+ </div>
6
+ </div>
7
+
8
+ <div id="submenu" class="ui-corner-all">
9
+ <ul>
10
+ <li><%= link_to t('page.show'), @barcode -%></li>
11
+ <li><%= link_to t('page.back'), barcodes_path -%></li>
12
+ </ul>
13
+ </div>
@@ -0,0 +1,32 @@
1
+ <div id="content_detail" class="ui-corner-all">
2
+ <h1 class="title"><%= t('page.listing', :model => t('activerecord.models.barcode')) -%></h1>
3
+ <div id="content_list">
4
+
5
+ <table class="index">
6
+ <tr>
7
+ <th><%= t('activerecord.attributes.barcode.code_word') -%></th>
8
+ <th><%= t('activerecord.attributes.barcode.barcode_type') -%></th>
9
+ <th></th>
10
+ </tr>
11
+
12
+ <%- for barcode in @barcodes -%>
13
+ <tr class="line<%= cycle("0", "1") -%>">
14
+ <td><%= link_to barcode.code_word, barcode -%></td>
15
+ <td><%= barcode.barcode_type -%></td>
16
+ <td>
17
+ <%= link_to t('page.edit'), edit_barcode_path(barcode) -%>
18
+ <%= link_to t('page.destroy'), barcode, :confirm => t('page.are_you_sure'), :method => :delete -%>
19
+ </td>
20
+ </tr>
21
+ <%- end -%>
22
+ </table>
23
+
24
+ <%= will_paginate(@barcodes) -%>
25
+ </div>
26
+ </div>
27
+
28
+ <div id="submenu" class="ui-corner-all">
29
+ <ul>
30
+ <li><%= link_to t('page.new', :model => t('activerecord.models.barcode')), new_barcode_path -%></li>
31
+ </ul>
32
+ </div>
@@ -0,0 +1,12 @@
1
+ <div id="content_detail" class="ui-corner-all">
2
+ <h1 class="title"><%= t('page.new', :model => t('activerecord.models.barcode')) -%></h1>
3
+ <div id="content_list">
4
+ <%= render 'form' %>
5
+ </div>
6
+ </div>
7
+
8
+ <div id="submenu" class="ui-corner-all">
9
+ <ul>
10
+ <li><%= link_to t('page.back'), barcodes_path -%></li>
11
+ </ul>
12
+ </div>
@@ -0,0 +1,27 @@
1
+ <div id="content_detail" class="ui-corner-all">
2
+ <h1 class="title"><%= t('page.showing', :model => t('activerecord.models.barcode')) -%></h1>
3
+ <div id="content_list">
4
+ <p>
5
+ <strong><%= t('activerecord.attributes.barcode.barcode_type') -%>:</strong>
6
+ <%= @barcode.barcode_type -%>
7
+ </p>
8
+
9
+ <p>
10
+ <strong><%= t('activerecord.attributes.barcode.barcodable') -%>:</strong>
11
+ <%= link_to h("#{@barcode.barcodable_type} / #{@barcode.barcodable_id}"), @barcode.barcodable if @barcode.barcodable -%>
12
+ </p>
13
+
14
+ <p>
15
+ <strong><%= t('activerecord.attributes.barcode.data') -%>:</strong>
16
+ <%= image_tag(barcode_path(@barcode, :format => :svg), :alt => @barcode.code_word) -%>
17
+ </p>
18
+
19
+ </div>
20
+ </div>
21
+
22
+ <div id="submenu" class="ui-corner-all">
23
+ <ul>
24
+ <li><%= link_to t('page.edit'), edit_barcode_path(@barcode) -%></li>
25
+ <li><%= link_to t('page.back'), barcodes_path -%></li>
26
+ </ul>
27
+ </div>
@@ -0,0 +1 @@
1
+ <%= @barcode.data -%>
@@ -0,0 +1,9 @@
1
+ ja:
2
+ activerecord:
3
+ models:
4
+ barcode: "Barcode"
5
+
6
+ attributes:
7
+ barcode:
8
+ code_word: "Code word"
9
+ data: "Data"
@@ -0,0 +1,9 @@
1
+ ja:
2
+ activerecord:
3
+ models:
4
+ barcode: バーコード
5
+
6
+ attributes:
7
+ barcode:
8
+ code_word: コードワード
9
+ data: データ
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ resources :barcodes
3
+ end
@@ -0,0 +1,14 @@
1
+ class CreateBarcodes < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :barcodes do |t|
4
+ t.string :code_word
5
+ t.binary :data
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :barcodes
13
+ end
14
+ end