tramway-core 0.1.0.4 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e709b036766d7a01f92253914862034eed4301e2
4
- data.tar.gz: 7fece4bf9945deee77ecbcf67ab5ed8ada854ae3
2
+ SHA256:
3
+ metadata.gz: f1fdd99b3bcf9ff2140b9cb18f1312eaf6ec59148a3ae8041d6ec5645be035a4
4
+ data.tar.gz: f7646bb17b0dc8ddfcbbadc4e7f5b15f6b2b0bfd26cb2946e4787ed5ad8bc29b
5
5
  SHA512:
6
- metadata.gz: aedf05dbb92dd481a5cd56565a5e0d2e4d18f765b23629efbbfebeca51afa8800fb7d732b9c555bb4d4fa642e15854bf730f0d0878e290d55df4303e7a352e2f
7
- data.tar.gz: 44e8d4861ae6da3589de4cd76d8f7344437c4ba5db3dda7fb57a11d1e9c55a660e18768127979f8c96501df0d39d4c1ce6ec559b41cd3eddd7e97d2407279d72
6
+ metadata.gz: f9cddd8d4a8765d39ca37c2498f5a4b41db1ad455ea7153968077460a1e6db3c8659aa32e98cc1b17b2bb6e2578e12f313d895c84c4254d86daea1fa26bf9550
7
+ data.tar.gz: 6d23dd21b4b146b15fe7ff2654321e3262899e91646b88e84739a27f615a80fad5ff8232ac367dc0cfc217f703a8e2578a0ba78b922e54f662618b15f0d7425c
@@ -0,0 +1,3 @@
1
+ #= require jquery
2
+ #= require jquery_ujs
3
+ #= require_tree .
@@ -4,3 +4,6 @@
4
4
  */
5
5
 
6
6
  @import "bootstrap"
7
+
8
+ .container
9
+ padding-top: 2rem
@@ -0,0 +1,14 @@
1
+ class Tramway::Core::ApplicationDecoratedCollection < Array
2
+ def initialize(array, original_array)
3
+ @original_array = original_array
4
+ super(array)
5
+ end
6
+
7
+ def original_array
8
+ @original_array
9
+ end
10
+
11
+ delegate :total_pages, to: :original_array
12
+ delegate :current_page, to: :original_array
13
+ delegate :limit_value, to: :original_array
14
+ end
@@ -0,0 +1,65 @@
1
+ class Tramway::Core::ApplicationDecorator
2
+ include ActionView::Helpers
3
+ include ActionView::Context
4
+ include FontAwesome::Rails::IconHelper
5
+
6
+ def initialize(object)
7
+ @object = object
8
+ end
9
+
10
+ def name
11
+ object.try(:name) || object.try(:title) || title
12
+ end
13
+
14
+ class << self
15
+ def list_attributes
16
+ []
17
+ end
18
+
19
+ def decorate(object_or_array)
20
+ if object_or_array.class.superclass == ActiveRecord::Relation
21
+ decorated_array = object_or_array.map do |obj|
22
+ new obj
23
+ end
24
+ Tramway::Core::ApplicationDecoratedCollection.new decorated_array, object_or_array
25
+ else
26
+ new object_or_array
27
+ end
28
+ end
29
+ end
30
+
31
+ delegate :id, to: :object
32
+ delegate :class, to: :object
33
+ delegate :human_state_name, to: :object
34
+
35
+ def model
36
+ object
37
+ end
38
+
39
+ def attributes
40
+ object.attributes.reduce({}) do |hash, attribute|
41
+ value = object.send attribute[0]
42
+ if attribute[0].to_s.in? object.class.state_machines.keys.map(&:to_s)
43
+ hash.merge! attribute[0] => object.send("human_#{attribute[0]}_name")
44
+ elsif value.class.in? [ ActiveSupport::TimeWithZone, DateTime, Time ]
45
+ hash.merge! attribute[0] => I18n.l(attribute[1])
46
+ elsif value.class.superclass == ApplicationUploader
47
+ tags = content_tag(:div) do
48
+ concat image_tag value.small.url if value.url.match(/jpg|JPG|png|PNG$/)
49
+ concat link_to(fa_icon(:download), value.url, class: 'btn btn-success')
50
+ end
51
+ hash.merge! attribute[0] => tags
52
+ elsif value.is_a? Enumerize::Value
53
+ hash.merge! attribute[0] => value.text
54
+ else
55
+ hash.merge! attribute[0] => attribute[1]
56
+ end
57
+ end
58
+ end
59
+
60
+ protected
61
+
62
+ def object
63
+ @object
64
+ end
65
+ end
@@ -4,5 +4,13 @@ module Tramway::Core
4
4
  raise 'ApplicationForm::Params should not be nil'.inspect unless params
