flowcation 0.2.18 → 0.2.19

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2e51ea8371dda9e9681420be1bf5952e652dca8
4
- data.tar.gz: fa3c4f855cfd2c95a2cc2f526539ad8f9ec4bc8e
3
+ metadata.gz: c2b5f6400fc880f4774beb7b2cfd623f257cd6a3
4
+ data.tar.gz: d9174f5b83e5385b78e387eb841139327926f354
5
5
  SHA512:
6
- metadata.gz: 8d69ea6443345fadfd78c7cb30fd52ddffdeaad28642e2bb8cfb419899e16767a9cb4e7124384c857f1532cdb5e436bb2fad2ccf141e828b1f5a29698377731f
7
- data.tar.gz: fb4a591712a21717ea434d007562044c4abb90433646cf9d89d95d92c2be173d179d3233c24adf51e298145946bcab8ad88af2060718a77ebd668651bed4d218
6
+ metadata.gz: '078ccdfb5abd001c67da8e954cef22e18ff1c22705cd3dd5f967c5836860be2085daffb337a6109488c8d196aba4a47acd3d47ad67878f13cefcafee5bd6c0e1'
7
+ data.tar.gz: 94ccc5d2abf988099eba38a99c0bb5a32304c86546f50d29b7336cf8122d665a4c5026c45240a7e5e0bbfae441d50b73ebb64818ad13905aad36073bf9508f23
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- flowcation (0.2.18)
4
+ flowcation (0.2.19)
5
5
  activesupport (~> 5.1.5)
6
6
  nokogiri (~> 1.8.2)
7
7
 
data/exe/flowcation CHANGED
@@ -40,7 +40,9 @@ rescue Exception => e
40
40
  return 1
41
41
  end
42
42
 
43
- if config
43
+ if config
44
+ Flowcation::set_user_object name: 'helper', config: config, path: File.dirname(config_path)
45
+ Flowcation::set_user_object name: 'processor', config: config, path: File.dirname(config_path)
44
46
  Flowcation::generate config
45
47
  Flowcation::Runtime.instance.write_files
46
48
  end
data/lib/flowcation.rb CHANGED
@@ -21,10 +21,25 @@ require 'flowcation/overwrite_exception'
21
21
  require 'flowcation/block_not_found_exception'
22
22
  require 'flowcation/substitution_not_found_exception'
23
23
  require 'flowcation/assets'
24
+ require 'flowcation/layout_helper'
25
+ require 'flowcation/processor'
24
26
 
25
27
  module Flowcation
26
28
  DEFAULT_GENERATED_TEXT = "GENERATED_BY_FLOWCATION"
27
29
  DEFAULT_COMMENT = "<!-- ::comment:: -->"
30
+
31
+ def self.set_user_object(name:, config:, path:)
32
+ if settings = config['flowcation']
33
+ file = File.join(path, settings[name])
34
+ if File.exist?(file)
35
+ existing_classes = ObjectSpace.each_object(Class).to_a
36
+ require file
37
+ helper_class = (ObjectSpace.each_object(Class).to_a - existing_classes)[0]
38
+ Flowcation::Settings.set(name + '_object', helper_class.new)
39
+ end
40
+ end
41
+ end
42
+
28
43
  def self.generate(config)
29
44
  Flowcation::Settings.from_config(config['flowcation'])
30
45
  Flowcation::Assets.from_config(config['assets'])
@@ -3,7 +3,7 @@ module Flowcation
3
3
 
4
4
  def self.from_config(config={})
5
5
  config&.each do |name, options|
6
- options['folders'].each do |path, asset_folder_name|
6
+ options['folders']&.each do |path, asset_folder_name|
7
7
  asset_folder_path = File.join(options['output'], asset_folder_name)
8
8
  FileUtils.mkdir_p(asset_folder_path)
9
9
  asset_folder = File.new(asset_folder_path)
@@ -11,7 +11,25 @@ module Flowcation
11
11
  source: File.join(options['input'], path),
