bemer 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +12 -0
  3. data/.overcommit.yml +59 -0
  4. data/.rspec +4 -0
  5. data/.rubocop.yml +12 -1
  6. data/.rubocop_todo.yml +3 -6
  7. data/Gemfile +6 -0
  8. data/LICENSE +21 -0
  9. data/LICENSE-RU +23 -0
  10. data/README.md +2 -10
  11. data/Rakefile +8 -1
  12. data/bemer.gemspec +19 -6
  13. data/lib/bemer.rb +93 -2
  14. data/lib/bemer/asset_matcher.rb +21 -0
  15. data/lib/bemer/builders.rb +23 -0
  16. data/lib/bemer/builders/tag/element.rb +22 -0
  17. data/lib/bemer/builders/template.rb +57 -0
  18. data/lib/bemer/builders/template_list.rb +56 -0
  19. data/lib/bemer/builders/tree.rb +35 -0
  20. data/lib/bemer/builders/tree/element.rb +22 -0
  21. data/lib/bemer/common_template.rb +29 -0
  22. data/lib/bemer/component.rb +19 -0
  23. data/lib/bemer/component_pack.rb +39 -0
  24. data/lib/bemer/configuration.rb +36 -0
  25. data/lib/bemer/context.rb +44 -0
  26. data/lib/bemer/context_extentions.rb +12 -0
  27. data/lib/bemer/context_extentions/structure.rb +32 -0
  28. data/lib/bemer/context_extentions/template.rb +15 -0
  29. data/lib/bemer/default_template_list.rb +35 -0
  30. data/lib/bemer/entity.rb +94 -0
  31. data/lib/bemer/entity_builder.rb +126 -0
  32. data/lib/bemer/helpers.rb +41 -0
  33. data/lib/bemer/mixin_list.rb +74 -0
  34. data/lib/bemer/modifier_list.rb +68 -0
  35. data/lib/bemer/pipeline.rb +85 -0
  36. data/lib/bemer/pipeline/handler.rb +132 -0
  37. data/lib/bemer/predicate.rb +63 -0
  38. data/lib/bemer/railtie.rb +36 -0
  39. data/lib/bemer/renderer.rb +15 -0
  40. data/lib/bemer/tag.rb +35 -0
  41. data/lib/bemer/tag_builder.rb +11 -0
  42. data/lib/bemer/template.rb +90 -0
  43. data/lib/bemer/template_catalog.rb +42 -0
  44. data/lib/bemer/template_catalog/drawer.rb +31 -0
  45. data/lib/bemer/template_list.rb +62 -0
  46. data/lib/bemer/tree.rb +143 -0
  47. data/lib/bemer/tree/base_node.rb +49 -0
  48. data/lib/bemer/tree/node.rb +129 -0
  49. data/lib/bemer/tree/text_node.rb +11 -0
  50. data/lib/bemer/version.rb +1 -1
  51. data/spec/bemer/entity_spec.rb +37 -0
  52. data/spec/bemer/mixin_list_spec.rb +99 -0
  53. data/spec/bemer/modifier_list_spec.rb +83 -0
  54. data/spec/bemer_spec.rb +36 -0
  55. data/spec/dummy/Rakefile +8 -0
  56. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  57. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  58. data/spec/dummy/app/helpers/application_helper.rb +4 -0
  59. data/spec/dummy/app/jobs/application_job.rb +4 -0
  60. data/spec/dummy/app/mailers/application_mailer.rb +6 -0
  61. data/spec/dummy/app/models/application_record.rb +5 -0
  62. data/spec/dummy/app/models/concerns/.keep +0 -0
  63. data/spec/dummy/app/views/layouts/application.html.erb +13 -0
  64. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  65. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  66. data/spec/dummy/bin/bundle +5 -0
  67. data/spec/dummy/bin/rails +6 -0
  68. data/spec/dummy/bin/rake +6 -0
  69. data/spec/dummy/bin/setup +39 -0
  70. data/spec/dummy/bin/update +31 -0
  71. data/spec/dummy/bin/yarn +13 -0
  72. data/spec/dummy/config.ru +7 -0
  73. data/spec/dummy/config/application.rb +27 -0
  74. data/spec/dummy/config/boot.rb +7 -0
  75. data/spec/dummy/config/cable.yml +10 -0
  76. data/spec/dummy/config/database.yml +25 -0
  77. data/spec/dummy/config/environment.rb +7 -0
  78. data/spec/dummy/config/environments/development.rb +51 -0
  79. data/spec/dummy/config/environments/production.rb +84 -0
  80. data/spec/dummy/config/environments/test.rb +44 -0
  81. data/spec/dummy/config/initializers/application_controller_renderer.rb +7 -0
  82. data/spec/dummy/config/initializers/backtrace_silencers.rb +8 -0
  83. data/spec/dummy/config/initializers/bemer.rb +7 -0
  84. data/spec/dummy/config/initializers/cookies_serializer.rb +7 -0
  85. data/spec/dummy/config/initializers/filter_parameter_logging.rb +6 -0
  86. data/spec/dummy/config/initializers/inflections.rb +17 -0
  87. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  88. data/spec/dummy/config/initializers/wrap_parameters.rb +16 -0
  89. data/spec/dummy/config/locales/en.yml +33 -0
  90. data/spec/dummy/config/puma.rb +58 -0
  91. data/spec/dummy/config/routes.rb +5 -0
  92. data/spec/dummy/config/secrets.yml +32 -0
  93. data/spec/dummy/config/spring.rb +8 -0
  94. data/spec/dummy/lib/assets/.keep +0 -0
  95. data/spec/dummy/log/.keep +0 -0
  96. data/spec/dummy/package.json +5 -0
  97. data/spec/dummy/public/404.html +67 -0
  98. data/spec/dummy/public/422.html +67 -0
  99. data/spec/dummy/public/500.html +66 -0
  100. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  101. data/spec/dummy/public/apple-touch-icon.png +0 -0
  102. data/spec/dummy/public/favicon.ico +0 -0
  103. data/spec/rails_helper.rb +37 -0
  104. data/spec/spec_helper.rb +41 -0
  105. metadata +301 -7
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Bemer::ModifierList do
4
+ describe 'modifiers from an empty params' do
5
+ subject(:modifier_list) { described_class.new(:block, nil, [nil, '', {}, enabled: false]) }
6
+
7
+ it 'returns an empty string' do
8
+ expect(modifier_list.to_s).to be_empty
9
+ end
10
+
11
+ it 'returns an empty array' do
12
+ expect(modifier_list.to_a).to be_empty
13
+ end
14
+
15
+ it 'returns an empty hash' do
16
+ expect(modifier_list.to_h).to be_empty
17
+ end
18
+ end
19
+
20
+ describe 'modifiers from a hash' do
21
+ subject(:modifier_list) { described_class.new(:block_name, nil, enabled: true, theme: :green_islands, disabled: false) }
22
+
23
+ it 'returns modifiers as a string' do
24
+ expect(modifier_list.to_s).to eq 'block-name_enabled block-name_theme_green-islands'
25
+ end
26
+
27
+ it 'returns modifiers as an array' do
28
+ expect(modifier_list.to_a).to match_array %w[block-name_enabled block-name_theme_green-islands]
29
+ end
30
+
31
+ it 'returns modifiers as a hash' do
32
+ expect(modifier_list.to_h).to eql('enabled' => true, 'theme' => 'green-islands')
33
+ end
34
+ end
35
+
36
+ describe 'modifiers from an array' do
37
+ subject(:modifier_list) { described_class.new(:block_name, nil, [:enabled, theme: :green_islands, disabled: false]) }
38
+
39
+ it 'returns modifiers as a string' do
40
+ expect(modifier_list.to_s).to eq 'block-name_enabled block-name_theme_green-islands'
41
+ end
42
+
43
+ it 'returns modifiers as an array' do
44
+ expect(modifier_list.to_a).to match_array %w[block-name_enabled block-name_theme_green-islands]
45
+ end
46
+
47
+ it 'returns modifiers as a hash' do
48
+ expect(modifier_list.to_h).to eql('enabled' => true, 'theme' => 'green-islands')
49
+ end
50
+ end
51
+
52
+ describe 'modifiers from a symbol' do
53
+ subject(:modifier_list) { described_class.new(:block_name, :elem_name, :has_tail) }
54
+
55
+ it 'returns modifiers as a string' do
56
+ expect(modifier_list.to_s).to eq 'block-name__elem-name_has-tail'
57
+ end
58
+
59
+ it 'returns modifiers as an array' do
60
+ expect(modifier_list.to_a).to match_array %w[block-name__elem-name_has-tail]
61
+ end
62
+
63
+ it 'returns modifiers as a hash' do
64
+ expect(modifier_list.to_h).to eql('has-tail' => true)
65
+ end
66
+ end
67
+
68
+ describe 'modifiers from a string' do
69
+ subject(:modifier_list) { described_class.new(:block_name, :elem_name, 'Has-Tail') }
70
+
71
+ it 'returns modifiers as a string' do
72
+ expect(modifier_list.to_s).to eq 'block-name__elem-name_Has-Tail'
73
+ end
74
+
75
+ it 'returns modifiers as an array' do
76
+ expect(modifier_list.to_a).to match_array %w[block-name__elem-name_Has-Tail]
77
+ end
78
+
79
+ it 'returns modifiers as a hash' do
80
+ expect(modifier_list.to_h).to eql('Has-Tail' => true)
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Bemer do
4
+ describe '.config' do
5
+ it 'returns instance of the Configuration class' do
6
+ expect(described_class.config).to be Bemer::Configuration.instance
7
+ end
8
+ end
9
+
10
+ describe '.bem_class' do
11
+ subject(:bem_class) { described_class.method(:bem_class) }
12
+
13
+ let(:empty_arguments) { [nil, false, '', ' '] }
14
+ let(:block_name) { 'Block_Name' }
15
+ let(:element_name) { 'Element_Name' }
16
+ let(:block_class) { 'Block_Name' }
17
+ let(:element_class) { 'Block_Name__Element_Name' }
18
+ let(:modifier_class) { 'Block_Name__Element_Name_Has_Tail' }
19
+ let(:modifier_class_with_value) { 'Block_Name__Element_Name_Has_Tail_Yes' }
20
+
21
+ it 'creates an empty class from empty arguments', :aggregate_failures do
22
+ empty_arguments.combination(2).each do |block, element|
23
+ expect(bem_class.call(block, element_name)).to be_empty
24
+ expect(bem_class.call(block, element)).to be_empty
25
+ end
26
+ end
27
+
28
+ it 'creates a block class' do
29
+ expect(bem_class.call(block_name)).to eq block_class
30
+ end
31
+
32
+ it 'creates an element class' do
33
+ expect(bem_class.call(block_name, element_name)).to eq element_class
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
4
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
5
+
6
+ require_relative 'config/application'
7
+
8
+ Rails.application.load_tasks
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationController < ActionController::Base
4
+ protect_from_forgery with: :exception
5
+ end
File without changes
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ApplicationHelper
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationJob < ActiveJob::Base
4
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationMailer < ActionMailer::Base
4
+ default from: 'from@example.com'
5
+ layout 'mailer'
6
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationRecord < ActiveRecord::Base
4
+ self.abstract_class = true
5
+ end
File without changes
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= csrf_meta_tags %>
6
+
7
+ <%= stylesheet_link_tag 'application', media: 'all' %>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ APP_PATH = File.expand_path('../config/application', __dir__)
5
+ require_relative '../config/boot'
6
+ require 'rails/commands'
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../config/boot'
5
+ require 'rake'
6
+ Rake.application.run
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'pathname'
5
+ require 'fileutils'
6
+ include FileUtils
7
+
8
+ # path to your application root.
9
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
10
+
11
+ def system!(*args)
12
+ system(*args) || abort("\n== Command #{args} failed ==")
13
+ end
14
+
15
+ chdir APP_ROOT do
16
+ # This script is a starting point to setup your application.
17
+ # Add necessary setup steps to this file.
18
+
19
+ puts '== Installing dependencies =='
20
+ system! 'gem install bundler --conservative'
21
+ system('bundle check') || system!('bundle install')
22
+
23
+ # Install JavaScript dependencies if using Yarn
24
+ # system('bin/yarn')
25
+
26
+ # puts "\n== Copying sample files =="
27
+ # unless File.exist?('config/database.yml')
28
+ # cp 'config/database.yml.sample', 'config/database.yml'
29
+ # end
30
+
31
+ puts "\n== Preparing database =="
32
+ system! 'bin/rails db:setup'
33
+
34
+ puts "\n== Removing old logs and tempfiles =="
35
+ system! 'bin/rails log:clear tmp:clear'
36
+
37
+ puts "\n== Restarting application server =="
38
+ system! 'bin/rails restart'
39
+ end
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'pathname'
5
+ require 'fileutils'
6
+ include FileUtils
7
+
8
+ # path to your application root.
9
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
10
+
11
+ def system!(*args)
12
+ system(*args) || abort("\n== Command #{args} failed ==")
13
+ end
14
+
15
+ chdir APP_ROOT do
16
+ # This script is a way to update your development environment automatically.
17
+ # Add necessary update steps to this file.
18
+
19
+ puts '== Installing dependencies =='
20
+ system! 'gem install bundler --conservative'
21
+ system('bundle check') || system!('bundle install')
22
+
23
+ puts "\n== Updating database =="
24
+ system! 'bin/rails db:migrate'
25
+
26
+ puts "\n== Removing old logs and tempfiles =="
27
+ system! 'bin/rails log:clear tmp:clear'
28
+
29
+ puts "\n== Restarting application server =="
30
+ system! 'bin/rails restart'
31
+ end
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ VENDOR_PATH = File.expand_path('..', __dir__)
5
+ Dir.chdir(VENDOR_PATH) do
6
+ begin
7
+ exec "yarnpkg #{ARGV.join(' ')}"
8
+ rescue Errno::ENOENT
9
+ warn 'Yarn executable was not detected in the system.'
10
+ warn 'Download Yarn at https://yarnpkg.com/en/docs/install'
11
+ exit 1
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is used by Rack-based servers to start the application.
4
+
5
+ require_relative 'config/environment'
6
+
7
+ run Rails.application
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'boot'
4
+
5
+ # Pick the frameworks you want:
6
+ require 'active_record/railtie'
7
+ require 'action_controller/railtie'
8
+ require 'action_view/railtie'
9
+ require 'action_mailer/railtie'
10
+ require 'active_job/railtie'
11
+ # require "action_cable/engine"
12
+ # require "rails/test_unit/railtie"
13
+ # require "sprockets/railtie"
14
+
15
+ Bundler.require(*Rails.groups)
16
+ require 'bemer'
17
+
18
+ module Dummy
19
+ class Application < Rails::Application
20
+ # Initialize configuration defaults for originally generated Rails version.
21
+ config.load_defaults 5.1
22
+
23
+ # Settings in config/environments/* take precedence over those specified here.
24
+ # Application configuration should go into files in config/initializers
25
+ # -- all .rb files in that directory are automatically loaded.
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
5
+
6
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
7
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
@@ -0,0 +1,10 @@
1
+ development:
2
+ adapter: async
3
+
4
+ test:
5
+ adapter: async
6
+
7
+ production:
8
+ adapter: redis
9
+ url: redis://localhost:6379/1
10
+ channel_prefix: dummy_production
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ #
7
+ default: &default
8
+ adapter: sqlite3
9
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
10
+ timeout: 5000
11
+
12
+ development:
13
+ <<: *default
14
+ database: db/development.sqlite3
15
+
16
+ # Warning: The database defined as "test" will be erased and
17
+ # re-generated from your development database when you run "rake".
18
+ # Do not set this db to the same as development or production.
19
+ test:
20
+ <<: *default
21
+ database: db/test.sqlite3
22
+
23
+ production:
24
+ <<: *default
25
+ database: db/production.sqlite3
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Load the Rails application.
4
+ require_relative 'application'
5
+
6
+ # Initialize the Rails application.
7
+ Rails.application.initialize!
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ Rails.application.configure do
4
+ # Settings specified here will take precedence over those in config/application.rb.
5
+
6
+ # In the development environment your application's code is reloaded on
7
+ # every request. This slows down response time but is perfect for development
8
+ # since you don't have to restart the web server when you make code changes.
9
+ config.cache_classes = false
10
+
11
+ # Do not eager load code on boot.
12
+ config.eager_load = false
13
+
14
+ # Show full error reports.
15
+ config.consider_all_requests_local = true
16
+
17
+ # Enable/disable caching. By default caching is disabled.
18
+ if Rails.root.join('tmp/caching-dev.txt').exist?
19
+ config.action_controller.perform_caching = true
20
+
21
+ config.cache_store = :memory_store
22
+ config.public_file_server.headers = {
23
+ 'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}"
24
+ }
25
+ else
26
+ config.action_controller.perform_caching = false
27
+
28
+ config.cache_store = :null_store
29
+ end
30
+
31
+ # Don't care if the mailer can't send.
32
+ config.action_mailer.raise_delivery_errors = false
33
+
34
+ config.action_mailer.perform_caching = false
35
+
36
+ # Print deprecation notices to the Rails logger.
37
+ config.active_support.deprecation = :log
38
+
39
+ # Raise an error on page load if there are pending migrations.
40
+ config.active_record.migration_error = :page_load
41
+
42
+ # Raises error for missing translations
43
+ # config.action_view.raise_on_missing_translations = true
44
+
45
+ # Use an evented file watcher to asynchronously detect changes in source code,
46
+ # routes, locales, etc. This feature depends on the listen gem.
47
+ # config.file_watcher = ActiveSupport::EventedFileUpdateChecker
48
+
49
+ RequireReloader.watch :bemer, path: Rails.root.join('..', '..').to_s,
50
+ callback: proc { load Rails.root.join('config', 'initializers', 'bemer.rb') } # rubocop:disable Metrics/LineLength
51
+ end