5
5
  save if validate params
6
6
  end
7
+
8
+ def form_properties(**args)
9
+ @form_properties = args
10
+ end
11
+
12
+ def properties
13
+ @form_properties
14
+ end
7
15
  end
8
16
  end
@@ -1,7 +1,38 @@
1
+ require 'carrierwave/orm/activerecord'
2
+
1
3
  module Tramway
2
4
  module Core
3
5
  class ApplicationRecord < ActiveRecord::Base
4
6
  self.abstract_class = true
7
+ audited
8
+ extend Enumerize
9
+
10
+ state_machine :state, initial: :active do
11
+ state :active
12
+ state :removed
13
+
14
+ event :remove do
15
+ transition active: :remove
16
+ end
17
+ end
18
+
19
+ scope :active, -> { where state: :active }
20
+
21
+ # FIXME detect inhertited locales
22
+ class << self
23
+ def human_attribute_name(attribute_name)
24
+ excepted_attributes = %w( created_at updated_at state )
25
+ if attribute_name.to_s.in? excepted_attributes
26
+ I18n.t "activerecord.attributes.tramway/core/application_record.#{attribute_name}"
27
+ else
28
+ super attribute_name
29
+ end
30
+ end
31
+ end
32
+ # FIXME detect inhertited locales
33
+ def human_state_name
34
+ I18n.t "activerecord.state_machines.tramway/core/application_record.state.states.#{state}"
35
+ end
5
36
  end
6
37
  end
7
38
  end
@@ -0,0 +1,7 @@
1
+ class ApplicationUploader < CarrierWave::Uploader::Base
2
+ storage :file
3
+
4
+ def store_dir
5
+ "system/uploads/#{model.class.model_name.to_s.underscore}/#{mounted_as}/#{model.id}"
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class FileUploader < ApplicationUploader
2
+ def extension_white_list
3
+ %w(pdf doc docx xls csv xlsx)
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ module ImageDefaults
2
+ include CarrierWave::MiniMagick
3
+
4
+ def default_url
5
+ "/images/fallback/#{model.class.model_name.to_s.underscore}/" << [mounted_as, version_name].compact.join("_") << ".gif"
6
+ end
7
+
8
+ def extension_white_list
9
+ %w(jpg jpeg gif png)
10
+ end
11
+ end
@@ -0,0 +1,39 @@
1
+ class PhotoUploader < ApplicationUploader
2
+ include ImageDefaults
3
+
4
+ def default_url
5
+ ActionController::Base.helpers.asset_path("images/default_photo.png")
6
+ end
7
+
8
+ def url
9
+ if File.exist? file.file
10
+ file.file.match(/\/system\/uploads\/.*/).to_s
11
+ else
12
+ "/assets/tramway/core/mona_lisa_from_prado_square.jpg"
13
+ end
14
+ end
15
+
16
+ version :medium do
17
+ process :resize_to_fill => [400, 400]
18
+ end
19
+
20
+ version :small do
21
+ process :resize_to_fill => [100, 100]
22
+ end
23
+
24
+ attr_reader :width, :height
25
+
26
+ before :cache, :capture_size
27
+
28
+ def capture_size(file)
29
+ if version_name.blank?
30
+ if file.path.nil?
31
+ img = ::MiniMagick::Image::read(file.file)
32
+ @width = img[:width]
33
+ @height = img[:height]
34
+ else
35
+ @width, @height = `identify -format "%wx %h" #{file.path}`.split(/x/).map{|dim| dim.to_i }
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,11 @@
1
+ - if object.model.errors.any?
2
+ .alert.alert-dismissible.alert-danger
3
+ %h4= t('.some_errors_was_found')
4
+ %ul
5
+ - object.errors.full_messages.each do |message|
6
+ %li= message
7
+ - object.model.errors.full_messages.each do |message|
8
+ %li= message
9
+ - if params[:message]
10
+ .alert.alert-dismissible.alert-info
11
+ %h4= t("messages.#{params[:message]}")
@@ -0,0 +1,7 @@
1
+ ru:
2
+ date:
3
+ formats:
4
+ default: "%d.%m.%Y"
5
+ time:
6
+ formats:
7
+ default: "%d.%m.%Y %H:%M"
@@ -0,0 +1,11 @@
1
+ ru:
2
+ helpers:
3
+ links:
4
+ enter: Войти
5
+ save: Сохранить
6
+ back: Назад
7
+ sign_out: Выйти
8
+ actions: Действия
9
+ actions:
10
+ create: Создать
11
+ update: Редактировать
@@ -0,0 +1,7 @@
1
+ ru:
2
+ activerecord:
3
+ attributes:
4
+ tramway/core/application_record:
5
+ created_at: Создан
6
+ updated_at: Обновлён
7
+ state: Статус
@@ -0,0 +1,8 @@
1
+ ru:
2
+ activerecord:
3
+ state_machines:
4
+ tramway/core/application_record:
5
+ state:
6
+ states:
7
+ active: Активный
8
+ removed: Удалённый
@@ -2,6 +2,12 @@ module Tramway
2
2
  module Core
