ehbrs-tools 0.16.5 → 0.17.0

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 (45) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ehbrs/cooking_book.rb +9 -0
  3. data/lib/ehbrs/cooking_book/build.rb +45 -0
  4. data/lib/ehbrs/cooking_book/build/base_page.rb +43 -0
  5. data/lib/ehbrs/cooking_book/build/index_page.rb +26 -0
  6. data/lib/ehbrs/cooking_book/build/recipe_page.rb +27 -0
  7. data/lib/ehbrs/cooking_book/project.rb +25 -0
  8. data/lib/ehbrs/cooking_book/recipe.rb +37 -0
  9. data/lib/ehbrs/cooking_book/recipe/ingredient.rb +21 -0
  10. data/lib/ehbrs/cooking_book/recipe/measure.rb +60 -0
  11. data/lib/ehbrs/cooking_book/recipe/part.rb +32 -0
  12. data/lib/ehbrs/patches/module/erb_template.rb +11 -0
  13. data/lib/ehbrs/patches/object/erb_template.rb +9 -0
  14. data/lib/ehbrs/patches/object/template.rb +7 -0
  15. data/lib/ehbrs/runner.rb +6 -13
  16. data/lib/ehbrs/runner/cooking_book.rb +30 -0
  17. data/lib/ehbrs/runner/cooking_book/build.rb +32 -0
  18. data/lib/ehbrs/tools/application.rb +13 -0
  19. data/lib/ehbrs/tools/version.rb +1 -1
  20. data/template/ehbrs/cooking_book/build/base_page/layout.html.erb +20 -0
  21. data/template/ehbrs/cooking_book/build/index_page/inner.html.erb +6 -0
  22. data/template/ehbrs/cooking_book/build/recipe_page/inner.html.erb +6 -0
  23. data/template/ehbrs/cooking_book/build/recipe_page/part.html.erb +27 -0
  24. data/vendor/eac_ruby_base0/Gemfile +5 -0
  25. data/vendor/eac_ruby_base0/eac_ruby_base0.gemspec +20 -0
  26. data/vendor/eac_ruby_base0/lib/eac_ruby_base0.rb +7 -0
  27. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/application.rb +69 -0
  28. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner.rb +54 -0
  29. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner/test_all.rb +27 -0
  30. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb +5 -0
  31. data/vendor/eac_ruby_base0/spec/rubocop_spec.rb +7 -0
  32. data/vendor/eac_ruby_base0/spec/spec_helper.rb +100 -0
  33. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb +16 -6
  34. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb +2 -99
  35. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/class_initialize.rb +29 -0
  36. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/instance_initialize.rb +53 -0
  37. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/super_args.rb +54 -0
  38. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb +10 -1
  39. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/template.rb +10 -0
  40. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/template.rb +1 -8
  41. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  42. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +8 -0
  43. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb +14 -4
  44. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +30 -0
  45. metadata +35 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6dc9f681502aa982f3b5f9858770ca29aaf4d993495bf29fdc59e6393a517a47
4
- data.tar.gz: 99b2ab99b50446770660561475f1f164e52bd6728b0532423db5062a1ef622ab
3
+ metadata.gz: 22c8958278ed0b73c620d9dd9db824cd9afc3f5bb10ed9ceec52a9c994173bcf
4
+ data.tar.gz: 0b34372d1969e38768067c175d520d5e214cb2191e01b5bb63d4f878cff12a56
5
5
  SHA512:
