jira_adf 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c12f1f4bf3a957099126699a8573156a43a3bb0f34ae8d285bab4b743806f3d2
4
+ data.tar.gz: 563da7bf6e15d6cb039a1aaf2a699923afb51dabb37f6be05faab74c3c792c4d
5
+ SHA512:
6
+ metadata.gz: 3e1f46ee048bb7cbaa54a84703fcc7ddf15a1448cbaeeed98778c74e9f666288a1f8391ea2d0a9b9f6342585ee3e862c8b9aa9a571b55439553272a0e8f64e3e
7
+ data.tar.gz: 7e43ceb08b89d66420029c1bc552d659d9a2c9c0c6cce2616c446579eb4cd40de77460e1460592670e88a5930940303642e19fa3ba223adbc22b10c66544ab67
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-08-01
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at max@bitsonnet.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ gemspec
5
+
6
+ gem 'rake', '~> 13.0'
7
+ gem 'minitest', '~> 5.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,21 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jira_adf (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.15.0)
10
+ rake (13.0.6)
11
+
12
+ PLATFORMS
13
+ arm64-darwin-21
14
+
15
+ DEPENDENCIES
16
+ jira_adf!
17
+ minitest (~> 5.0)
18
+ rake (~> 13.0)
19
+
20
+ BUNDLED WITH
21
+ 2.3.19
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Max Chernyak
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,75 @@
1
+ # JiraAdf
2
+
3
+ [Atlassian Document Format](https://developer.atlassian.com/cloud/jira/platform/apis/document/structure/) is how Jira and friends format rich text. This tools helps you make those rich texts in ruby, with a neat builder-like syntax.
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ $ bundle add jira_adf
10
+
11
+ If bundler is not being used to manage dependencies, install the gem by executing:
12
+
13
+ $ gem install jira_adf
14
+
15
+ ## Usage
16
+
17
+ ```ruby
18
+ result = JiraAdf {
19
+ # Keyword args become "attrs".
20
+ heading(level: 3) { text('An h3 heading') }
21
+
22
+ ordered_list {
23
+ list_item { paragraph { text('Paragraph in listItem') } }
24
+ list_item {
25
+ paragraph {
26
+ text('Text with ')
27
+
28
+ # Methods chained at the end of the node become "marks". Their
29
+ # keyword args become "attrs" of the mark.
30
+ text('bold and superscript').strong.subsup(type: 'sub')
31
+
32
+ text(' styling in the middle.')
33
+ }
34
+ }
35
+
36
+ # Use a regular lambda for snippet reuse. Keep in mind that due to how
37
+ # closures work, if you call this lambda in sub-nested scopes, it will
38
+ # still add an item in the scope where it was defined. And it will not
39
+ # exist at higher / neighbor scopes.
40
+ item = -> string { list_item { paragraph { text(string) } } }
41
+
42
+ # Now you can use shorter syntax.
43
+ item['Item 3']
44
+ item['Item 4']
45
+ item['Item 5']
46
+ }
47
+ }
48
+
49
+ result.to_h # => Ruby Hash ready for converting to JSON.
50
+ ```
51
+
52
+ If you want to specify custom doc type / version, you can pass args to the `JiraAdf` call.
53
+
54
+ ```ruby
55
+ result = JiraAdf(version: 2, type: 'doc') { … }
56
+ result.to_h
57
+ ```
58
+
59
+ ## Development
60
+
61
+ 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.
62
+
63
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/maxim/jira_adf. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/jira_adf/blob/main/CODE_OF_CONDUCT.md).
68
+
69
+ ## License
70
+
71
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
72
+
73
+ ## Code of Conduct
74
+
75
+ Everyone interacting in the JiraAdf project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/jira_adf/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/test_*.rb']
10
+ end
11
+
12
+ task default: :test
data/jira_adf.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/jira_adf/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'jira_adf'
7
+ spec.version = JiraAdf::VERSION
8
+ spec.authors = ['Max Chernyak']
9
+ spec.email = ['hello@max.engineer']
10
+
11
+
12
+ spec.summary = 'Builder-like syntax for Atlassian Document Format (ADF).'
13
+ spec.description = 'Simple builder for making Atlassian Document Format ' \
14
+ '(ADF) look neat in Ruby.'
15
+ spec.homepage = 'https://github.com/maxim/jira_adf'
16
+ spec.license = 'MIT'
17
+
18
+ spec.required_ruby_version = '>= 2.6.0'
19
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
+
21
+ spec.metadata['homepage_uri'] = spec.homepage
22
+ spec.metadata['source_code_uri'] = spec.homepage
23
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/main/CHANGELOG.md"
24
+
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:bin|test|\.git)})
28
+ end
29
+ end
30
+
31
+ spec.require_paths = ['lib']
32
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class JiraAdf
4
+ VERSION = '0.1.0'
5
+ end
data/lib/jira_adf.rb ADDED
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'jira_adf/version'
4
+
5
+ # A simple ADF (Atlassian Document Format) builder.
6
+ #
7
+ # Usage example:
8
+ #
9
+ # result = JiraAdf {
10
+ # # Keyword args become "attrs".
11
+ # heading(level: 3) { text('An h3 heading') }
12
+ #
13
+ # ordered_list {
14
+ # list_item { paragraph { text('Paragraph in listItem') } }
15
+ # list_item {
16
+ # paragraph {
17
+ # text('Text with ')
18
+ #
19
+ # # Methods chained at the end of the node become "marks". Their
20
+ # # keyword args become "attrs" of the mark.
21
+ # text('bold and superscript').strong.subsup(type: 'sub')
22
+ #
23
+ # text(' styling in the middle.')
24
+ # }
25
+ # }
26
+ #
27
+ # # Use a regular lambda for snippet reuse. Keep in mind that due to how
28
+ # # closures work, if you call this lambda in sub-nested scopes, it will
29
+ # # still add an item in the scope where it was defined. And it will not
30
+ # # exist at higher / neighbor scopes.
31
+ # item = -> string { list_item { paragraph { text(string) } } }
32
+ #
33
+ # # Now you can use shorter syntax.
34
+ # item['Item 3']
35
+ # item['Item 4']
36
+ # item['Item 5']
37
+ # }
38
+ # }
39
+ #
40
+ # result.to_h # => Ruby Hash ready for converting to JSON.
41
+ class JiraAdf
42
+ class << self
43
+ def format_hash(hash)
44
+ hash.map { |k, v|
45
+ key = camelize(k)
46
+
47
+ [ key,
48
+
49
+ if key == 'type'; camelize(v)
50
+ elsif Hash === v; format_hash(v)
51
+ elsif Symbol === v; v.to_s
52
+ else; v
53
+ end
54
+ ]
55
+ }.to_h
56
+ end
57
+
58
+ def camelize(term)
59
+ term.to_s.gsub(/(?:^|_+)([^_])/) { $1.upcase }
60
+ .tap { |s| s[0] = s[0].downcase }
61
+ end
62
+ end
63
+
64
+ def initialize(node = { 'version' => 1, 'type' => 'doc' }, &block)
65
+ @node = self.class.format_hash(node)
66
+ instance_eval(&block) if block_given?
67
+
68
+ # It's important that this variable is not yet set while instance_eval on
69
+ # the previous line is being executed. This is how method_missing can
70
+ # distinguish whether a method was called on a node, or it was called in an
71
+ # instance_eval block. We use this fact to switch to adding `mark` fields
72
+ # instead of `content` fields.
73
+ @block_evaled_or_not_given = true
74
+ end
75
+
76
+ def to_h
77
+ @node.transform_values { |v|
78
+ case v
79
+ when Array; v.map { |e| self.class === e ? e.to_h : e }
80
+ when Hash; v.transform_values { |e| self.class === e ? e.to_h : e }
81
+ when self.class; v.to_h
82
+ else; v
83
+ end
84
+ }
85
+ end
86
+
87
+ def method_missing(type, *args, **kwargs, &block)
88
+ if @block_evaled_or_not_given
89
+ hash = { 'type' => type }
90
+ hash.merge! 'attrs' => kwargs if kwargs.any?
91
+ @node['marks'] ||= []
92
+ @node['marks'] << self.class.new(hash)
93
+ self
94
+ elsif type == :text
95
+ self.class.new('type' => 'text', 'text' => args[0]).tap { |node|
96
+ @node['content'] ||= []
97
+ @node['content'] << node
98
+ }
99
+ else
100
+ hash = { 'type' => type }
101
+ hash.merge! 'attrs' => kwargs if kwargs.any?
102
+ self.class.new(hash, &block).tap { |node|
103
+ @node['content'] ||= []
104
+ @node['content'] << node
105
+ }
106
+ end
107
+ end
108
+ end
109
+
110
+ def JiraAdf(*args, **kwargs, &blk); JiraAdf.new(*args, **kwargs, &blk) end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jira_adf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Max Chernyak
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-08-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Simple builder for making Atlassian Document Format (ADF) look neat in
14
+ Ruby.
15
+ email:
16
+ - hello@max.engineer
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - CHANGELOG.md
22
+ - CODE_OF_CONDUCT.md
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - jira_adf.gemspec
29
+ - lib/jira_adf.rb
30
+ - lib/jira_adf/version.rb
31
+ homepage: https://github.com/maxim/jira_adf
32
+ licenses:
33
+ - MIT
34
+ metadata:
35
+ allowed_push_host: https://rubygems.org
36
+ homepage_uri: https://github.com/maxim/jira_adf
37
+ source_code_uri: https://github.com/maxim/jira_adf
38
+ changelog_uri: https://github.com/maxim/jira_adf/blob/main/CHANGELOG.md
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.6.0
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.3.7
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Builder-like syntax for Atlassian Document Format (ADF).
58
+ test_files: []