3
3
  class Engine < ::Rails::Engine
4
4
  isolate_namespace Tramway::Core
5
+
6
+ config.before_initialize do
7
+ config.i18n.available_locales = [:ru]
8
+ config.i18n.default_locale = :ru
9
+ config.i18n.load_path += Dir["#{config.root}/config/locales/**/*.yml"]
10
+ end
5
11
  end
6
12
  end
7
13
  end
@@ -1,12 +1,25 @@
1
1
  require 'rails/generators'
2
2
 
3
- module Tramway::Core::Generators
4
- class InstallGenerator < ::Rails::Generators::Base
5
- source_root File.expand_path('../templates', __FILE__)
3
+ module Tramway
4
+ module Core
5
+ module Generators
6
+ class InstallGenerator < ::Rails::Generators::Base
7
+ source_root File.expand_path('../templates', __FILE__)
6
8
 
7
- def copy_initializer
8
- copy_file "/#{File.dirname __dir__}/generators/templates/initializers/simple_form.rb", 'config/initializers/simple_form.rb'
9
- copy_file "/#{File.dirname __dir__}/generators/templates/initializers/simple_form_bootstrap.rb", 'config/initializers/simple_form_bootstrap.rb'
9
+ def run_other_generators
10
+ generate 'audited:install'
11
+ end
12
+
13
+ def self.next_migration_number(path)
14
+ next_migration_number = current_migration_number(path) + 1
15
+ ActiveRecord::Migration.next_migration_number next_migration_number
16
+ end
17
+
18
+ def copy_initializer
19
+ copy_file "/#{File.dirname __dir__}/generators/templates/initializers/simple_form.rb", 'config/initializers/simple_form.rb'
20
+ copy_file "/#{File.dirname __dir__}/generators/templates/initializers/simple_form_bootstrap.rb", 'config/initializers/simple_form_bootstrap.rb'
21
+ end
22
+ end
10
23
  end
11
24
  end
12
25
  end
@@ -1,5 +1,5 @@
1
1
  module Tramway
2
2
  module Core
3
- VERSION = '0.1.0.4'
3
+ VERSION = '0.2'
4
4
  end
5
5
  end
data/lib/tramway/core.rb CHANGED
@@ -3,6 +3,5 @@ require 'tramway/core/generators/install_generator'
3
3
 