6
- metadata.gz: e55b14db254112bc093cb6d1b16c590cd21fcfa626d8969eb7d9c672d6652c4c08be83c4e7152bd715ed4b9105b9164d7529471b87ceeb48ca88880237bd5849
7
- data.tar.gz: a5c2dc9b6fc43cb397ed01aa7ddbba7d3d466507a1974b4c24d9b68b71285e2e666be34c92935f1a467b20a6f963afde0136fe5968989c719468bb8d7ee42bb8
6
+ metadata.gz: 191c6230c49d4c080f56ae46b462785d598c00bf45c876fcbede25b3150e57a17160b4376b404137a6b1cc6de666e1a0480ebe9170927727a28d2633880752ba
7
+ data.tar.gz: 6357f4aabe4cf05c6414e49bd079c9fc3e1963cb44556af608a23f4708ca80ec64a42f9d1d8d420c52760a1b1581c9a4b91355e5edfc3c4d3935130a22959ad1
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Ehbrs
6
+ module CookingBook
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/fs/clearable_directory'
5
+
6
+ module Ehbrs
7
+ module CookingBook
8
+ class Build
9
+ require_sub __FILE__
10
+ enable_simple_cache
11
+ enable_listable
12
+ lists.add_symbol :option, :target_dir
13
+
14
+ common_constructor :project, :options, default: [{}] do
15
+ self.options = self.class.lists.option.hash_keys_validate!(options.symbolize_keys)
16
+ end
17
+
18
+ def run
19
+ target_dir.clear
20
+ index_page.build
21
+ recipes_pages.each(&:build)
22
+ end
23
+
24
+ private
25
+
26
+ def index_page_uncached
27
+ ::Ehbrs::CookingBook::Build::IndexPage.new(self)
28
+ end
29
+
30
+ def recipes_pages_uncached
31
+ project.recipes.map do |recipe|
32
+ ::Ehbrs::CookingBook::Build::RecipePage.new(self, recipe)
33
+ end
34
+ end
35
+
36
+ def target_dir_uncached
37
+ ::EacRubyUtils::Fs::ClearableDirectory.new(options[OPTION_TARGET_DIR] || default_target_dir)
38
+ end
39
+
40
+ def default_target_dir
41
+ project.root.join('dist')
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs/patches/object/erb_template'
5
+
6
+ module Ehbrs
7
+ module CookingBook
8
+ class Build
9
+ class BasePage < SimpleDelegator
10
+ attr_reader :parent
11
+
12
+ def initialize(parent, source_object)
13
+ super(source_object)
14
+ @parent = parent
15
+ end
16
+
17
+ def build
18
+ target_path.write(target_content)
19
+ end
20
+
21
+ def href
22
+ "#{target_basename}.html"
23
+ end
24
+
25
+ def target_path
26
+ parent.target_dir.join(href)
27
+ end
28
+
29
+ def target_content
30
+ erb_result('layout', ::Ehbrs::CookingBook::Build::BasePage)
31
+ end
32
+
33
+ def inner_content
34
+ erb_result('inner', self.class)
35
+ end
36
+
37
+ def erb_result(template_basename, template_source = self)
38
+ template_source.erb_template("#{template_basename}.html.erb", self)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs/cooking_book/build/base_page'
5
+
6
+ module Ehbrs
7
+ module CookingBook
8
+ class Build
9
+ class IndexPage < ::Ehbrs::CookingBook::Build::BasePage
10
+ TITLE = 'Início'
11
+
12
+ def initialize(parent)
13
+ super(parent, nil)
14
+ end
15
+
16
+ def target_basename
17
+ 'index'
18
+ end
19
+
20
+ def title
21
+ TITLE
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs/cooking_book/build/base_page'
5
+ require 'ehbrs/patches/object/erb_template'
6
+
7
+ module Ehbrs
8
+ module CookingBook
9
+ class Build
10
+ class RecipePage < ::Ehbrs::CookingBook::Build::BasePage
11
+ def target_basename
12
+ title.variableize
13
+ end
14
+
15
+ def parts
16
+ @parts ||= super.map { |e| Part.new(e) }
17
+ end
18
+
19
+ class Part < SimpleDelegator
20
+ def content
21
+ ::Ehbrs::CookingBook::Build::RecipePage.erb_template('part.html.erb', self)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs/cooking_book/recipe'
5
+
6
+ module Ehbrs
7
+ module CookingBook
8
+ class Project
9
+ enable_simple_cache
10
+ common_constructor :root do
11
+ self.root = root.to_pathname
12
+ end
13
+
14
+ delegate :to_s, to: :root
15
+
16
+ private
17
+
18
+ def recipes_uncached
19
+ ::Dir.glob(File.join('**', '*.{yml,yaml}'), base: root.to_path).map do |subpath|
20
+ ::Ehbrs::CookingBook::Recipe.from_file(root.join(subpath))
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/yaml'
5
+
6
+ module Ehbrs
7
+ module CookingBook
8
+ class Recipe
9
+ enable_simple_cache
10
+ require_sub __FILE__
11
+
12
+ class << self
13
+ def from_file(path)
14
+ new(::EacRubyUtils::Yaml.load_file(path))
15
+ end
16
+ end
17
+
18
+ common_constructor :source_data do
19
+ self.source_data = source_data.deep_symbolize_keys
20
+ end
21
+
22
+ def title
23
+ source_data.fetch(:title)
24
+ end
25
+
26
+ def notes
27
+ source_data[:notes]
28
+ end
29
+
30
+ def parts
31
+ @parts ||= source_data.fetch(:parts).map do |k, v|
32
+ ::Ehbrs::CookingBook::Recipe::Part.new(k, v)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs/cooking_book/recipe/measure'
5
+
6
+ module Ehbrs
7
+ module CookingBook
8
+ class Recipe
9
+ class Ingredient
10
+ class << self
11
+ def build(label, value)
12
+ new(label, ::Ehbrs::CookingBook::Recipe::Measure.build(value))
13
+ end
14
+ end
15
+
16
+ enable_simple_cache
17
+ common_constructor :name, :measure
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/yaml'
5
+ require 'ehbrs/cooking_book/recipe/ingredient'
6
+
7
+ module Ehbrs
8
+ module CookingBook
9
+ class Recipe
10
+ class Measure
11
+ FLOAT_PATTERN = /\d+(?:\.\d+)?/.freeze
12
+ FRACTION_PATTERN = %r{(#{FLOAT_PATTERN})(?:\s*/\s*(#{FLOAT_PATTERN}))?}.freeze
13
+ QUANTITY_UNIT_PATTERN = /\A#{FRACTION_PATTERN}(?:\s*(\S+))?\z/.freeze
14
+ VARIABLE_PATTERN = /\A\~\z/.freeze
15
+ VARIABLE_TEXT = 'a gosto'
16
+
17
+ class << self
18
+ def build(value)
19
+ value = value.to_s.strip
20
+ build_from_variable(value) || build_from_pattern(value) || build_unknown(value)
21
+ end
22
+
23
+ private
24
+
25
+ def build_from_variable(value)
26
+ VARIABLE_PATTERN.if_match(value, false) do
27
+ new(nil, nil, nil)
28
+ end
29
+ end
30
+
31
+ def build_from_pattern(value)
32
+ QUANTITY_UNIT_PATTERN.if_match(value, false) do |m|
33
+ new(m[1].if_present(&:to_f), m[2].if_present(&:to_f), m[3])
34
+ end
35
+ end
36
+
37
+ def build_unknown(value)
38
+ new(nil, nil, "unknown format: |#{value}|")
39
+ end
40
+ end
41
+
42
+ common_constructor :numerator, :denominator, :unit
43
+
44
+ def to_s
45
+ return VARIABLE_TEXT if variable?
46
+
47
+ "#{quantity_to_s} #{unit}"
48
+ end
49
+
50
+ def quantity_to_s
51
+ numerator.to_s + (denominator.if_present('') { |v| "/ #{v}" })
52
+ end
53
+
54
+ def variable?
55
+ numerator.blank?
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/yaml'
5
+ require 'ehbrs/cooking_book/recipe/ingredient'
6
+
7
+ module Ehbrs
8
+ module CookingBook
9
+ class Recipe
10
+ class Part
11
+ enable_simple_cache
12
+ common_constructor :title, :source_data
13
+
14
+ def notes
15
+ source_data[:notes]
16
+ end
17
+
18
+ private
19
+
20
+ def ingredients_uncached
21
+ source_data.fetch(:ingredients).map do |label, value|
22
+ ::Ehbrs::CookingBook::Recipe::Ingredient.build(label, value)
23
+ end
24
+ end
25
+
26
+ def steps_uncached
27
+ source_data.fetch(:steps)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ehbrs/patches/object/template'
4
+ require 'erb'
5
+
6
+ class Module
7
+ def erb_template(subpath, binding_obj)
8
+ ::ERB.new(template.child(subpath).path.read)
9
+ .result binding_obj.binding
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ehbrs/patches/module/erb_template'
4
+
5
+ class Object
6
+ def erb_template(subpath, binding_obj = self)
7
+ self.class.erb_template(subpath, binding_obj)
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ehbrs/tools/application'
4
+ require 'eac_ruby_utils/patches/object/template'
5
+
6
+ ::EacRubyUtils::Templates::Searcher.default.included_paths <<
7
+ ::Ehbrs::Tools.application.gemspec_dir.join('template').to_path
@@ -1,26 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_cli/core_ext'
4
- require 'ehbrs/tools/version'
3
+ require 'eac_ruby_base0/runner'
4
+ require 'ehbrs/tools/application'
5
5
 
6
6
  module Ehbrs
7
7
  class Runner
8
8
  require_sub __FILE__
9
+ include ::EacRubyBase0::Runner
9
10
 
10
- runner_with :help, :subcommands do
11
+ runner_definition do
11
12
  desc 'Tools for EHB/RS.'
12
- subcommands
13
- alt do
14
- bool_opt '-V', '--version', 'Show version.'
15
- end
16
13
  end
17
14
 
18
- def run
19
- if parsed[:version].present?
20
- out(::Ehbrs::Tools::VERSION + "\n")
21
- else
22
- run_with_subcommand
23
- end
15
+ def application
16
+ ::Ehbrs::Tools.application
24
17
  end
25
18
  end
26
19
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/core_ext'
4
+ require 'ehbrs/cooking_book/project'
5
+
6
+ module Ehbrs
7
+ class Runner
8
+ class CookingBook
9
+ require_sub __FILE__
10
+
11
+ DEFAULT_SOURCE_DIR = '.'
12
+
13
+ runner_with :help, :subcommands do
14
+ desc 'Operações para livros de receitas.'
15
+ arg_opt '-C', '--source-dir', 'Caminho para o diretório do código-fonte.'
16
+ subcommands
17
+ end
18
+
19
+ private
20
+
21
+ def source_dir_uncached
22
+ (parsed.source_dir || DEFAULT_SOURCE_DIR).to_pathname.expand_path
23
+ end
24
+
25
+ def project_uncached
26
+ ::Ehbrs::CookingBook::Project.new(source_dir)
27
+ end
28
+ end
29
+ end
30
+ end