12
12
  target: asset_folder
13
13
  end
14
- options['files'].each do |file_name|
14
+
15
+ if processor = Settings.get('processor_object')
16
+ options['post-process']&.each do |asset_path, file_process|
17
+ asset_folder_path = File.join(options['output'], asset_path)
18
+ file_process.each do |file_name, process_method|
19
+ #file = File.new(File.join(asset_folder_path, file_name))
20
+ path = File.join(asset_folder_path, file_name)
21
+ puts "Post Process #{File.join(asset_folder_path, file_name)}"
22
+ lines = IO.readlines(path).map do |line|
23
+ processor.send(process_method, line)
24
+ end
25
+ File.open(path, 'w') do |file|
26
+ file.puts lines
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ options['single-files']&.each do |file_name|
15
33
  output_folder_path = File.join(options['output'])
16
34
  FileUtils.mkdir_p(output_folder_path)
17
35
  output_folder = File.new(output_folder_path)
@@ -15,6 +15,7 @@ module Flowcation
15
15
  end
16
16
 
17
17
  def write_files
18
+ # todo rescue/finally close file
18
19
  self.class.file_writer_collections.each do |writables|
19
20
  send(writables).each do |writeable|
20
21
  file_name = writeable.path
@@ -26,7 +27,7 @@ module Flowcation
26
27
  c = add_generated_comment c
27
28
  File.write(file, c.encode(cr_newline: true))
28
29
  else
29
- STDERR.puts "File #{path} not generated by flowcation. Use -f to overwrite or add Setting 'force-overwrite: true' to configuration yaml file entry 'flowcation:'"
30
+ STDERR.puts "File #{file_name} not generated by flowcation. Use -f to overwrite or add Setting 'force-overwrite: true' to configuration yaml file entry 'flowcation:'"
30
31
  end
31
32
  end
32
33
  end
@@ -0,0 +1,4 @@
1
+ module Flowcation
2
+ class LayoutHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Flowcation
2
+ class Processor
3
+ end
4
+ end
@@ -6,7 +6,11 @@ module Flowcation
6
6
  gsub("&lt;%", "<%").
7
7
  gsub("\r\n", "\n").
8
8
  gsub("%20", " ").
9
- gsub("&amp;", "&")
9
+ gsub("&amp;", "&").
10
+ gsub("=&gt;", "=>").
11
+ gsub("-&gt;", "->").
12
+ gsub("&gt;", ">").
13
+ gsub("&lt;", "<")
10
14
  end
11
15
  end
12
16
  end
@@ -1,27 +1,51 @@
1
1
  module Flowcation
2
2
  class Substitution
3
3
  attr_reader :name, :xpath, :type, :value
4
- def initialize(name, xpath, type, value, key)
5
- @name, @xpath, @type, @value, @key = name, xpath, type, value, key
4
+ def initialize(name, xpath, type, value, key, use_helper)
5
+ @name, @xpath, @type, @value, @key, @use_helper = name, xpath, type, value, key, use_helper
6
+ end
7
+ def value(node)
8
+ if @use_helper && helper = Settings.get('helper_object')
9
+ helper.send(@value, node)
10
+ else
11
+ @value
12
+ end
6
13
  end
7
14
  def apply(doc)
15
+ # todo Refactor to SubstitutionType class with ContentSubstitution, AttributeSubstitution...
16
+
17
+ # todo Better type names. More Like Targets in Stimulus? each->attribute
18
+ # Even Helpers could be included in type: each-replace->LayoutHelper#image_tag
19
+
8
20
  element = doc.at_xpath(@xpath)
9
21
  raise SubstitutionNotFoundException.build(xpath: @xpath, name: @name) unless element
10
22
  case @type
11
23
  when 'content'
12
- doc.at_xpath(@xpath).content = @value
24
+ doc.at_xpath(@xpath).content = value(doc.at_xpath(@xpath))
25
+ when 'content_collection'
26
+ doc.xpath(@xpath).each do |node|
27
+ node.content = value(node)
28
+ end
13
29
  when 'attribute'
