flowcation 0.2.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 24fd6a618c9f05708f4103d8a815dd35eabfee46
4
+ data.tar.gz: 419630b742e5bc28a2539f18b0f0fb917faaadee
5
+ SHA512:
6
+ metadata.gz: 4dd8f73e2678a3eadbb18490712dd52c1b22c505069183696c028dd0c96110a58f1c2fd08986b0261a36d4f9ae722d450901039b3362d3aa5724e3408cf827e8
7
+ data.tar.gz: 475d799ea45c5070af1efbc5c8f7f31c6cf2371ef890e6026a5e537ad3dfa29de6590269f11784aede4abedaea1bca3c7dd69faf35e73d1b70b0b9bcceb7ce98
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.0
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at TODO: Write your email address. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in flowcation.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ flowcation (0.2.0)
5
+ activesupport (~> 5.1.5)
6
+ nokogiri (~> 1.8.2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (5.1.6)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ concurrent-ruby (1.0.5)
17
+ i18n (1.0.0)
18
+ concurrent-ruby (~> 1.0)
19
+ mini_portile2 (2.3.0)
20
+ minitest (5.11.3)
21
+ nokogiri (1.8.2)
22
+ mini_portile2 (~> 2.3.0)
23
+ rake (10.5.0)
24
+ thread_safe (0.3.6)
25
+ tzinfo (1.2.5)
26
+ thread_safe (~> 0.1)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ bundler (~> 1.16)
33
+ flowcation!
34
+ minitest (~> 5.0)
35
+ rake (~> 10.0)
36
+
37
+ BUNDLED WITH
38
+ 1.16.0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Matthias Hennemeyer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # Flowcation
2
+
3
+ # This is pre-alpha. Don't use just yet :)
4
+
5
+ Generate Views from static Html.
6
+ Flowcation enables Designers to work on a rails apps layout without installing ruby and rails locally.
7
+ This is also useful for Themes purchased from a marketplace like themeforest.
8
+ The time-consuming integration can be almost entirely omitted.
9
+ The one-off effort of mapping layouts, templates, partials and subtitutions via xpath declarations allows to transfer further, at least minor, changes automatically.
10
+
11
+
12
+ ## Installation
13
+
14
+ ### Prerequisites
15
+
16
+ Flowcation depends on Nokogiri (1.8.2) and ActiveSupport.
17
+
18
+ ### Basic
19
+
20
+ $ gem install flowcation
21
+
22
+ ### Bundler
23
+
24
+ Add this line to your application's Gemfile:
25
+
26
+ ```ruby
27
+ gem 'flowcation'
28
+ ```
29
+
30
+ And then execute:
31
+
32
+ $ bundle
33
+
34
+ ### Rails
35
+
36
+ After installing via Bundler, execute
37
+
38
+ $ rails g flowcation:install
39
+
40
+ This creates a folder 'flowcation' inside the config with a barebone rails.yml file.
41
+
42
+
43
+ ## Usage
44
+
45
+
46
+
47
+ ## Development
48
+
49
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50
+
51
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mhennemeyer/flowcation. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
60
+
61
+ ## Code of Conduct
62
+
63
+ Everyone interacting in the Flowcation project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mhennemeyer/flowcation/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "flowcation"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/flowcation ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+ require 'flowcation'
3
+ require 'optparse'
4
+
5
+ options = {}
6
+ option_parser = OptionParser.new do |opts|
7
+ opts.on("-c config","--config config", "Relative Path to Yaml Configuration File") do |config|
8
+ options[:config] = File.join(Dir.pwd, config)
9
+ end
10
+ opts.on("-f","--force-overwrite", "Overwrite any file flowcation attempts to generate.") do
11
+ options[:force_overwrite] = true
12
+ end
13
+ end
14
+ option_parser.parse!
15
+
16
+ cmd = :generate
17
+
18
+ case ARGV[0]
19
+ when "generate"
20
+ cmd = :generate
21
+ when "bootstrap"
22
+ cmd = :bootstrap
23
+ else
24
+ cmd = :generate
25
+ end
26
+
27
+ puts "#{cmd} #{options[:config]}"
28
+
29
+ if cmd == :generate
30
+ config = begin
31
+ YAML.load File.new(options[:config]).read
32
+ rescue Exception => e
33
+ puts "Invalid Configuration."
34
+ return 1
35
+ end
36
+ if config
37
+ if overwrite = options[:force_overwrite]
38
+ Flowcation::Settings.set('force-overwrite', true)
39
+ end
40
+
41
+ Flowcation::generate config
42
+ Flowcation::Runtime.instance.write_files
43
+ end
44
+ end
45
+
@@ -0,0 +1,38 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "flowcation/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "flowcation"
8
+ spec.version = Flowcation::VERSION
9
+ spec.authors = ["Matthias Hennemeyer"]
10
+ spec.email = ["mhennemeyer@me.com"]
11
+
12
+ spec.summary = %q{Generate Views from static Html files.}
13
+ spec.homepage = "http://www.flowcation.com"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = ['flowcation'] #spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency "activesupport", "~> 5.1.5"
33
+ spec.add_dependency "nokogiri", "~> 1.8.2"
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.16"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "minitest", "~> 5.0"
38
+ end
@@ -0,0 +1,30 @@
1
+ module Flowcation
2
+ class Assets
3
+
4
+ def self.from_config(config={})
5
+ config.each do |name, options|
6
+ options['folders'].each do |path, asset_folder_name|
7
+ asset_folder_path = File.join(options['output'], asset_folder_name)
8
+ FileUtils.mkdir_p(asset_folder_path)
9
+ asset_folder = File.new(asset_folder_path)
10
+ copy_assets \
11
+ source: File.join(options['input'], path),
12
+ target: asset_folder
13
+ end
14
+ end
15
+ end
16
+
17
+ def self.copy_assets(source:, target:)
18
+ FileUtils.mkdir_p(target)
19
+ Dir.entries(source).reject {|file_name| %w(. ..).include?(file_name) }.each do |file_name|
20
+ if File.directory? File.join(source, file_name)
21
+ copy_assets \
22
+ source: File.join(source, file_name),
23
+ target: File.join(target, file_name)
24
+ else
25
+ FileUtils.cp(File.join(source, file_name), target)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,8 @@
1
+ module Flowcation
2
+ class Block
3
+ attr_reader :name, :type, :xpath
4
+ def initialize(name, options={})
5
+ @name, @type, @xpath = name, (options['substitute']||'content'), options['xpath']
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module Flowcation
2
+ class BlockNotFoundException < Exception
3
+ def self.build(xpath:, path:)
4
+ new("Yield Block #{xpath} not found for Layout #{path}")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ module Flowcation
2
+ module Callbacks
3
+ extend ActiveSupport::Concern
4
+ included do
5
+ end
6
+
7
+ class_methods do
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,63 @@
1
+ module Flowcation
2
+ module FileWriter
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ end
7
+
8
+ class_methods do
9
+ def file_writer_collections
10
+ @file_writer_collections
11
+ end
12
+ def writeables(file_writer_collections)
13
+ @file_writer_collections = file_writer_collections
14
+ end
15
+ end
16
+
17
+ def write_files
18
+ self.class.file_writer_collections.each do |writables|
19
+ send(writables).each do |writeable|
20
+ file_name = writeable.path
21
+ path = File.dirname file_name
22
+ FileUtils.mkdir_p(path)
23
+ if check_if_generated_by_flowcation! file_name
24
+ file = File.new(file_name, 'w')
25
+ c = writeable.content
26
+ c = add_generated_comment c
27
+ File.write(file, c.encode(cr_newline: true))
28
+ 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
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ def within_comment(content)
36
+ comment = Settings.get('comment') || DEFAULT_COMMENT
37
+ comment.sub("::comment::", content)
38
+ end
39
+
40
+ def generated_comment
41
+ Settings.get('generated-line') || DEFAULT_GENERATED_TEXT
42
+ end
43
+
44
+ def add_generated_comment(content)
45
+ within_comment(generated_comment) + "\n" + content
46
+ end
47
+
48
+ def generated?(file)
49
+ !!File.open(file).readlines.first&.scan(/#{generated_comment}/)&.send(:[],0)
50
+ end
51
+
52
+ def check_if_generated_by_flowcation!(file)
53
+ return true unless File.exist? file
54
+ return true if Settings.get('force-overwrite')
55
+ generated? file
56
+ # if generated? file
57
+ # return true
58
+ # else
59
+ # raise OverwriteException.for_file(file)
60
+ # end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,47 @@
1
+ module Flowcation
2
+ class Layout
3
+ include Substitutions, Registry
4
+ register :blocks, type: :list
5
+ attr_reader :path
6
+ def initialize(doc, path, blocks, substitutions, format)
7
+ @doc = doc
8
+ @path = path
9
+ @format = format
10
+ @substitutions = substitutions
11
+ blocks.each do |name, options|
12
+ register_block Flowcation::Block.new(name, options)
13
+ end
14
+ end
15
+
16
+ def content
17
+ doc = @doc.dup
18
+ substitute(doc)
19
+ blocks.each do |block|
20
+ block_doc = doc.at_xpath(block.xpath)
21
+ raise BlockNotFoundException.build(xpath: block.xpath, path: self.path) unless block_doc
22
+ value = @format.sub("::name::", block.name)
23
+ case block.type
24
+ when 'content'
25
+ doc.at_xpath(block.xpath).content = value
26
+ when 'replace'
27
+ doc.at_xpath(block.xpath).replace Nokogiri::XML::Text.new(value, doc.document)
28
+ when 'replace_collection'
29
+ doc.at_xpath(block.xpath).replace Nokogiri::XML::Text.new(value, doc.document)
30
+ doc.xpath(block.xpath).each do |node|
31
+ node.remove if node.is_a? Nokogiri::XML::Element
32
+ end
33
+ end
34
+ end
35
+ Render.sanitize(doc.to_html(encoding: 'UTF-8'))
36
+ end
37
+
38
+ def self.from_config(options={})
39
+ new \
40
+ Nokogiri::HTML(File.new(options['file'])).xpath("/html"),
41
+ options['path'],
42
+ options['yields'],
43
+ options['substitutions'],
44
+ options['format']
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,7 @@
1
+ module Flowcation
2
+ class OverwriteException < Exception
3
+ def self.for_file(file)
4
+ new "Attempt to overwrite file not generated by flowcation: \n#{file}"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ module Flowcation
2
+ class Partial
3
+ include Substitutions, Callbacks
4
+ attr_reader :path
5
+ def initialize(doc, path, substitutions)
6
+ @doc = doc
7
+ @path = path
8
+ @substitutions = substitutions || []
9
+ end
10
+
11
+ def content
12
+ doc = @doc.dup
13
+ substitute(doc)
14
+ Render.sanitize(doc.to_html(encoding: 'UTF-8'))
15
+ end
16
+
17
+ def self.from_config(options={})
18
+ doc = Nokogiri::HTML(File.new(options['file'])).xpath("//body").xpath(options['xpath'])
19
+ doc = doc[0].children if options['type'] == 'content'
20
+ partial = Flowcation::Partial.new \
21
+ doc,
22
+ options['path'],
23
+ options['substitutions']
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ module Flowcation
2
+ module Registry
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ end
7
+
8
+ class_methods do
9
+ def register(register, options={})
10
+ list = options[:type] == :list
11
+ #registrator = options[:in] || :instance
12
+ data = ActiveSupport::Inflector.singularize(register)
13
+ define_method("register_#{data}") do |obj, v=nil|
14
+ v ? send(register)[obj] = v : send(register) << obj
15
+ end
16
+ define_method(register) do
17
+ instance_variable_set "@#{register}", (list ? [] : {}) unless instance_variable_get "@#{register}"
18
+ instance_variable_get "@#{register}"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,12 @@
1
+ module Flowcation
2
+ module Render
3
+ def self.sanitize(s)
4
+ s.
5
+ gsub("%&gt;", "%>").
6
+ gsub("&lt;%", "<%").
7
+ gsub("\r\n", "\n").
8
+ gsub("%20", " ").
9
+ gsub("&amp;", "&")
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,28 @@
1
+ require "singleton"
2
+ module Flowcation
3
+ class Runtime
4
+ include Registry, Singleton, FileWriter
5
+ register :layouts, type: :list
6
+ register :templates, type: :list
7
+ register :partials, type: :list
8
+ writeables %i( layouts templates partials )
9
+
10
+ def self.register_layouts_from_config(config={})
11
+ config&.each do |name, options|
12
+ instance.register_layout Layout.from_config(options)
13
+ end
14
+ end
15
+
16
+ def self.register_templates_from_config(config={})
17
+ config&.each do |name, options|
18
+ instance.register_template Template.from_config(options)
19
+ end
20
+ end
21
+
22
+ def self.register_partial_from_config(config={})
23
+ config&.each do |name, options|
24
+ instance.register_partial Partial.from_config(options)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ require "singleton"
2
+ module Flowcation
3
+ class Settings
4
+ include Registry, Singleton
5
+ register :settings
6
+
7
+ def self.get(k)
8
+ instance.settings[k]
9
+ end
10
+
11
+ def self.set(k, v)
12
+ instance.settings[k] = v
13
+ end
14
+
15
+ def self.from_config(options={})
16
+ options.each do |k,v|
17
+ instance.register_setting k,v
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ module Flowcation
2
+ class Substitution
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
6
+ end
7
+ def apply(doc)
8
+ element = doc.at_xpath(@xpath)
9
+ raise SubstitutionNotFoundException.build(xpath: @xpath, name: @name) unless element
10
+ case @type
11
+ when 'content'
12
+ doc.at_xpath(@xpath).content = @value
13
+ when 'attribute'
14
+ doc.at_xpath(@xpath).attributes[@key].value = @value
15
+ 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)
20
+ when 'replace_collection'
21
+ doc.xpath(@xpath).first.replace Nokogiri::XML::Text.new(@value, doc.document)
22
+ doc.xpath(@xpath).each do |node|
23
+ node.remove if node.is_a? Nokogiri::XML::Element
24
+ end
25
+ end
26
+ doc
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ module Flowcation
2
+ class SubstitutionNotFoundException < Exception
3
+ def self.build(xpath:, name:)
4
+ new("Substitution #{name} not found for xpath #{xpath}")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ module Flowcation
2
+ module Substitutions
3
+ def substitute(doc)
4
+ @substitutions&.each do |name, settings|
5
+ substitution = Substitution.new \
6
+ name,
7
+ settings['xpath'],
8
+ settings['substitute'],
9
+ settings['value'],
10
+ settings['key']
11
+
12
+ substitution.apply(doc)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,48 @@
1
+ module Flowcation
2
+ class Template
3
+ include Substitutions, Registry
4
+ register :blocks, type: :list
5
+ attr_reader :path, :layout_name
6
+ def initialize(doc, layout, path, content_for_blocks, substitutions, format)
7
+ @doc = doc
8
+ @path = path
9
+ @layout_name = layout
10
+ @substitutions = substitutions
11
+ @format = format
12
+ content_for_blocks.each do |name, options|
13
+ register_block Flowcation::Block.new(name, options)
14
+ end
15
+ end
16
+
17
+ def content
18
+ doc = @doc.dup
19
+ substitute(doc)
20
+ erb = ""
21
+ blocks.each do |block|
22
+ block_doc = doc.at_xpath(block.xpath)
23
+ raise BlockNotFoundException.build(xpath: block.xpath, path: self.path) unless block_doc
24
+ content = case block.type
25
+ when 'content'
26
+ doc.at_xpath(block.xpath).inner_html
27
+ when 'replace_collection'
28
+ doc.xpath(block.xpath).to_html
29
+ end
30
+
31
+ erb << @format.
32
+ sub("::name::", block.name).
33
+ sub("::content::", content)
34
+ end
35
+ Render.sanitize(erb)
36
+ end
37
+
38
+ def self.from_config(options={})
39
+ new \
40
+ Nokogiri::HTML(File.new(options['file'])).xpath("//body"),
41
+ options['layout'],
42
+ options['path'],
43
+ options['content_for'],
44
+ options['substitutions'],
45
+ options['format']
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ module Flowcation
2
+ VERSION = "0.2.0"
3
+ end
data/lib/flowcation.rb ADDED
@@ -0,0 +1,36 @@
1
+ require 'nokogiri'
2
+ require 'fileutils'
3
+ require 'yaml'
4
+ require 'active_support/concern'
5
+ require 'active_support/inflector'
6
+
7
+ require "flowcation/version"
8
+ require "flowcation/registry"
9
+ require "flowcation/callbacks"
10
+ require "flowcation/settings"
11
+ require "flowcation/file_writer"
12
+ require "flowcation/runtime"
13
+ require 'flowcation/block'
14
+ require 'flowcation/substitution'
15
+ require 'flowcation/substitutions'
16
+ require 'flowcation/layout'
17
+ require 'flowcation/template'
18
+ require 'flowcation/partial'
19
+ require 'flowcation/render'
20
+ require 'flowcation/overwrite_exception'
21
+ require 'flowcation/block_not_found_exception'
22
+ require 'flowcation/substitution_not_found_exception'
23
+ require 'flowcation/assets'
24
+
25
+ module Flowcation
26
+ DEFAULT_GENERATED_TEXT = "GENERATED_BY_FLOWCATION"
27
+ DEFAULT_COMMENT = "<!-- ::comment:: -->"
28
+ def self.generate(config)
29
+ Flowcation::Settings.from_config(config['flowcation'])
30
+ Flowcation::Assets.from_config(config['assets'])
31
+
32
+ Flowcation::Runtime.register_layouts_from_config(config['layouts'])
33
+ Flowcation::Runtime.register_templates_from_config(config['templates'])
34
+ Flowcation::Runtime.register_partial_from_config(config['partials'])
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flowcation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Matthias Hennemeyer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-04-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.8.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ description:
84
+ email:
85
+ - mhennemeyer@me.com
86
+ executables:
87
+ - flowcation
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - exe/flowcation
102
+ - flowcation.gemspec
103
+ - lib/flowcation.rb
104
+ - lib/flowcation/assets.rb
105
+ - lib/flowcation/block.rb
106
+ - lib/flowcation/block_not_found_exception.rb
107
+ - lib/flowcation/callbacks.rb
108
+ - lib/flowcation/file_writer.rb
109
+ - lib/flowcation/layout.rb
110
+ - lib/flowcation/overwrite_exception.rb
111
+ - lib/flowcation/partial.rb
112
+ - lib/flowcation/registry.rb
113
+ - lib/flowcation/render.rb
114
+ - lib/flowcation/runtime.rb
115
+ - lib/flowcation/settings.rb
116
+ - lib/flowcation/substitution.rb
117
+ - lib/flowcation/substitution_not_found_exception.rb
118
+ - lib/flowcation/substitutions.rb
119
+ - lib/flowcation/template.rb
120
+ - lib/flowcation/version.rb
121
+ homepage: http://www.flowcation.com
122
+ licenses:
123
+ - MIT
124
+ metadata:
125
+ allowed_push_host: https://rubygems.org
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.6.12
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Generate Views from static Html files.
146
+ test_files: []