4
4
  module Tramway
5
5
  module Core
6
- # Your code goes here...
7
6
  end
8
7
  end
@@ -0,0 +1,25 @@
1
+ require 'rails/generators'
2
+
3
+ module Tramway
4
+ module Core
5
+ module Generators
6
+ class InstallGenerator < ::Rails::Generators::Base
7
+ source_root File.expand_path('../templates', __FILE__)
8
+
9
+ def run_other_generators
10
+ generate 'audited:install'
11
+ end
12
+
13
+ def self.next_migration_number(path)
14
+ next_migration_number = current_migration_number(path) + 1
15
+ ActiveRecord::Migration.next_migration_number next_migration_number
16
+ end
17
+
18
+ def copy_initializer
19
+ copy_file "/#{File.dirname __dir__}/generators/templates/initializers/simple_form.rb", 'config/initializers/simple_form.rb'
20
+ copy_file "/#{File.dirname __dir__}/generators/templates/initializers/simple_form_bootstrap.rb", 'config/initializers/simple_form_bootstrap.rb'
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.4
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-26 00:00:00.000000000 Z
11
+ date: 2018-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -49,18 +49,31 @@ files:
49
49
  - README.md
50
50
  - Rakefile
51
51
  - app/assets/config/tramway_core_manifest.js
52
- - app/assets/javascripts/tramway/core/application.js
52
+ - app/assets/images/tramway/core/mona_lisa_from_prado.jpg
53
+ - app/assets/images/tramway/core/mona_lisa_from_prado_square.jpg
54
+ - app/assets/javascripts/tramway/core/application.js.coffee
53
55
  - app/assets/javascripts/tramway/core/web/application.js
54
56
  - app/assets/stylesheets/tramway/core/application.css.sass
55
57
  - app/controllers/tramway/core/application_controller.rb
56
58
  - app/controllers/tramway/core/web/application_controller.rb
59
+ - app/decorators/tramway/core/application_decorated_collection.rb
60
+ - app/decorators/tramway/core/application_decorator.rb
57
61
  - app/forms/tramway/core/application_form.rb
58
62
  - app/helpers/tramway/core/application_helper.rb
59
63
  - app/helpers/tramway/core/web/application_helper.rb
60
64
  - app/jobs/tramway/core/application_job.rb
61
65
  - app/mailers/tramway/core/application_mailer.rb
62
66
  - app/models/tramway/core/application_record.rb
67
+ - app/uploaders/application_uploader.rb
68
+ - app/uploaders/file_uploader.rb
69
+ - app/uploaders/image_defaults.rb
70
+ - app/uploaders/photo_uploader.rb
63
71
  - app/views/layouts/tramway/core/application.html.erb
72
+ - app/views/tramway/core/shared/_messages.html.haml
73
+ - config/locales/ru/dates.yml
74
+ - config/locales/ru/helpers.yml
75
+ - config/locales/ru/models.yml
76
+ - config/locales/ru/state_machines.yml
64
77
  - config/routes.rb
65
78
  - lib/tasks/tramway/core_tasks.rake
66
79
  - lib/tramway/core.rb
@@ -69,6 +82,7 @@ files:
69
82
  - lib/tramway/core/generators/templates/initializers/simple_form.rb
70
83
  - lib/tramway/core/generators/templates/initializers/simple_form_bootstrap.rb
71
84
  - lib/tramway/core/version.rb
85
+ - lib/tramway/generators/install_generator.rb
72
86
  homepage: https://github.com/kalashnikovisme/tramway-core
73
87
  licenses:
74
88
  - MIT
@@ -89,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
103
  version: '0'
90
104
  requirements: []
91
105
  rubyforge_project:
92
- rubygems_version: 2.6.11
106
+ rubygems_version: 2.7.3
93
107
  signing_key:
94
108
  specification_version: 4
95
109
  summary: Core for all Tramway Rails Engines
@@ -1,13 +0,0 @@
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 any plugin's vendor/assets/javascripts directory 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
- // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
- //
10
- // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
- // about supported directives.
12
- //
13
- //= require_tree .