14
- doc.at_xpath(@xpath).attributes[@key].value = @value
30
+ doc.at_xpath(@xpath).attributes[@key].value = value(doc.at_xpath(@xpath))
31
+ when 'attribute_collection'
32
+ doc.xpath(@xpath).each do |node|
33
+ node.attributes[@key].value = value(node)
34
+ end
15
35
  when 'replace'
16
- doc.at_xpath(@xpath).replace Nokogiri::XML::Text.new(@value, doc.document)
17
- when 'append'
18
- puts "APPEND #{doc.at_xpath(@xpath).class}"
19
- doc.at_xpath(@xpath).after Nokogiri::XML::Text.new(@value, doc.document)
36
+ doc.at_xpath(@xpath).replace Nokogiri::XML::Text.new(value(doc.at_xpath(@xpath)), doc.document)
37
+ when 'replace_each'
38
+ doc.xpath(@xpath).each do |node|
39
+ node.replace Nokogiri::XML::Text.new(value(node), doc.document)
40
+ end
20
41
  when 'replace_collection'
21
42
  doc.xpath(@xpath).first.replace Nokogiri::XML::Text.new(@value, doc.document)
22
43
  doc.xpath(@xpath).each do |node|
23
44
  node.remove if node.is_a? Nokogiri::XML::Element
24
45
  end
46
+ when 'append'
47
+ puts "APPEND #{doc.at_xpath(@xpath).class}"
48
+ doc.at_xpath(@xpath).after Nokogiri::XML::Text.new(value(doc.at_xpath(@xpath)), doc.document)
25
49
  end
26
50
  doc
27
51
  end
@@ -7,7 +7,8 @@ module Flowcation
7
7
  settings['xpath'],
8
8
  settings['substitute'],
9
9
  settings['value'],
10
- settings['key']
10
+ settings['key'],
11
+ settings['helper']
11
12
 
12
13
  substitution.apply(doc)
13
14
  end
@@ -1,3 +1,3 @@
1
1
  module Flowcation
2
- VERSION = "0.2.18"
2
+ VERSION = "0.2.19"
3
3
  end
@@ -7,7 +7,8 @@ module Flowcation
7
7
  desc "This generator creates a basic rails.yml file at config/flowcation"
8
8
  source_root File.expand_path("../templates", __FILE__)
9
9
  def copy_config_file
10
- copy_file "rails.yml", "config/flowcation/rails.yml"
10
+ copy_file "rails.yml", "config/flowcation/rails.yml"
11
+ copy_file "public.yml", "config/flowcation/public.yml"
11
12
  end
12
13
  end
13
14
  end
@@ -0,0 +1,6 @@
1
+ files:
2
+ input: frontend
3
+ output: public/mockup
4
+ folders:
5
+ single-files:
6
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flowcation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.18
4
+ version: 0.2.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthias Hennemeyer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-13 00:00:00.000000000 Z
11
+ date: 2018-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -108,8 +108,10 @@ files:
108
108
  - lib/flowcation/callbacks.rb
109
109
  - lib/flowcation/file_writer.rb
110
110
  - lib/flowcation/layout.rb
111
+ - lib/flowcation/layout_helper.rb
111
112
  - lib/flowcation/overwrite_exception.rb
112
113
  - lib/flowcation/partial.rb
114
+ - lib/flowcation/processor.rb
113
115
  - lib/flowcation/registry.rb
114
116
  - lib/flowcation/render.rb
115
117
  - lib/flowcation/runtime.rb
@@ -120,6 +122,7 @@ files:
120
122
  - lib/flowcation/template.rb
121
123
  - lib/flowcation/version.rb
122
124
  - lib/generators/flowcation/generate/config_generator.rb
125
+ - lib/generators/flowcation/generate/templates/public.yml
123
126
  - lib/generators/flowcation/generate/templates/rails.yml
124
127
  homepage: http://www.flowcation.com
125
128
  licenses: