yorinter 0.2.1 → 0.2.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
2
  SHA1:
3
- metadata.gz: 4c275d6128aecdefc5591000be7d0165126f463e
4
- data.tar.gz: 22fb474826894f39def7492ed8c34d469864ead6
3
+ metadata.gz: 2460be357739bdbddd9a34fb844d0bf938543b5f
4
+ data.tar.gz: 2b683055c64747ef4f440a3c3a66f9f23ae9fc97
5
5
  SHA512:
6
- metadata.gz: 2f69338e77c7ea598b7ee27f79bf8560218381e65e47190f857292d11d1f335e1907147cde03d6f11854303039f265a9cddee88490e44c7c727b5919f9a9f28e
7
- data.tar.gz: 97ffb8387c8feb4c0019e73bbc54025d9da24f6b7179189364db3c8cddc4337907007ac4a305111b09ce62837da5d939e5dec722c56c16038be5c29e170d667e
6
+ metadata.gz: 773150a86e149e1504e6ab3a1bdbb0b8f9d20f97f33012b290083d1297c2e9e3cc9f228602c02ebad1845693d912fd6eadfc422bde6ffd2177619174f39f254c
7
+ data.tar.gz: b9cb0cae6cb6ec19041d4385919362b2af591062b4d79d14c6d0a88087c2ee9bd623f8342351f792d54bce2fbead3afbd22ead43513de409b59e0b48e07d881b
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -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 hailn@topica.edu.vn. 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 yorinter.gemspec
6
+ gemspec
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ yorinter (0.1.2)
5
+ activesupport
6
+ haml
7
+ wicked_pdf
8
+ wkhtmltopdf-binary
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activesupport (5.1.4)
14
+ concurrent-ruby (~> 1.0, >= 1.0.2)
15
+ i18n (~> 0.7)
16
+ minitest (~> 5.1)
17
+ tzinfo (~> 1.1)
18
+ addressable (2.5.2)
19
+ public_suffix (>= 2.0.2, < 4.0)
20
+ concurrent-ruby (1.0.5)
21
+ crack (0.4.3)
22
+ safe_yaml (~> 1.0.0)
23
+ diff-lcs (1.3)
24
+ haml (5.0.4)
25
+ temple (>= 0.8.0)
26
+ tilt
27
+ hashdiff (0.3.7)
28
+ i18n (0.9.1)
29
+ concurrent-ruby (~> 1.0)
30
+ minitest (5.11.1)
31
+ public_suffix (3.0.1)
32
+ rake (10.5.0)
33
+ rspec (3.7.0)
34
+ rspec-core (~> 3.7.0)
35
+ rspec-expectations (~> 3.7.0)
36
+ rspec-mocks (~> 3.7.0)
37
+ rspec-core (3.7.1)
38
+ rspec-support (~> 3.7.0)
39
+ rspec-expectations (3.7.0)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.7.0)
42
+ rspec-mocks (3.7.0)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.7.0)
45
+ rspec-support (3.7.0)
46
+ safe_yaml (1.0.4)
47
+ temple (0.8.0)
48
+ thread_safe (0.3.6)
49
+ tilt (2.0.8)
50
+ tzinfo (1.2.4)
51
+ thread_safe (~> 0.1)
52
+ webmock (3.1.1)
53
+ addressable (>= 2.3.6)
54
+ crack (>= 0.3.2)
55
+ hashdiff
56
+ wicked_pdf (1.1.0)
57
+ wkhtmltopdf-binary (0.12.3.1)
58
+
59
+ PLATFORMS
60
+ ruby
61
+
62
+ DEPENDENCIES
63
+ bundler (~> 1.16)
64
+ rake (~> 10.0)
65
+ rspec (~> 3.0)
66
+ webmock (~> 3.1)
67
+ yorinter!
68
+
69
+ BUNDLED WITH
70
+ 1.16.0
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Hai Le
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.
@@ -0,0 +1,43 @@
1
+ # Yorinter
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/yorinter`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'yorinter'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install yorinter
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yorinter. 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.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Yorinter project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/yorinter/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "yorinter"
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__)
@@ -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
@@ -0,0 +1,15 @@
1
+ require "haml"
2
+ require "wicked_pdf"
3
+ require "active_support"
4
+ require 'active_support/core_ext'
5
+
6
+ require "yorinter/version"
7
+ require "yorinter/printable"
8
+ require "yorinter/printable_document"
9
+ require "yorinter/engine"
10
+ require "yorinter/erb_engine"
11
+ require "yorinter/haml_engine"
12
+ require "yorinter/pdf_engine"
13
+
14
+ module Yorinter
15
+ end
@@ -0,0 +1,121 @@
1
+ module Yorinter
2
+ class Engine
3
+ def initialize document, params = {}, options = {}
4
+ @document = document
5
+ @params = params
6
+ @engine = build_engine
7
+ @options = options
8
+ end
9
+
10
+ def document_model
11
+ @document.model || {}
12
+ end
13
+
14
+ def model_endpoint
15
+ if @document.model_endpoint
16
+ PrintableDocument.new(
17
+ template: @document.model_endpoint
18
+ ).render ErbEngine, @params
19
+ end
20
+ end
21
+
22
+ # Get model from endpoint
23
+ def endpoint_model
24
+ if endpoint = model_endpoint
25
+ JSON.parse Net::HTTP.get(URI(endpoint))
26
+ else
27
+ {}
28
+ end
29
+ end
30
+
31
+ def model_binding_object
32
+ model = document_model.deep_merge(endpoint_model)
33
+ JSON.parse(model.to_json, object_class: OpenStruct)
34
+ end
35
+
36
+ def params_binding_object
37
+ JSON.parse((@params || {}).to_json, object_class: OpenStruct)
38
+ end
39
+
40
+ def binding_object
41
+ return @binding_object if @binding_object
42
+
43
+ # Use document binding_object if it already has
44
+ if @document.respond_to?(:binding_object) and @document.binding_object
45
+ return @binding_object = @document.binding_object
46
+ end
47
+
48
+ this = self
49
+ helper = @options[:helper]
50
+
51
+ helper_wrapper = Object.new
52
+ helper_wrapper.instance_eval @document.helper.to_s
53
+
54
+ @binding_object = Object.new.instance_eval do
55
+ @model = this.model_binding_object
56
+ @params = this.params_binding_object
57
+
58
+ # Helper from params
59
+ extend helper if helper
60
+
61
+ # Helper from document
62
+ helper_wrapper.singleton_class.constants.each do |const|
63
+ extend helper_wrapper.singleton_class.const_get const
64
+ end
65
+
66
+ def get_binding
67
+ binding
68
+ end
69
+
70
+ self
71
+ end
72
+ end
73
+
74
+ def document_options
75
+ return @document_options if @document_options
76
+
77
+ @document_options = (@document.options || {}).deep_symbolize_keys
78
+
79
+ # Render title
80
+ if @document_options[:title]
81
+ @document_options[:title] = render_partial @document_options[:title]
82
+ end
83
+
84
+ # Render footer content
85
+ if footer = @document_options[:footer]
86
+ if footer[:content]
87
+ footer[:content] = render_partial footer[:content]
88
+ end
89
+ end
90
+
91
+ @document_options
92
+ end
93
+
94
+ def render_partial template
95
+ PrintableDocument.new(
96
+ template: template,
97
+ binding_object: binding_object
98
+ ).render ErbEngine, @params
99
+ end
100
+
101
+ # Abstract methods
102
+ def build_engine
103
+ raise 'Abstract method'
104
+ end
105
+
106
+ def render
107
+ raise 'Abstract method'
108
+ end
109
+
110
+ class << self
111
+ def search_engine input, output
112
+ (@@engines || {})[[input, output]]
113
+ end
114
+
115
+ def register_engine input, output
116
+ @@engines ||= {}
117
+ @@engines[[input, output]] = self
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,13 @@
1
+ module Yorinter
2
+ class ErbEngine < Engine
3
+ register_engine 'erb','html'
4
+
5
+ def build_engine
6
+ ERB.new(@document.template || '')
7
+ end
8
+
9
+ def render
10
+ @engine.result(binding_object.get_binding)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Yorinter
2
+ class HamlEngine < Engine
3
+ register_engine 'haml', 'html'
4
+
5
+ def build_engine
6
+ Haml::Engine.new(@document.template || '')
7
+ end
8
+
9
+ def render
10
+ @engine.render binding_object
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,33 @@
1
+ module Yorinter
2
+ class PdfEngine < Engine
3
+ def build_engine
4
+ @engine = WickedPdf.new
5
+ end
6
+ end
7
+
8
+ class HtmlToPdfEngine < PdfEngine
9
+ register_engine 'html', 'pdf'
10
+
11
+ def render
12
+ @engine.pdf_from_string(@document.template, document_options)
13
+ end
14
+ end
15
+
16
+ class ErbToPdfEngine < PdfEngine
17
+ register_engine 'erb', 'pdf'
18
+
19
+ def render
20
+ html = ErbEngine.new(@document, @params, @options).render
21
+ @engine.pdf_from_string(html, document_options)
22
+ end
23
+ end
24
+
25
+ class HamlToPdfEngine < PdfEngine
26
+ register_engine 'haml', 'pdf'
27
+
28
+ def render
29
+ html = HamlEngine.new(@document, @params, @options).render
30
+ @engine.pdf_from_string(html, document_options)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,17 @@
1
+ module Yorinter
2
+ DEFAULT_INPUT_FORMAT = 'erb'
3
+ DEFAULT_OUTPUT_FORMAT = 'html'
4
+
5
+ module Printable
6
+ def print params = {}, options = {}
7
+ input_format = self.input_format || DEFAULT_INPUT_FORMAT
8
+ output_format = params[:format] || self.output_format || DEFAULT_OUTPUT_FORMAT
9
+
10
+ engine_class = Engine.search_engine input_format, output_format
11
+
12
+ raise 'Not convertable' unless engine_class
13
+
14
+ engine = engine_class.new(self, params, options).render
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ module Yorinter
2
+ class PrintableDocument
3
+ include Yorinter::Printable
4
+
5
+ def initialize params = {}
6
+ [:name, :code, :version, :template, :helper, :style,
7
+ :model, :model_endpoint, :binding_object,
8
+ :input_format, :output_format, :options].each do |field|
9
+ send("#{field}=".to_sym, params[field]) if params[field]
10
+ end
11
+ end
12
+
13
+ def render engine, params = {}, options = {}
14
+ engine.new(self, params, options).render
15
+ end
16
+
17
+ attr_accessor :name
18
+ attr_accessor :code
19
+ attr_accessor :version
20
+ attr_accessor :template
21
+ attr_accessor :helper
22
+ attr_accessor :style
23
+ attr_accessor :model
24
+ attr_accessor :model_endpoint
25
+ attr_accessor :input_format
26
+ attr_accessor :output_format
27
+ attr_accessor :options
28
+ attr_accessor :binding_object
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module Yorinter
2
+ VERSION = "0.2.2"
3
+ end
@@ -0,0 +1,43 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "yorinter/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yorinter"
8
+ spec.version = Yorinter::VERSION
9
+ spec.authors = ["Hai Le"]
10
+ spec.email = ["hailn@topica.edu.vn"]
11
+
12
+ spec.summary = "Help render document template"
13
+ spec.description = "Support render erb or haml to html or pdf, using data from json or from api endpoint"
14
+ spec.homepage = "https://git.edumall.io/eden/yorinter"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "https://gemall.edumall.io"
21
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
22
+ else
23
+ raise "RubyGems 2.0 or newer is required to protect against " \
24
+ "public gem pushes."
25
+ end
26
+
27
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
28
+ f.match(%r{^(test|spec|features)/})
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.16"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rspec", "~> 3.0"
37
+ spec.add_development_dependency "webmock", "~> 3.1"
38
+
39
+ spec.add_runtime_dependency 'activesupport'
40
+ spec.add_runtime_dependency 'wicked_pdf'
41
+ spec.add_runtime_dependency 'wkhtmltopdf-binary'
42
+ spec.add_runtime_dependency 'haml'
43
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yorinter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hai Le
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-24 00:00:00.000000000 Z
11
+ date: 2019-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -129,7 +129,27 @@ email:
129
129
  executables: []
130
130
  extensions: []
131
131
  extra_rdoc_files: []
132
- files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".travis.yml"
136
+ - CODE_OF_CONDUCT.md
137
+ - Gemfile
138
+ - Gemfile.lock
139
+ - LICENSE.txt
140
+ - README.md
141
+ - Rakefile
142
+ - bin/console
143
+ - bin/setup
144
+ - lib/yorinter.rb
145
+ - lib/yorinter/engine.rb
146
+ - lib/yorinter/erb_engine.rb
147
+ - lib/yorinter/haml_engine.rb
148
+ - lib/yorinter/pdf_engine.rb
149
+ - lib/yorinter/printable.rb
150
+ - lib/yorinter/printable_document.rb
151
+ - lib/yorinter/version.rb
152
+ - yorinter.gemspec
133
153
  homepage: https://git.edumall.io/eden/yorinter
134
154
  licenses:
135
155
  - MIT