pagebuilder 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +10 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/gems.rb +6 -0
- data/lib/pagebuilder.rb +11 -0
- data/lib/pagebuilder/document.rb +31 -0
- data/lib/pagebuilder/elements.rb +8 -0
- data/lib/pagebuilder/elements/anchor.rb +31 -0
- data/lib/pagebuilder/elements/basic.rb +38 -0
- data/lib/pagebuilder/elements/input.rb +44 -0
- data/lib/pagebuilder/elements/inputs.rb +13 -0
- data/lib/pagebuilder/elements/inputs/checkbox.rb +19 -0
- data/lib/pagebuilder/elements/inputs/email.rb +18 -0
- data/lib/pagebuilder/elements/inputs/file.rb +18 -0
- data/lib/pagebuilder/elements/inputs/hidden.rb +18 -0
- data/lib/pagebuilder/elements/inputs/password.rb +18 -0
- data/lib/pagebuilder/elements/inputs/radio_button.rb +19 -0
- data/lib/pagebuilder/elements/inputs/search.rb +18 -0
- data/lib/pagebuilder/elements/inputs/submit_button.rb +18 -0
- data/lib/pagebuilder/elements/inputs/text.rb +18 -0
- data/lib/pagebuilder/tag_helpers.rb +23 -0
- data/lib/pagebuilder/tag_helpers/embeds.rb +65 -0
- data/lib/pagebuilder/tag_helpers/forms.rb +90 -0
- data/lib/pagebuilder/tag_helpers/lists.rb +33 -0
- data/lib/pagebuilder/tag_helpers/miscellaneous.rb +59 -0
- data/lib/pagebuilder/tag_helpers/page_structure.rb +69 -0
- data/lib/pagebuilder/tag_helpers/pagebuilder_prefixed_helpers.rb +28 -0
- data/lib/pagebuilder/tag_helpers/tables.rb +49 -0
- data/lib/pagebuilder/tag_helpers/text_markup.rb +165 -0
- data/lib/pagebuilder/version.rb +4 -0
- data/pagebuilder.gemspec +34 -0
- metadata +170 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 20c3e9b1f9ee062b88333481c0b3ae229f74c2ef
|
4
|
+
data.tar.gz: bf084d67ff8d49de5670df8c251f5c14d668f307
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 266e3a19041f3aa0b65d680d9066853339dbde525bc776371c4126e6222a50afe589df3469b620cc02bc5955b4aca6ed15bed03a5acacd123cba6c24f7f3dd01
|
7
|
+
data.tar.gz: 7a2f224579aab8e416e5f845be8cfb064fff14186bf979daa8d74dc4448b9a9260b6763996c35d4d6f0b7f60ed5eadf5b9bc372d56917d7f65b1aafd23a0be81
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 through github. 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/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Rob Widmer
|
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,51 @@
|
|
1
|
+
# Pagebuilder
|
2
|
+
|
3
|
+
This gem provides helpers for building html pages. It uses the nokogiri gem to manage the page/DOM.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'pagebuilder'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install pagebuilder
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Include `PageBuilder::Tags` in the class where you want to build out pages. It will add helper methods for most HTML 5 tags. As an example, you can then call `a 'click here', href: 'http://www.example.com'` to generate an anchor node that links to `http://www.example.com` with "click here" as the text.
|
24
|
+
|
25
|
+
### Available helpers
|
26
|
+
|
27
|
+
There are some helpers added with the tags that are not directly related to element nodes. These are generally prefixed with `pagebuilder_` and are private except for the `to_html` method.
|
28
|
+
|
29
|
+
- `to_html` (public method)
|
30
|
+
- It calls `to_html` on the document to generate the output
|
31
|
+
- `pagebuilder_document` and `pagebuilder_document=`
|
32
|
+
- Read or set the Nokogiri HTML document that should be used for generating html nodes
|
33
|
+
- If a document has not been set, an html5 doctyped Nokogiri Document will be created the first time it is called
|
34
|
+
|
35
|
+
## Development
|
36
|
+
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec`, or just `rspec`, to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rdubya/pagebuilder. 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.
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
48
|
+
|
49
|
+
## Code of Conduct
|
50
|
+
|
51
|
+
Everyone interacting in the Pagebuilder project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rdubya/pagebuilder/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "pagebuilder"
|
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
data/gems.rb
ADDED
data/lib/pagebuilder.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PageBuilder
|
4
|
+
|
5
|
+
# Adds helper methods to the standard Nokogiri HTML document and
|
6
|
+
# forces an html5 doctype
|
7
|
+
class Document < Nokogiri::HTML::Document
|
8
|
+
|
9
|
+
# TODO Make helpers for more often used meta tags
|
10
|
+
# TODO make helpers for more common link tags
|
11
|
+
|
12
|
+
def self.new
|
13
|
+
# This is the only way I've found so far to force the html5 subtype
|
14
|
+
parse('<!DOCTYPE html><html><head></head><body></body></html>')
|
15
|
+
end
|
16
|
+
|
17
|
+
# Gets the body node for the document
|
18
|
+
# @return [Nokogiri::XML::Node]
|
19
|
+
def body
|
20
|
+
@body ||= at('/html/body')
|
21
|
+
end
|
22
|
+
|
23
|
+
# Gets the head node for the document
|
24
|
+
# @return [Nokogiri::XML::Node]
|
25
|
+
def head
|
26
|
+
@head ||= at('/html/head')
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PageBuilder
|
4
|
+
module Elements
|
5
|
+
|
6
|
+
# Creates anchor nodes and adds some helper
|
7
|
+
# methods for commonly used attributes
|
8
|
+
class Anchor < Basic
|
9
|
+
|
10
|
+
# We have to override #new because nokogiri creates
|
11
|
+
# the nodes before calling initialize
|
12
|
+
# @param parent_or_doc [Nokogiri::XML::Node, Nokogiri::XML::Document] something to pull the current document from
|
13
|
+
def self.new(parent_or_doc)
|
14
|
+
super('a', parent_or_doc)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Gets the current href attribute's value
|
18
|
+
# @return [String, nil]
|
19
|
+
def href
|
20
|
+
self['href']
|
21
|
+
end
|
22
|
+
|
23
|
+
# Sets the href attribute's value
|
24
|
+
# @param url [String] the url to link to
|
25
|
+
# @return void
|
26
|
+
def href=(url)
|
27
|
+
self['href'] = url
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module PageBuilder
|
2
|
+
module Elements
|
3
|
+
|
4
|
+
# A wrapper for Nokogiri::XML::Element so that
|
5
|
+
# we can add extra helpers
|
6
|
+
class Basic < Nokogiri::XML::Element
|
7
|
+
|
8
|
+
# Helper to easily set the content and attributes for this element
|
9
|
+
# @param content [String] text for the content of the element
|
10
|
+
# @param attributes [] keyword arguments for the attributes that should be set
|
11
|
+
# @option data [Hash] data attributes that should be set
|
12
|
+
# @return [self]
|
13
|
+
def configure(content = nil, **attributes)
|
14
|
+
self.content = content if content
|
15
|
+
|
16
|
+
# Deal with helper attributes
|
17
|
+
data_attrs = attributes.delete(:data)
|
18
|
+
self.data_attributes = data_attrs if data_attrs
|
19
|
+
|
20
|
+
# Set normal attributes
|
21
|
+
attributes.each { |k, v| self[k] = v }
|
22
|
+
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
# Helper to set data attributes as a single call instead of
|
27
|
+
# an individual line for each attributes
|
28
|
+
# @param attributes [Hash] data attributes that should be set (minus the "data-" prefix)
|
29
|
+
# @return void
|
30
|
+
def data_attributes=(attributes)
|
31
|
+
attributes.each do |k, v|
|
32
|
+
self["data-#{k}"] = v
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PageBuilder
|
4
|
+
module Elements
|
5
|
+
|
6
|
+
# Creates anchor nodes and adds some helper
|
7
|
+
# methods for commonly used attributes
|
8
|
+
class Input < Basic
|
9
|
+
|
10
|
+
# We have to override #new because nokogiri creates
|
11
|
+
# the nodes before calling initialize
|
12
|
+
# @param parent_or_doc [Nokogiri::XML::Node, Nokogiri::XML::Document] something to pull the current document from
|
13
|
+
def self.new(parent_or_doc)
|
14
|
+
super('input', parent_or_doc)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Gets the current type attribute's value
|
18
|
+
# @return [String, nil]
|
19
|
+
def type
|
20
|
+
self['type']
|
21
|
+
end
|
22
|
+
|
23
|
+
# Sets the type attribute's value
|
24
|
+
# @param type [String] the type of the input
|
25
|
+
# @return void
|
26
|
+
def type=(type)
|
27
|
+
self['type'] = type
|
28
|
+
end
|
29
|
+
|
30
|
+
# Gets the current value attribute's value
|
31
|
+
# @return [String, nil]
|
32
|
+
def value
|
33
|
+
self['value']
|
34
|
+
end
|
35
|
+
|
36
|
+
# Sets the value attribute's value
|
37
|
+
# @param value [String] the value for this input
|
38
|
+
# @return void
|
39
|
+
def value=(value)
|
40
|
+
self['value'] = value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'pagebuilder/elements/inputs/checkbox'
|
2
|
+
require 'pagebuilder/elements/inputs/email'
|
3
|
+
require 'pagebuilder/elements/inputs/file'
|
4
|
+
require 'pagebuilder/elements/inputs/hidden'
|
5
|
+
require 'pagebuilder/elements/inputs/password'
|
6
|
+
require 'pagebuilder/elements/inputs/radio_button'
|
7
|
+
require 'pagebuilder/elements/inputs/search'
|
8
|
+
require 'pagebuilder/elements/inputs/submit_button'
|
9
|
+
require 'pagebuilder/elements/inputs/text'
|
10
|
+
|
11
|
+
# Namespace for all specialized input elements
|
12
|
+
module PageBuilder::Elements::Inputs
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PageBuilder
|
4
|
+
module Elements
|
5
|
+
module Inputs
|
6
|
+
|
7
|
+
# Creates checkbox input nodes and adds some helper
|
8
|
+
# methods for commonly used attributes
|
9
|
+
class Checkbox < PageBuilder::Elements::Input
|
10
|
+
|
11
|
+
def initialize(*args)
|
12
|
+
super
|
13
|
+
self.type = 'checkbox'
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PageBuilder
|
4
|
+
module Elements
|
5
|
+
module Inputs
|
6
|
+
|
7
|
+
# Creates email input nodes
|
8
|
+
class Email < PageBuilder::Elements::Input
|
9
|
+
|
10
|
+
def initialize(*args)
|
11
|
+
super
|
12
|
+
self.type = 'email'
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|