diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..f0527e6 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +version: 2 +updates: +- package-ecosystem: bundler + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 +- package-ecosystem: github-actions + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 diff --git a/.github/workflows/linter_erb.yml b/.github/workflows/linter_erb.yml new file mode 100644 index 0000000..81ba405 --- /dev/null +++ b/.github/workflows/linter_erb.yml @@ -0,0 +1,19 @@ +on: [push] + +name: Linter, ERB + +jobs: + run: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@main + + - name: Set up Ruby + uses: ruby/setup-ruby@master + with: + bundler-cache: true + + - name: Run ERB linter + run: bundle exec erb_lint app diff --git a/.github/workflows/linter_rubocop.yml b/.github/workflows/linter_rubocop.yml new file mode 100644 index 0000000..4549c51 --- /dev/null +++ b/.github/workflows/linter_rubocop.yml @@ -0,0 +1,19 @@ +on: [push] + +name: Linter, Rubocop + +jobs: + run: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@main + + - name: Set up Ruby + uses: ruby/setup-ruby@master + with: + bundler-cache: true + + - name: Run Rubocop linter + run: bundle exec rubocop diff --git a/.github/workflows/scan_ruby_brakeman.yml b/.github/workflows/scan_ruby_brakeman.yml new file mode 100644 index 0000000..37883a2 --- /dev/null +++ b/.github/workflows/scan_ruby_brakeman.yml @@ -0,0 +1,19 @@ +on: [push] + +name: Scan Ruby, Brakeman + +jobs: + scan_ruby: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@main + + - name: Set up Ruby + uses: ruby/setup-ruby@master + with: + bundler-cache: true + + - name: Scan for common Rails security vulnerabilities using static analysis + run: bin/brakeman --no-pager diff --git a/.rubocop.yml b/.rubocop.yml index 5537838..db6c2e5 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,100 +1,33 @@ -require: rubocop-rspec +inherit_from: .rubocop_todo.yml -AllCops: - TargetRubyVersion: 2.5 - - Exclude: - - 'db/**/*' - - 'script/*' - - 'bin/*' - - 'log/**/*' - - 'node_modules/**/*' - - 'public/**/*' - - 'vendor/**/*' - - 'tmp/**/*' - - '.git/**/*' - -IndentationConsistency: - EnforcedStyle: 'rails' - -Naming/FileName: - Exclude: - - 'Gemfile' - - 'Guardfile' - - 'Rakefile' - -Rails: - Enabled: true - -Metrics/CyclomaticComplexity: - Max: 15 - -Metrics/PerceivedComplexity: - Max: 15 - -Metrics/ClassLength: - Max: 210 - -Metrics/ParameterLists: - Max: 6 - -Metrics/LineLength: - Max: 200 - -Metrics/MethodLength: - Max: 40 - -Metrics/BlockLength: - Max: 140 +plugins: + - rubocop-capybara + - rubocop-rails + - rubocop-rspec + - rubocop-rspec_rails +AllCops: + NewCops: enable Exclude: - - 'spec/**/*' - -Metrics/AbcSize: - Max: 65 - -Style/Documentation: - Enabled: false + - "db/schema.rb" + - "script/*" + - "bin/*" + - "log/**/*" + - "node_modules/**/*" + - "public/**/*" + - "vendor/**/*" + - "tmp/**/*" + - ".git/**/*" -Style/SymbolArray: - Enabled: false +Layout/HashAlignment: + EnforcedHashRocketStyle: table + EnforcedColonStyle: table -Style/MethodDefParentheses: +Rails/I18nLocaleTexts: Enabled: false -Style/AsciiComments: - Enabled: false - -Style/NestedParenthesizedCalls: - Enabled: false - -# TEMP: private and def foo() are at the same indentation level -# This should NOT cause an offense but it does. ¯\_(ツ)_/¯ -# https://rubocop.readthedocs.io/en/latest/cops_layout/ -Layout/IndentationWidth: +Style/Documentation: Enabled: false Style/FrozenStringLiteralComment: Enabled: false - -Rails/OutputSafety: - Enabled: false - -RSpec/NestedGroups: - Max: 4 - -RSpec/ExampleLength: - Max: 20 - -RSpec/MultipleExpectations: - Max: 10 - -RSpec/VerifiedDoubles: - Enabled: false - -RSpec/MessageSpies: - Enabled: false - -RSpec/DescribeClass: - Exclude: - - 'spec/system/*' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..3749664 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,28 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2025-08-09 04:53:37 UTC using RuboCop version 1.79.2. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 2 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +Metrics/MethodLength: + Max: 15 + +# Offense count: 5 +# Configuration parameters: CountAsOne. +RSpec/ExampleLength: + Max: 9 + +# Offense count: 3 +RSpec/MultipleExpectations: + Max: 3 + +# Offense count: 2 +# Configuration parameters: Include. +# Include: db/**/*.rb +Rails/ThreeStateBooleanColumn: + Exclude: + - 'db/migrate/20170516194159_create_submissions.rb' diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..4f5e697 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.4.5 diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 0224d95..071f00c 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,74 +1,85 @@ -# Contributor Covenant Code of Conduct +# Contributor Covenant 3.0 Code of Conduct ## Our Pledge -In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making participation in our project and -our community a harassment-free experience for everyone, regardless of age, body -size, disability, ethnicity, gender identity and expression, level of experience, -nationality, personal appearance, race, religion, or sexual identity and -orientation. +We pledge to make our community welcoming, safe, and equitable for all. -## Our Standards +We are committed to fostering an environment that respects and promotes the dignity, rights, and contributions of all individuals, regardless of characteristics including race, ethnicity, caste, color, age, physical characteristics, neurodiversity, disability, sex or gender, gender identity or expression, sexual orientation, language, philosophy or religion, national or social origin, socio-economic position, level of education, or other status. The same privileges of participation are extended to everyone who participates in good faith and in accordance with this Covenant. -Examples of behavior that contributes to creating a positive environment -include: +## Encouraged Behaviors -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members +While acknowledging differences in social norms, we all strive to meet our community's expectations for positive behavior. We also understand that our words and actions may be interpreted differently than we intend based on culture, background, or native language. -Examples of unacceptable behavior by participants include: +With these considerations in mind, we agree to behave mindfully toward each other and act in ways that center our shared values, including: -* The use of sexualized language or imagery and unwelcome sexual attention or -advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic - address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting +1. Respecting the **purpose of our community**, our activities, and our ways of gathering. +2. Engaging **kindly and honestly** with others. +3. Respecting **different viewpoints** and experiences. +4. **Taking responsibility** for our actions and contributions. +5. Gracefully giving and accepting **constructive feedback**. +6. Committing to **repairing harm** when it occurs. +7. Behaving in other ways that promote and sustain the **well-being of our community**. -## Our Responsibilities +## Restricted Behaviors -Project maintainers are responsible for clarifying the standards of acceptable -behavior and are expected to take appropriate and fair corrective action in -response to any instances of unacceptable behavior. +We agree to restrict the following behaviors in our community. Instances, threats, and promotion of these behaviors are violations of this Code of Conduct. -Project maintainers 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, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, -threatening, offensive, or harmful. +1. **Harassment.** Violating explicitly expressed boundaries or engaging in unnecessary personal attention after any clear request to stop. +2. **Character attacks.** Making insulting, demeaning, or pejorative comments directed at a community member or group of people. +3. **Stereotyping or discrimination.** Characterizing anyone’s personality or behavior on the basis of immutable identities or traits. +4. **Sexualization.** Behaving in a way that would generally be considered inappropriately intimate in the context or purpose of the community. +5. **Violating confidentiality**. Sharing or acting on someone's personal or private information without their permission. +6. **Endangerment.** Causing, encouraging, or threatening violence or other harm toward any person or group. +7. Behaving in other ways that **threaten the well-being** of our community. -## Scope +### Other Restrictions + +1. **Misleading identity.** Impersonating someone else for any reason, or pretending to be someone else to evade enforcement actions. +2. **Failing to credit sources.** Not properly crediting the sources of content you contribute. +3. **Promotional materials**. Sharing marketing or other commercial content in a way that is outside the norms of the community. +4. **Irresponsible communication.** Failing to responsibly present content which includes, links or describes any other restricted behaviors. + +## Reporting an Issue + +Tensions can occur between community members even when they are trying their best to collaborate. Not every conflict represents a code of conduct violation, and this Code of Conduct reinforces encouraged behaviors and norms that can help avoid conflicts and minimize harm. + +When an incident does occur, it is important to report it promptly. To report a possible violation, **[NOTE: describe your means of reporting here.]** + +Community Moderators take reports of violations seriously and will make every effort to respond in a timely manner. They will investigate all reports of code of conduct violations, reviewing messages, logs, and recordings, or interviewing witnesses and other participants. Community Moderators will keep investigation and enforcement actions as transparent as possible while prioritizing safety and confidentiality. In order to honor these values, enforcement actions are carried out in private with the involved parties, but communicating to the whole community may be part of a mutually agreed upon resolution. -This Code of Conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. Examples of -representing a project or community include using an official project e-mail -address, posting via an official social media account, or acting as an appointed -representative at an online or offline event. Representation of a project may be -further defined and clarified by project maintainers. +## Addressing and Repairing Harm -## Enforcement +**[NOTE: The remedies and repairs outlined below are suggestions based on best practices in code of conduct enforcement. If your community has its own established enforcement process, be sure to edit this section to describe your own policies.]** -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at veganstraightedge@gmail.com. All -complaints will be reviewed and investigated and will result in a response that -is deemed necessary and appropriate to the circumstances. The project team is -obligated to maintain confidentiality with regard to the reporter of an incident. -Further details of specific enforcement policies may be posted separately. +If an investigation by the Community Moderators finds that this Code of Conduct has been violated, the following enforcement ladder may be used to determine how best to repair harm, based on the incident's impact on the individuals involved and the community as a whole. Depending on the severity of a violation, lower rungs on the ladder may be skipped. -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. +1) Warning + 1) Event: A violation involving a single incident or series of incidents. + 2) Consequence: A private, written warning from the Community Moderators. + 3) Repair: Examples of repair include a private written apology, acknowledgement of responsibility, and seeking clarification on expectations. +2) Temporarily Limited Activities + 1) Event: A repeated incidence of a violation that previously resulted in a warning, or the first incidence of a more serious violation. + 2) Consequence: A private, written warning with a time-limited cooldown period designed to underscore the seriousness of the situation and give the community members involved time to process the incident. The cooldown period may be limited to particular communication channels or interactions with particular community members. + 3) Repair: Examples of repair may include making an apology, using the cooldown period to reflect on actions and impact, and being thoughtful about re-entering community spaces after the period is over. +3) Temporary Suspension + 1) Event: A pattern of repeated violation which the Community Moderators have tried to address with warnings, or a single serious violation. + 2) Consequence: A private written warning with conditions for return from suspension. In general, temporary suspensions give the person being suspended time to reflect upon their behavior and possible corrective actions. + 3) Repair: Examples of repair include respecting the spirit of the suspension, meeting the specified conditions for return, and being thoughtful about how to reintegrate with the community when the suspension is lifted. +4) Permanent Ban + 1) Event: A pattern of repeated code of conduct violations that other steps on the ladder have failed to resolve, or a violation so serious that the Community Moderators determine there is no way to keep the community safe with this person as a member. + 2) Consequence: Access to all community spaces, tools, and communication channels is removed. In general, permanent bans should be rarely used, should have strong reasoning behind them, and should only be resorted to if working through other remedies has failed to change the behavior. + 3) Repair: There is no possible repair in cases of this severity. + +This enforcement ladder is intended as a guideline. It does not limit the ability of Community Managers to use their discretion and judgment, in keeping with the best interests of our community. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public or other spaces. Examples of representing our community include using an official email address, posting via an official social media account, or acting as an appointed representative at an online or offline event. ## Attribution -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at [http://contributor-covenant.org/version/1/4][version] +This Code of Conduct is adapted from the Contributor Covenant, version 3.0, permanently available at [https://www.contributor-covenant.org/version/3/0/](https://www.contributor-covenant.org/version/3/0/). + +Contributor Covenant is stewarded by the Organization for Ethical Source and licensed under CC BY-SA 4.0. To view a copy of this license, visit [https://creativecommons.org/licenses/by-sa/4.0/](https://creativecommons.org/licenses/by-sa/4.0/) -[homepage]: http://contributor-covenant.org -[version]: http://contributor-covenant.org/version/1/4/ +For answers to common questions about Contributor Covenant, see the FAQ at [https://www.contributor-covenant.org/faq](https://www.contributor-covenant.org/faq). Translations are provided at [https://www.contributor-covenant.org/translations](https://www.contributor-covenant.org/translations). Additional enforcement and community guideline resources can be found at [https://www.contributor-covenant.org/resources](https://www.contributor-covenant.org/resources). The enforcement ladder was inspired by the work of [Mozilla’s code of conduct team](https://github.com/mozilla/inclusion). diff --git a/Gemfile b/Gemfile index 1e59be6..18b0038 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,9 @@ source 'https://rubygems.org' -ruby '3.2.2' + +ruby file: '.ruby-version' # app server -gem 'rails', '~> 5.2.0' +gem 'rails' # database gem 'pg' @@ -10,50 +11,25 @@ gem 'pg' # webserver gem 'puma' -# webserver -gem 'microformats', '~> 4.0.7' - -# assets -gem 'autoprefixer-rails' -gem 'bootstrap' -gem 'jquery-rails' -gem 'sass-rails' -gem 'uglifier' - -# For codestyle guide and linting -gem 'rubocop', require: false -gem 'rubocop-rspec' +# parser +gem 'microformats' # dev and testing group :development, :test do - gem 'byebug', platform: :mri - gem 'factory_bot_rails' - gem 'guard-rspec' - gem 'nokogiri' + gem 'brakeman', require: false + gem 'erb_lint', require: false + gem 'capybara' gem 'rails-controller-testing' gem 'rspec-rails' - gem 'simplecov', require: false - gem 'spring-commands-rspec' -end - -# dev -group :development do - gem 'listen', '~> 3.1.5' - gem 'spring' - gem 'spring-watcher-listen', '~> 2.0.0' - gem 'web-console' - - # For measuring page/code performance - gem 'rack-mini-profiler' - - # For memory profiling - gem 'memory_profiler' - - # For call-stack profiling flamegraphs - gem 'fast_stack' - gem 'flamegraph' - gem 'stackprof' + gem 'selenium-webdriver' + + # For codestyle guide and linting + gem 'rubocop', require: false + gem 'rubocop-capybara', require: false + gem 'rubocop-rails', require: false + gem 'rubocop-rspec', require: false + gem 'rubocop-rspec_rails', require: false end # windows dev -gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] +gem 'tzinfo-data', platforms: %i[windows jruby] diff --git a/Gemfile.lock b/Gemfile.lock index b825237..65afff2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,294 +1,351 @@ GEM remote: https://rubygems.org/ specs: - actioncable (5.2.0) - actionpack (= 5.2.0) + actioncable (8.0.2) + actionpack (= 8.0.2) + activesupport (= 8.0.2) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.0) - actionpack (= 5.2.0) - actionview (= 5.2.0) - activejob (= 5.2.0) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (5.2.0) - actionview (= 5.2.0) - activesupport (= 5.2.0) - rack (~> 2.0) + zeitwerk (~> 2.6) + actionmailbox (8.0.2) + actionpack (= 8.0.2) + activejob (= 8.0.2) + activerecord (= 8.0.2) + activestorage (= 8.0.2) + activesupport (= 8.0.2) + mail (>= 2.8.0) + actionmailer (8.0.2) + actionpack (= 8.0.2) + actionview (= 8.0.2) + activejob (= 8.0.2) + activesupport (= 8.0.2) + mail (>= 2.8.0) + rails-dom-testing (~> 2.2) + actionpack (8.0.2) + actionview (= 8.0.2) + activesupport (= 8.0.2) + nokogiri (>= 1.8.5) + rack (>= 2.2.4) + rack-session (>= 1.0.1) rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.0) - activesupport (= 5.2.0) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + useragent (~> 0.16) + actiontext (8.0.2) + actionpack (= 8.0.2) + activerecord (= 8.0.2) + activestorage (= 8.0.2) + activesupport (= 8.0.2) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (8.0.2) + activesupport (= 8.0.2) builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.0) - activesupport (= 5.2.0) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (8.0.2) + activesupport (= 8.0.2) globalid (>= 0.3.6) - activemodel (5.2.0) - activesupport (= 5.2.0) - activerecord (5.2.0) - activemodel (= 5.2.0) - activesupport (= 5.2.0) - arel (>= 9.0) - activestorage (5.2.0) - actionpack (= 5.2.0) - activerecord (= 5.2.0) - marcel (~> 0.3.1) - activesupport (5.2.0) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - arel (9.0.0) - ast (2.4.0) - autoprefixer-rails (9.1.0) - execjs - bindex (0.5.0) - bootstrap (4.1.3) - autoprefixer-rails (>= 6.0.3) - popper_js (>= 1.12.9, < 2) - sass (>= 3.5.2) - builder (3.2.3) - byebug (10.0.2) - coderay (1.1.2) - concurrent-ruby (1.0.5) - crass (1.0.4) - diff-lcs (1.3) - docile (1.3.1) - erubi (1.7.1) - execjs (2.7.0) - factory_bot (4.10.0) - activesupport (>= 3.0.0) - factory_bot_rails (4.10.0) - factory_bot (~> 4.10.0) - railties (>= 3.0.0) - fast_stack (0.2.0) - ffi (1.9.25) - flamegraph (0.9.5) - formatador (0.2.5) - globalid (0.4.1) - activesupport (>= 4.2.0) - guard (2.14.2) - formatador (>= 0.2.4) - listen (>= 2.7, < 4.0) - lumberjack (>= 1.0.12, < 2.0) - nenv (~> 0.1) - notiffany (~> 0.0) - pry (>= 0.9.12) - shellany (~> 0.0) - thor (>= 0.18.1) - guard-compat (1.2.1) - guard-rspec (4.7.3) - guard (~> 2.1) - guard-compat (~> 1.1) - rspec (>= 2.99.0, < 4.0) - i18n (1.0.1) + activemodel (8.0.2) + activesupport (= 8.0.2) + activerecord (8.0.2) + activemodel (= 8.0.2) + activesupport (= 8.0.2) + timeout (>= 0.4.0) + activestorage (8.0.2) + actionpack (= 8.0.2) + activejob (= 8.0.2) + activerecord (= 8.0.2) + activesupport (= 8.0.2) + marcel (~> 1.0) + activesupport (8.0.2) + base64 + benchmark (>= 0.3) + bigdecimal + concurrent-ruby (~> 1.0, >= 1.3.1) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + logger (>= 1.4.2) + minitest (>= 5.1) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + uri (>= 0.13.1) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + ast (2.4.3) + base64 (0.3.0) + benchmark (0.4.1) + better_html (2.1.1) + actionview (>= 6.0) + activesupport (>= 6.0) + ast (~> 2.0) + erubi (~> 1.4) + parser (>= 2.4) + smart_properties + bigdecimal (3.2.2) + brakeman (7.1.0) + racc + builder (3.3.0) + capybara (3.40.0) + addressable + matrix + mini_mime (>= 0.1.3) + nokogiri (~> 1.11) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (>= 1.5, < 3.0) + xpath (~> 3.2) + concurrent-ruby (1.3.5) + connection_pool (2.5.3) + crass (1.0.6) + date (3.4.1) + diff-lcs (1.6.2) + drb (2.2.3) + erb (5.0.2) + erb_lint (0.9.0) + activesupport + better_html (>= 2.0.1) + parser (>= 2.7.1.4) + rainbow + rubocop (>= 1) + smart_properties + erubi (1.13.1) + globalid (1.2.1) + activesupport (>= 6.1) + i18n (1.14.7) concurrent-ruby (~> 1.0) - jaro_winkler (1.5.1) - jquery-rails (4.3.3) - rails-dom-testing (>= 1, < 3) - railties (>= 4.2.0) - thor (>= 0.14, < 2.0) - json (2.1.0) - listen (3.1.5) - rb-fsevent (~> 0.9, >= 0.9.4) - rb-inotify (~> 0.9, >= 0.9.7) - ruby_dep (~> 1.2) - loofah (2.2.2) + io-console (0.8.1) + irb (1.15.2) + pp (>= 0.6.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + json (2.13.2) + language_server-protocol (3.17.0.5) + lint_roller (1.1.0) + logger (1.7.0) + loofah (2.24.1) crass (~> 1.0.2) - nokogiri (>= 1.5.9) - lumberjack (1.0.13) - mail (2.7.0) + nokogiri (>= 1.12.0) + mail (2.8.1) mini_mime (>= 0.1.1) - marcel (0.3.2) - mimemagic (~> 0.3.2) - memory_profiler (0.9.11) - method_source (0.9.0) - microformats (4.0.7) + net-imap + net-pop + net-smtp + marcel (1.0.4) + matrix (0.4.3) + microformats (4.5.0) json nokogiri - mimemagic (0.3.10) - nokogiri (~> 1) - rake - mini_mime (1.0.0) - mini_portile2 (2.3.0) - minitest (5.11.3) - nenv (0.3.0) - nio4r (2.3.1) - nokogiri (1.8.4) - mini_portile2 (~> 2.3.0) - notiffany (0.1.1) - nenv (~> 0.1) - shellany (~> 0.0) - parallel (1.12.1) - parser (2.5.1.2) - ast (~> 2.4.0) - pg (1.0.0) - popper_js (1.14.3) - powerpack (0.1.2) - pry (0.11.3) - coderay (~> 1.1.0) - method_source (~> 0.9.0) - puma (3.12.0) - rack (2.0.5) - rack-mini-profiler (1.0.0) - rack (>= 1.2.0) - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (5.2.0) - actioncable (= 5.2.0) - actionmailer (= 5.2.0) - actionpack (= 5.2.0) - actionview (= 5.2.0) - activejob (= 5.2.0) - activemodel (= 5.2.0) - activerecord (= 5.2.0) - activestorage (= 5.2.0) - activesupport (= 5.2.0) - bundler (>= 1.3.0) - railties (= 5.2.0) - sprockets-rails (>= 2.0.0) - rails-controller-testing (1.0.2) - actionpack (~> 5.x, >= 5.0.1) - actionview (~> 5.x, >= 5.0.1) - activesupport (~> 5.x) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) + mini_mime (1.1.5) + minitest (5.25.5) + net-imap (0.5.9) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.5.1) + net-protocol + nio4r (2.7.4) + nokogiri (1.18.9-aarch64-linux-gnu) + racc (~> 1.4) + nokogiri (1.18.9-aarch64-linux-musl) + racc (~> 1.4) + nokogiri (1.18.9-arm-linux-gnu) + racc (~> 1.4) + nokogiri (1.18.9-arm-linux-musl) + racc (~> 1.4) + nokogiri (1.18.9-arm64-darwin) + racc (~> 1.4) + nokogiri (1.18.9-x86_64-darwin) + racc (~> 1.4) + nokogiri (1.18.9-x86_64-linux-gnu) + racc (~> 1.4) + nokogiri (1.18.9-x86_64-linux-musl) + racc (~> 1.4) + parallel (1.27.0) + parser (3.3.9.0) + ast (~> 2.4.1) + racc + pg (1.6.1) + pg (1.6.1-aarch64-linux) + pg (1.6.1-aarch64-linux-musl) + pg (1.6.1-arm64-darwin) + pg (1.6.1-x86_64-darwin) + pg (1.6.1-x86_64-linux) + pg (1.6.1-x86_64-linux-musl) + pp (0.6.2) + prettyprint + prettyprint (0.2.0) + prism (1.4.0) + psych (5.2.6) + date + stringio + public_suffix (6.0.2) + puma (6.6.1) + nio4r (~> 2.0) + racc (1.8.1) + rack (3.2.0) + rack-session (2.1.1) + base64 (>= 0.1.0) + rack (>= 3.0.0) + rack-test (2.2.0) + rack (>= 1.3) + rackup (2.2.1) + rack (>= 3) + rails (8.0.2) + actioncable (= 8.0.2) + actionmailbox (= 8.0.2) + actionmailer (= 8.0.2) + actionpack (= 8.0.2) + actiontext (= 8.0.2) + actionview (= 8.0.2) + activejob (= 8.0.2) + activemodel (= 8.0.2) + activerecord (= 8.0.2) + activestorage (= 8.0.2) + activesupport (= 8.0.2) + bundler (>= 1.15.0) + railties (= 8.0.2) + rails-controller-testing (1.0.5) + actionpack (>= 5.0.1.rc1) + actionview (>= 5.0.1.rc1) + activesupport (>= 5.0.1.rc1) + rails-dom-testing (2.3.0) + activesupport (>= 5.0.0) + minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.0.4) - loofah (~> 2.2, >= 2.2.2) - railties (5.2.0) - actionpack (= 5.2.0) - activesupport (= 5.2.0) - method_source - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rainbow (3.0.0) - rake (12.3.1) - rb-fsevent (0.10.3) - rb-inotify (0.9.10) - ffi (>= 0.5.0, < 2) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-core (3.8.0) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.0) + rails-html-sanitizer (1.6.2) + loofah (~> 2.21) + nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) + railties (8.0.2) + actionpack (= 8.0.2) + activesupport (= 8.0.2) + irb (~> 1.13) + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) + rainbow (3.1.1) + rake (13.3.0) + rdoc (6.14.2) + erb + psych (>= 4.0.0) + regexp_parser (2.11.1) + reline (0.6.2) + io-console (~> 0.5) + rexml (3.4.1) + rspec-core (3.13.5) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.5) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-mocks (3.8.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.5) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-rails (3.8.0) - actionpack (>= 3.0) - activesupport (>= 3.0) - railties (>= 3.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.0) - rubocop (0.58.2) - jaro_winkler (~> 1.5.1) + rspec-support (~> 3.13.0) + rspec-rails (8.0.1) + actionpack (>= 7.2) + activesupport (>= 7.2) + railties (>= 7.2) + rspec-core (~> 3.13) + rspec-expectations (~> 3.13) + rspec-mocks (~> 3.13) + rspec-support (~> 3.13) + rspec-support (3.13.4) + rubocop (1.79.2) + json (~> 2.3) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.1.0) parallel (~> 1.10) - parser (>= 2.5, != 2.5.1.1) - powerpack (~> 0.1) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.46.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.0, >= 1.0.1) - rubocop-rspec (1.27.0) - rubocop (>= 0.56.0) - ruby-progressbar (1.9.0) - ruby_dep (1.5.0) - sass (3.5.7) - sass-listen (~> 4.0.0) - sass-listen (4.0.0) - rb-fsevent (~> 0.9, >= 0.9.4) - rb-inotify (~> 0.9, >= 0.9.7) - sass-rails (5.0.7) - railties (>= 4.0.0, < 6) - sass (~> 3.1) - sprockets (>= 2.8, < 4.0) - sprockets-rails (>= 2.0, < 4.0) - tilt (>= 1.1, < 3) - shellany (0.0.1) - simplecov (0.16.1) - docile (~> 1.1) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) - spring (2.0.2) - activesupport (>= 4.2) - spring-commands-rspec (1.0.4) - spring (>= 0.9.1) - spring-watcher-listen (2.0.1) - listen (>= 2.7, < 4.0) - spring (>= 1.2, < 3.0) - sprockets (3.7.2) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.46.0) + parser (>= 3.3.7.2) + prism (~> 1.4) + rubocop-capybara (2.22.1) + lint_roller (~> 1.1) + rubocop (~> 1.72, >= 1.72.1) + rubocop-rails (2.32.0) + activesupport (>= 4.2.0) + lint_roller (~> 1.1) + rack (>= 1.1) + rubocop (>= 1.75.0, < 2.0) + rubocop-ast (>= 1.44.0, < 2.0) + rubocop-rspec (3.6.0) + lint_roller (~> 1.1) + rubocop (~> 1.72, >= 1.72.1) + rubocop-rspec_rails (2.31.0) + lint_roller (~> 1.1) + rubocop (~> 1.72, >= 1.72.1) + rubocop-rspec (~> 3.5) + ruby-progressbar (1.13.0) + rubyzip (2.4.1) + securerandom (0.4.1) + selenium-webdriver (4.34.0) + base64 (~> 0.2) + logger (~> 1.4) + rexml (~> 3.2, >= 3.2.5) + rubyzip (>= 1.2.2, < 3.0) + websocket (~> 1.0) + smart_properties (1.17.0) + stringio (3.1.7) + thor (1.4.0) + timeout (0.4.3) + tzinfo (2.0.6) concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.2.1) - actionpack (>= 4.0) - activesupport (>= 4.0) - sprockets (>= 3.0.0) - stackprof (0.2.12) - thor (0.20.0) - thread_safe (0.3.6) - tilt (2.0.8) - tzinfo (1.2.10) - thread_safe (~> 0.1) - uglifier (4.1.17) - execjs (>= 0.3.0, < 3) - unicode-display_width (1.4.0) - web-console (3.6.2) - actionview (>= 5.0) - activemodel (>= 5.0) - bindex (>= 0.4.0) - railties (>= 5.0) - websocket-driver (0.7.0) + unicode-display_width (3.1.4) + unicode-emoji (~> 4.0, >= 4.0.4) + unicode-emoji (4.0.4) + uri (1.0.3) + useragent (0.16.11) + websocket (1.2.11) + websocket-driver (0.8.0) + base64 websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.3) + websocket-extensions (0.1.5) + xpath (3.2.0) + nokogiri (~> 1.8) + zeitwerk (2.7.3) PLATFORMS - ruby + aarch64-linux + aarch64-linux-gnu + aarch64-linux-musl + arm-linux-gnu + arm-linux-musl + arm64-darwin + x86_64-darwin + x86_64-linux + x86_64-linux-gnu + x86_64-linux-musl DEPENDENCIES - autoprefixer-rails - bootstrap - byebug - factory_bot_rails - fast_stack - flamegraph - guard-rspec - jquery-rails - listen (~> 3.1.5) - memory_profiler - microformats (~> 4.0.7) - nokogiri + brakeman + capybara + erb_lint + microformats pg puma - rack-mini-profiler - rails (~> 5.2.0) + rails rails-controller-testing rspec-rails rubocop + rubocop-capybara + rubocop-rails rubocop-rspec - sass-rails - simplecov - spring - spring-commands-rspec - spring-watcher-listen (~> 2.0.0) - stackprof + rubocop-rspec_rails + selenium-webdriver tzinfo-data - uglifier - web-console RUBY VERSION - ruby 2.5.1p57 + ruby 3.4.5p51 BUNDLED WITH - 1.16.2 + 2.7.1 diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 61ad10d..e69de29 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -1,19 +0,0 @@ -@import "bootstrap"; - -form { - label { - font-weight: bold; - } - - textarea, - input[type=url], - input[type=text] { - font-family: "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; - } - - .form-control:disabled { - cursor: default; - background: #efefef; - color: black; - } -} diff --git a/app/controllers/microformats_controller.rb b/app/controllers/microformats_controller.rb index 3025fa6..fb8ac01 100644 --- a/app/controllers/microformats_controller.rb +++ b/app/controllers/microformats_controller.rb @@ -9,7 +9,7 @@ def show results[:debug] = { package: 'https://rubygems.org/gems/microformats', version: Microformats::VERSION, - note: [ + note: [ 'This output was generated from the microformats-ruby gem available at https://github.com/indieweb/microformats-ruby', 'Please file any issues with the parser at https://github.com/indieweb/microformats-rubygems/issues' ] @@ -17,7 +17,7 @@ def show render json: JSON.pretty_generate(results) else - redirect_to new_submission_path + redirect_to :root end end end diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index 63f82a2..7cdb458 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -1,10 +1,9 @@ class SubmissionsController < ApplicationController - before_action :set_submission, only: [:show, :edit, :update, :destroy] + before_action :set_submission, only: %i[show edit update destroy] + before_action :redirect_to_root, only: %i[index edit update destroy] # GET /submissions - def index - redirect_to new_submission_path - end + def index; end # GET /submissions/1 def show; end @@ -15,9 +14,7 @@ def new end # GET /submissions/1/edit - def edit - redirect_to new_submission_path - end + def edit; end # POST /submissions def create @@ -40,14 +37,10 @@ def create end # PATCH/PUT /submissions/1 - def update - redirect_to new_submission_path - end + def update; end # DELETE /submissions/1 - def destroy - redirect_to new_submission_path - end + def destroy; end private @@ -56,8 +49,12 @@ def set_submission @submission = Submission.find(params[:id]) end + def redirect_to_root + redirect_to :root + end + # Only allow a trusted parameter "white list" through. def submission_params - params.require(:submission).permit(:url, :html, :base_url, :save_html, :render_html_in_page) + params.expect submission: %i[url html base_url save_html render_html_in_page] end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..68b00c5 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,16 @@ module ApplicationHelper + # From: https://getbootstrap.com/docs/5.3/getting-started/download/#cdn-via-jsdelivr + BOOTSTRAP_VERSION = '5.3.7'.freeze + BOOTSTRAP_CSS_INTEGRITY = 'sha384-LN+7fdVzj6u52u30Kp6M/trliBMCMKTyK833zpbD+pXdCLuTusPj697FH4R/5mcr'.freeze + + def bootstrap_stylesheet_link_tag + stylesheet_link_tag "https://cdn.jsdelivr.net/npm/bootstrap@#{BOOTSTRAP_VERSION}/dist/css/bootstrap.min.css", + media: 'all', + integrity: BOOTSTRAP_CSS_INTEGRITY, + crossorigin: 'anonymous' + end + + def on_results_page? + action_name != 'new' + end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e4f2361..19cf2f2 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -3,17 +3,28 @@ - Ruby Microformats Parser <%= csrf_meta_tags %> - - <%= stylesheet_link_tag "application", media: "all" %> - <%= javascript_include_tag "application" %> + <%= bootstrap_stylesheet_link_tag %> + + +
- <% if notice.present? %>
diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb index cbd34d2..3aac900 100644 --- a/app/views/layouts/mailer.html.erb +++ b/app/views/layouts/mailer.html.erb @@ -1,7 +1,7 @@ - + diff --git a/app/views/submissions/_form.html.erb b/app/views/submissions/_form.html.erb deleted file mode 100644 index fca3d79..0000000 --- a/app/views/submissions/_form.html.erb +++ /dev/null @@ -1,55 +0,0 @@ -<%= form_with model: submission, local: true, class: "mb-5" do |form| %> - <% if submission.errors.any? %> -
-

<%= pluralize(submission.errors.count, "error") %> prohibited this submission from being saved:

- - -
- <% end %> - -
- <%= form.label :html, "HTML" %> - <%= form.text_area :html, id: :submission_html, class: "form-control form-control-lg", rows: 6, disabled: submission.id.present? %> -
- -
- <%= form.label :base_url, "Base URL" %> - <%= form.url_field :base_url, id: :submission_base_url, class: "form-control form-control-lg", disabled: submission.id.present? %> -
- - <% unless action_name == "new" %> -
- <%= form.label :json, "JSON" %> - <%= form.text_area :json, id: :submission_json, class: "form-control form-control-lg", rows: 10, disabled: submission.id.present? %> -
- <% end %> - - <% if submission.id.blank? %> -
- -
- -
- -
- -
- <%= form.submit "Parse", class: "btn btn-lg btn-success" %> -
- <% end %> - -<% end %> diff --git a/app/views/submissions/_submission.html.erb b/app/views/submissions/_submission.html.erb new file mode 100644 index 0000000..92ff27c --- /dev/null +++ b/app/views/submissions/_submission.html.erb @@ -0,0 +1,60 @@ +<%= form_with model: submission, class: 'mb-5' do |form| %> + <% if submission.errors.any? %> +
+

<%= pluralize(submission.errors.count, 'error') %> prohibited this submission from being saved:

+ + +
+ <% end %> + +
+ <%= form.label :html, :HTML %> + <%= form.text_area :html, + id: :submission_html, + class: 'form-control form-control-lg font-monospace', + rows: 6, + disabled: on_results_page?, + readonly: on_results_page? %> +
+ +
+ <%= form.label :base_url, 'Base URL' %> + <%= form.url_field :base_url, + id: :submission_base_url, + class: 'form-control form-control-lg font-monospace', + disabled: on_results_page?, + readonly: on_results_page? %> +
+ + <% if on_results_page? %> +
+ <%= form.label :json, :JSON %> + <%= form.text_area :json, + id: :submission_json, + class: 'form-control form-control-lg font-monospace', + rows: 10, + disabled: true, + readonly: true %> +
+ <% end %> + + <% unless on_results_page? %> +
+
+ <%= form.check_box :save_html, id: :submission_save_html, class: 'form-check-input' %> + <%= form.label :save_html, 'Save HTML?', for: :submission_save_html %> +
+ +
+ <%= form.check_box :render_html_in_page, id: :submission_render_html_in_page, class: 'form-check-input' %> + <%= form.label :render_html_in_page, 'Render HTML in Page?', for: :submission_render_html_in_page %> +
+
+ + <%= form.submit 'Parse', class: 'btn btn-lg btn-success' %> + <% end %> +<% end %> diff --git a/app/views/submissions/new.html.erb b/app/views/submissions/new.html.erb index 6d77bad..0a5d70e 100644 --- a/app/views/submissions/new.html.erb +++ b/app/views/submissions/new.html.erb @@ -1,16 +1,14 @@ -<%= form_with url: "/microformats", method: "get", local: true do |form| %> -
- <%= form.label :url, "Enter a URL" %> - <%= form.url_field :url, id: :submission_url, placeholder: "https://example.com/person.html", class: "form-control form-control-lg" %> +<%= form_with url: :microformats, method: :get, class: 'mb-5', enforce_utf8: false do |form| %> +
+ <%= form.label :url, 'Enter a URL' %> + <%= form.url_field :url, + id: :submission_url, + placeholder: 'https://example.com/person.html', + class: 'form-control form-control-lg font-monospace' %>
-
- -
+ <%= form.submit :Parse, class: 'btn btn-lg btn-success', name: nil %> <% end %> - -

OR parse just a snippet of HTML

- - -<%= render "form", submission: @submission %> +

OR parse just a snippet of HTML

+<%= render @submission %> diff --git a/app/views/submissions/show.html.erb b/app/views/submissions/show.html.erb index 2d955fe..54d3a6b 100644 --- a/app/views/submissions/show.html.erb +++ b/app/views/submissions/show.html.erb @@ -1,13 +1,13 @@ -<%= render "form", submission: @submission %> +<%= render @submission %> <% if @submission.render_html_in_page? %> -
-
- Rendered HTML -
+
+
+ Rendered HTML +
-
- <%= simple_format @submission.html %> +
+ <%= simple_format @submission.html %> +
-
<% end %> diff --git a/bin/brakeman b/bin/brakeman new file mode 100755 index 0000000..a2eeb02 --- /dev/null +++ b/bin/brakeman @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'brakeman' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("brakeman", "brakeman") diff --git a/bin/bundle b/bin/bundle index 66e9889..f19acf5 100755 --- a/bin/bundle +++ b/bin/bundle @@ -1,3 +1,3 @@ #!/usr/bin/env ruby -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) load Gem.bin_path('bundler', 'bundle') diff --git a/bin/dev b/bin/dev new file mode 100755 index 0000000..5f91c20 --- /dev/null +++ b/bin/dev @@ -0,0 +1,2 @@ +#!/usr/bin/env ruby +exec "./bin/rails", "server", *ARGV diff --git a/bin/erb_lint b/bin/erb_lint new file mode 100755 index 0000000..7477113 --- /dev/null +++ b/bin/erb_lint @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'erb_lint' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("erb_lint", "erb_lint") diff --git a/bin/erblint b/bin/erblint new file mode 100755 index 0000000..e17579f --- /dev/null +++ b/bin/erblint @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'erblint' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("erb_lint", "erblint") diff --git a/bin/rails b/bin/rails index 5badb2f..efc0377 100755 --- a/bin/rails +++ b/bin/rails @@ -1,9 +1,4 @@ #!/usr/bin/env ruby -begin - load File.expand_path('../spring', __FILE__) -rescue LoadError => e - raise unless e.message.include?('spring') -end -APP_PATH = File.expand_path('../config/application', __dir__) -require_relative '../config/boot' -require 'rails/commands' +APP_PATH = File.expand_path("../config/application", __dir__) +require_relative "../config/boot" +require "rails/commands" diff --git a/bin/rake b/bin/rake index d87d5f5..4fbf10b 100755 --- a/bin/rake +++ b/bin/rake @@ -1,9 +1,4 @@ #!/usr/bin/env ruby -begin - load File.expand_path('../spring', __FILE__) -rescue LoadError => e - raise unless e.message.include?('spring') -end -require_relative '../config/boot' -require 'rake' +require_relative "../config/boot" +require "rake" Rake.application.run diff --git a/bin/rspec b/bin/rspec new file mode 100755 index 0000000..d72fadf --- /dev/null +++ b/bin/rspec @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require 'bundler/setup' +load Gem.bin_path('rspec-core', 'rspec') diff --git a/bin/rubocop b/bin/rubocop new file mode 100755 index 0000000..40330c0 --- /dev/null +++ b/bin/rubocop @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby +require "rubygems" +require "bundler/setup" + +# explicit rubocop config increases performance slightly while avoiding config confusion. +ARGV.unshift("--config", File.expand_path("../.rubocop.yml", __dir__)) + +load Gem.bin_path("rubocop", "rubocop") diff --git a/bin/setup b/bin/setup index 78c4e86..be3db3c 100755 --- a/bin/setup +++ b/bin/setup @@ -1,38 +1,34 @@ #!/usr/bin/env ruby -require 'pathname' -require 'fileutils' -include FileUtils +require "fileutils" -# path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) +APP_ROOT = File.expand_path("..", __dir__) def system!(*args) - system(*args) || abort("\n== Command #{args} failed ==") + system(*args, exception: true) end -chdir APP_ROOT do - # This script is a starting point to setup your application. +FileUtils.chdir APP_ROOT do + # This script is a way to set up or update your development environment automatically. + # This script is idempotent, so that you can run it at any time and get an expectable outcome. # Add necessary setup steps to this file. - puts '== Installing dependencies ==' - system! 'gem install bundler --conservative' - system('bundle check') || system!('bundle install') - - # Install JavaScript dependencies if using Yarn - # system('bin/yarn') - + puts "== Installing dependencies ==" + system("bundle check") || system!("bundle install") # puts "\n== Copying sample files ==" - # unless File.exist?('config/database.yml') - # cp 'config/database.yml.sample', 'config/database.yml' + # unless File.exist?("config/database.yml") + # FileUtils.cp "config/database.yml.sample", "config/database.yml" # end puts "\n== Preparing database ==" - system! 'bin/rails db:setup' + system! "bin/rails db:prepare" puts "\n== Removing old logs and tempfiles ==" - system! 'bin/rails log:clear tmp:clear' + system! "bin/rails log:clear tmp:clear" - puts "\n== Restarting application server ==" - system! 'bin/rails restart' + unless ARGV.include?("--skip-server") + puts "\n== Starting development server ==" + STDOUT.flush # flush the output before exec(2) so that it displays + exec "bin/dev" + end end diff --git a/bin/spring b/bin/spring deleted file mode 100755 index fb2ec2e..0000000 --- a/bin/spring +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby - -# This file loads spring without using Bundler, in order to be fast. -# It gets overwritten when you run the `spring binstub` command. - -unless defined?(Spring) - require 'rubygems' - require 'bundler' - - lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) - spring = lockfile.specs.detect { |spec| spec.name == "spring" } - if spring - Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path - gem 'spring', spring.version - require 'spring/binstub' - end -end diff --git a/bin/yarn b/bin/yarn deleted file mode 100755 index c2bacef..0000000 --- a/bin/yarn +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env ruby -VENDOR_PATH = File.expand_path('..', __dir__) -Dir.chdir(VENDOR_PATH) do - begin - exec "yarnpkg #{ARGV.join(" ")}" - rescue Errno::ENOENT - $stderr.puts "Yarn executable was not detected in the system." - $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" - exit 1 - end -end diff --git a/config/application.rb b/config/application.rb index fa76920..6d275bf 100644 --- a/config/application.rb +++ b/config/application.rb @@ -9,10 +9,19 @@ module MicroformatsRubyParserWebsite class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 5.1 + config.load_defaults 8.0 - # Settings in config/environments/* take precedence over those specified here. - # Application configuration should go into files in config/initializers - # -- all .rb files in that directory are automatically loaded. + # Please, add to the `ignore` list any other `lib` subdirectories that do + # not contain `.rb` files, or that should not be reloaded or eager loaded. + # Common ones are `templates`, `generators`, or `middleware`, for example. + config.autoload_lib(ignore: %w[assets tasks]) + + # Configuration for the application, engines, and railties goes here. + # + # These settings can be overridden in specific environments using the files + # in config/environments, which are processed later. + # + # config.time_zone = "Central Time (US & Canada)" + # config.eager_load_paths << Rails.root.join("extras") end end diff --git a/config/environments/development.rb b/config/environments/development.rb index 5e3eb42..064bebc 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,10 +1,10 @@ +require 'active_support/core_ext/integer/time' + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - # In the development environment your application's code is reloaded on - # every request. This slows down response time but is perfect for development - # since you don't have to restart the web server when you make code changes. - config.cache_classes = false + # Make code changes take effect immediately without server restart. + config.enable_reloading = true # Do not eager load code on boot. config.eager_load = false @@ -12,43 +12,61 @@ # Show full error reports. config.consider_all_requests_local = true - # Enable/disable caching. By default caching is disabled. - if Rails.root.join('tmp', 'caching-dev.txt').exist? - config.action_controller.perform_caching = true + # Enable server timing. + config.server_timing = true - config.cache_store = :memory_store - config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}" - } + # Enable/disable Action Controller caching. By default Action Controller caching is disabled. + # Run rails dev:cache to toggle Action Controller caching. + if Rails.root.join('tmp/caching-dev.txt').exist? + config.action_controller.perform_caching = true + config.action_controller.enable_fragment_cache_logging = true + config.public_file_server.headers = { 'cache-control' => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false - - config.cache_store = :null_store end + # Change to :null_store to avoid any caching. + config.cache_store = :memory_store + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false + # Make template changes take effect immediately. config.action_mailer.perform_caching = false + # Set localhost to be used by links generated in mailer templates. + config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } + # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load - # Debug mode disables concatenation and preprocessing of assets. - # This option may cause significant delays in view rendering with a large - # number of complex assets. - config.assets.debug = true + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + + # Append comments with runtime information tags to SQL queries in logs. + config.active_record.query_log_tags_enabled = true + + # Highlight code that enqueued background job in logs. + config.active_job.verbose_enqueue_logs = true + + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + config.action_view.annotate_rendered_view_with_filenames = true - # Suppress logger output for asset requests. - config.assets.quiet = true + # Uncomment if you wish to allow Action Cable access from any origin. + # config.action_cable.disable_request_forgery_protection = true - # Raises error for missing translations - # config.action_view.raise_on_missing_translations = true + # Raise error when a before_action's only/except options reference missing actions. + config.action_controller.raise_on_missing_callback_actions = true - # Use an evented file watcher to asynchronously detect changes in source code, - # routes, locales, etc. This feature depends on the listen gem. - config.file_watcher = ActiveSupport::EventedFileUpdateChecker + # Apply autocorrection by RuboCop to files generated by `bin/rails generate`. + # config.generators.apply_rubocop_autocorrect_after_generate! end diff --git a/config/environments/production.rb b/config/environments/production.rb index 779d18f..6c41245 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,91 +1,89 @@ +require 'active_support/core_ext/integer/time' + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. - config.cache_classes = true + config.enable_reloading = false - # Eager load code on boot. This eager loads most of Rails and - # your application in memory, allowing both threaded web servers - # and those relying on copy on write to perform better. - # Rake tasks automatically ignore this option for performance. + # Eager load code on boot for better performance and memory savings (ignored by Rake tasks). config.eager_load = true - # Full error reports are disabled and caching is turned on. - config.consider_all_requests_local = false - config.action_controller.perform_caching = true - - # Attempt to read encrypted secrets from `config/secrets.yml.enc`. - # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or - # `config/secrets.yml.key`. - config.read_encrypted_secrets = true - - # Disable serving static files from the `/public` folder by default since - # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + # Full error reports are disabled. + config.consider_all_requests_local = false - # Compress JavaScripts and CSS. - config.assets.js_compressor = :uglifier - # config.assets.css_compressor = :sass - - # Do not fallback to assets pipeline if a precompiled asset is missed. - config.assets.compile = false + # Turn on fragment caching in view templates. + config.action_controller.perform_caching = true - # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + # Cache assets for far-future expiry since they are all digest stamped. + config.public_file_server.headers = { 'cache-control' => "public, max-age=#{1.year.to_i}" } # Enable serving of images, stylesheets, and JavaScripts from an asset server. - # config.action_controller.asset_host = 'http://assets.example.com' + # config.asset_host = "http://assets.example.com" - # Specifies the header that your server uses for sending files. - # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache - # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local - # Mount Action Cable outside main process or domain - # config.action_cable.mount_path = nil - # config.action_cable.url = 'wss://example.com/cable' - # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + # Assume all access to the app is happening through a SSL-terminating reverse proxy. + config.assume_ssl = true # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - # config.force_ssl = true + config.force_ssl = true - # Use the lowest log level to ensure availability of diagnostic information - # when problems arise. - config.log_level = :debug + # Skip http-to-https redirect for the default health check endpoint. + # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } - # Prepend all log lines with the following tags. + # Log to STDOUT with the current request id as a default log tag. config.log_tags = [:request_id] + config.logger = ActiveSupport::TaggedLogging.logger($stdout) + + # Change to "debug" to log everything (including potentially personally-identifiable information!) + config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info') + + # Prevent health checks from clogging up the logs. + config.silence_healthcheck_path = '/up' - # Use a different cache store in production. + # Don't log any deprecations. + config.active_support.report_deprecations = false + + # Replace the default in-process memory cache store with a durable alternative. # config.cache_store = :mem_cache_store - # Use a real queuing backend for Active Job (and separate queues per environment) - # config.active_job.queue_adapter = :resque - # config.active_job.queue_name_prefix = "microformats-ruby-parser_#{Rails.env}" - config.action_mailer.perform_caching = false + # Replace the default in-process and non-durable queuing backend for Active Job. + # config.active_job.queue_adapter = :resque # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false + # Set host to be used by links generated in mailer templates. + config.action_mailer.default_url_options = { host: 'example.com' } + + # Specify outgoing SMTP server. Remember to add smtp/* credentials via rails credentials:edit. + # config.action_mailer.smtp_settings = { + # user_name: Rails.application.credentials.dig(:smtp, :user_name), + # password: Rails.application.credentials.dig(:smtp, :password), + # address: "smtp.example.com", + # port: 587, + # authentication: :plain + # } + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true - # Send deprecation notices to registered listeners. - config.active_support.deprecation = :notify - - # Use default logging formatter so that PID and timestamp are not suppressed. - config.log_formatter = ::Logger::Formatter.new - - # Use a different logger for distributed setups. - # require 'syslog/logger' - # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') - - if ENV['RAILS_LOG_TO_STDOUT'].present? - logger = ActiveSupport::Logger.new(STDOUT) - logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) - end - # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false + + # Only use :id for inspections in production. + config.active_record.attributes_for_inspect = [:id] + + # Enable DNS rebinding protection and other `Host` header attacks. + # config.hosts = [ + # "example.com", # Allow requests from example.com + # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com` + # ] + # + # Skip DNS rebinding protection for the default health check endpoint. + # config.host_authorization = { exclude: ->(request) { request.path == "/up" } } end diff --git a/config/environments/test.rb b/config/environments/test.rb index 8e5cbde..7a026c6 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,42 +1,53 @@ +# The test environment is used exclusively to run your application's +# test suite. You never need to work with it otherwise. Remember that +# your test database is "scratch space" for the test suite and is wiped +# and recreated between test runs. Don't rely on the data there! + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - # The test environment is used exclusively to run your application's - # test suite. You never need to work with it otherwise. Remember that - # your test database is "scratch space" for the test suite and is wiped - # and recreated between test runs. Don't rely on the data there! - config.cache_classes = true + # While tests run files are not watched, reloading is not necessary. + config.enable_reloading = false - # Do not eager load code on boot. This avoids loading your whole application - # just for the purpose of running a single test. If you are using a tool that - # preloads Rails for running tests, you may have to set it to true. - config.eager_load = false + # Eager loading loads your entire application. When running a single test locally, + # this is usually not necessary, and can slow down your test suite. However, it's + # recommended that you enable it in continuous integration systems to ensure eager + # loading is working properly before deploying your code. + config.eager_load = ENV['CI'].present? - # Configure public file server for tests with Cache-Control for performance. - config.public_file_server.enabled = true - config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}" - } + # Configure public file server for tests with cache-control for performance. + config.public_file_server.headers = { 'cache-control' => 'public, max-age=3600' } - # Show full error reports and disable caching. - config.consider_all_requests_local = true - config.action_controller.perform_caching = false + # Show full error reports. + config.consider_all_requests_local = true + config.cache_store = :null_store - # Raise exceptions instead of rendering exception templates. - config.action_dispatch.show_exceptions = false + # Render exception templates for rescuable exceptions and raise for other exceptions. + config.action_dispatch.show_exceptions = :rescuable # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false - config.action_mailer.perform_caching = false + + # Store uploaded files on the local file system in a temporary directory. + config.active_storage.service = :test # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + # Set host to be used by links generated in mailer templates. + config.action_mailer.default_url_options = { host: 'example.com' } + # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr - # Raises error for missing translations - # config.action_view.raise_on_missing_translations = true + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true + + # Raise error when a before_action's only/except options reference missing actions. + config.action_controller.raise_on_missing_callback_actions = true end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb deleted file mode 100644 index 4b828e8..0000000 --- a/config/initializers/assets.rb +++ /dev/null @@ -1,14 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Version of your assets, change this if you want to expire all your assets. -Rails.application.config.assets.version = '1.0' - -# Add additional assets to the asset load path. -# Rails.application.config.assets.paths << Emoji.images_path -# Add Yarn node_modules folder to the asset load path. -Rails.application.config.assets.paths << Rails.root.join('node_modules') - -# Precompile additional assets. -# application.js, application.css, and all non-JS/CSS in the app/assets -# folder are already added. -# Rails.application.config.assets.precompile += %w( admin.js admin.css ) diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb new file mode 100644 index 0000000..b3076b3 --- /dev/null +++ b/config/initializers/content_security_policy.rb @@ -0,0 +1,25 @@ +# Be sure to restart your server when you modify this file. + +# Define an application-wide content security policy. +# See the Securing Rails Applications Guide for more information: +# https://guides.rubyonrails.org/security.html#content-security-policy-header + +# Rails.application.configure do +# config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end +# +# # Generate session nonces for permitted importmap, inline scripts, and inline styles. +# config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } +# config.content_security_policy_nonce_directives = %w(script-src style-src) +# +# # Report violations without enforcing the policy. +# # config.content_security_policy_report_only = true +# end diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 4a994e1..f72dcdf 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,4 +1,8 @@ # Be sure to restart your server when you modify this file. -# Configure sensitive parameters which will be filtered from the log file. -Rails.application.config.filter_parameters += [:password] +# Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file. +# Use this to limit dissemination of sensitive information. +# See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. +Rails.application.config.filter_parameters += %i[ + passw email secret token _key crypt salt certificate otp ssn cvv cvc +] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index ac033bf..3860f65 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -4,13 +4,13 @@ # are locale specific, and you may define rules for as many different # locales as you wish. All of these examples are active by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.plural /^(ox)$/i, '\1en' -# inflect.singular /^(ox)en/i, '\1' -# inflect.irregular 'person', 'people' +# inflect.plural /^(ox)$/i, "\\1en" +# inflect.singular /^(ox)en/i, "\\1" +# inflect.irregular "person", "people" # inflect.uncountable %w( fish sheep ) # end # These inflection rules are supported but not enabled by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.acronym 'RESTful' +# inflect.acronym "RESTful" # end diff --git a/config/puma.rb b/config/puma.rb index ccda173..6899c5a 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,56 +1,41 @@ -# Puma can serve each request in a thread from an internal thread pool. -# The `threads` method setting takes two numbers: a minimum and maximum. -# Any libraries that use thread pools should be configured to match -# the maximum value specified for Puma. Default is set to 5 threads for minimum -# and maximum; this matches the default thread size of Active Record. +# This configuration file will be evaluated by Puma. The top-level methods that +# are invoked here are part of Puma's configuration DSL. For more information +# about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html. # -threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 } -threads threads_count, threads_count - -# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +# Puma starts a configurable number of processes (workers) and each process +# serves each request in a thread from an internal thread pool. # -port ENV.fetch('PORT') { 3000 } - -# Specifies the `environment` that Puma will run in. +# You can control the number of workers using ENV["WEB_CONCURRENCY"]. You +# should only set this value when you want to run 2 or more workers. The +# default is already 1. # -environment ENV.fetch('RAILS_ENV') { 'development' } - -# Specifies the number of `workers` to boot in clustered mode. -# Workers are forked webserver processes. If using threads and workers together -# the concurrency of the application would be max `threads` * `workers`. -# Workers do not work on JRuby or Windows (both of which do not support -# processes). +# The ideal number of threads per worker depends both on how much time the +# application spends waiting for IO operations and on how much you wish to +# prioritize throughput over latency. # -# workers ENV.fetch("WEB_CONCURRENCY") { 2 } - -# Use the `preload_app!` method when specifying a `workers` number. -# This directive tells Puma to first boot the application and load code -# before forking the application. This takes advantage of Copy On Write -# process behavior so workers use less memory. If you use this option -# you need to make sure to reconnect any threads in the `on_worker_boot` -# block. +# As a rule of thumb, increasing the number of threads will increase how much +# traffic a given process can handle (throughput), but due to CRuby's +# Global VM Lock (GVL) it has diminishing returns and will degrade the +# response time (latency) of the application. # -# preload_app! - -# If you are preloading your application and using Active Record, it's -# recommended that you close any connections to the database before workers -# are forked to prevent connection leakage. +# The default is set to 3 threads as it's deemed a decent compromise between +# throughput and latency for the average Rails application. # -# before_fork do -# ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord) -# end +# Any libraries that use a connection pool or another resource pool should +# be configured to provide at least as many connections as the number of +# threads. This includes Active Record's `pool` parameter in `database.yml`. +threads_count = ENV.fetch('RAILS_MAX_THREADS', 3) +threads threads_count, threads_count -# The code in the `on_worker_boot` will be called if you are using -# clustered mode by specifying a number of `workers`. After each worker -# process is booted, this block will be run. If you are using the `preload_app!` -# option, you will want to use this block to reconnect to any threads -# or connections that may have been created at application boot, as Ruby -# cannot share connections between processes. -# -# on_worker_boot do -# ActiveRecord::Base.establish_connection if defined?(ActiveRecord) -# end -# +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +port ENV.fetch('PORT', 3000) -# Allow puma to be restarted by `rails restart` command. +# Allow puma to be restarted by `bin/rails restart` command. plugin :tmp_restart + +# Run the Solid Queue supervisor inside of Puma for single-server deployments +plugin :solid_queue if ENV['SOLID_QUEUE_IN_PUMA'] + +# Specify the PID file. Defaults to tmp/pids/server.pid in development. +# In other environments, only set the PID file if requested. +pidfile ENV['PIDFILE'] if ENV['PIDFILE'] diff --git a/config/spring.rb b/config/spring.rb deleted file mode 100644 index 9fa7863..0000000 --- a/config/spring.rb +++ /dev/null @@ -1,6 +0,0 @@ -%w[ - .ruby-version - .rbenv-vars - tmp/restart.txt - tmp/caching-dev.txt -].each { |path| Spring.watch(path) } diff --git a/config/storage.yml b/config/storage.yml new file mode 100644 index 0000000..4942ab6 --- /dev/null +++ b/config/storage.yml @@ -0,0 +1,34 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +# Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) +# amazon: +# service: S3 +# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> +# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> +# region: us-east-1 +# bucket: your_own_bucket-<%= Rails.env %> + +# Remember not to checkin your GCS keyfile to a repository +# google: +# service: GCS +# project: your_project +# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> +# bucket: your_own_bucket-<%= Rails.env %> + +# Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) +# microsoft: +# service: AzureStorage +# storage_account_name: your_account_name +# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> +# container: your_container_name-<%= Rails.env %> + +# mirror: +# service: Mirror +# primary: local +# mirrors: [ amazon, google, microsoft ] diff --git a/db/migrate/20250809045033_add_service_name_to_active_storage_blobs.active_storage.rb b/db/migrate/20250809045033_add_service_name_to_active_storage_blobs.active_storage.rb new file mode 100644 index 0000000..898f9d0 --- /dev/null +++ b/db/migrate/20250809045033_add_service_name_to_active_storage_blobs.active_storage.rb @@ -0,0 +1,24 @@ +# This migration comes from active_storage (originally 20190112182829) +class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0] + def up + return unless table_exists?(:active_storage_blobs) + + return if column_exists?(:active_storage_blobs, :service_name) + + add_column :active_storage_blobs, :service_name, :string + + # rubocop:disable Rails/SkipsModelValidations + if (configured_service = ActiveStorage::Blob.service.name) + ActiveStorage::Blob.unscoped.update_all(service_name: configured_service) + end + # rubocop:enable Rails/SkipsModelValidations + + change_column :active_storage_blobs, :service_name, :string, null: false + end + + def down + return unless table_exists?(:active_storage_blobs) + + remove_column :active_storage_blobs, :service_name + end +end diff --git a/db/migrate/20250809045034_create_active_storage_variant_records.active_storage.rb b/db/migrate/20250809045034_create_active_storage_variant_records.active_storage.rb new file mode 100644 index 0000000..58cc779 --- /dev/null +++ b/db/migrate/20250809045034_create_active_storage_variant_records.active_storage.rb @@ -0,0 +1,28 @@ +# This migration comes from active_storage (originally 20191206030411) +class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0] + def change + return unless table_exists?(:active_storage_blobs) + + # Use Active Record's configured type for primary key + create_table :active_storage_variant_records, id: primary_key_type, if_not_exists: true do |t| + t.belongs_to :blob, null: false, index: false, type: blobs_primary_key_type + t.string :variation_digest, null: false + + t.index %i[blob_id variation_digest], name: 'index_active_storage_variant_records_uniqueness', unique: true + t.foreign_key :active_storage_blobs, column: :blob_id + end + end + + private + + def primary_key_type + config = Rails.configuration.generators + config.options[config.orm][:primary_key_type] || :primary_key + end + + def blobs_primary_key_type + pkey_name = connection.primary_key(:active_storage_blobs) + pkey_column = connection.columns(:active_storage_blobs).find { |c| c.name == pkey_name } + pkey_column.bigint? ? :bigint : pkey_column.type + end +end diff --git a/db/migrate/20250809045035_remove_not_null_on_active_storage_blobs_checksum.active_storage.rb b/db/migrate/20250809045035_remove_not_null_on_active_storage_blobs_checksum.active_storage.rb new file mode 100644 index 0000000..93c8b85 --- /dev/null +++ b/db/migrate/20250809045035_remove_not_null_on_active_storage_blobs_checksum.active_storage.rb @@ -0,0 +1,8 @@ +# This migration comes from active_storage (originally 20211119233751) +class RemoveNotNullOnActiveStorageBlobsChecksum < ActiveRecord::Migration[6.0] + def change + return unless table_exists?(:active_storage_blobs) + + change_column_null(:active_storage_blobs, :checksum, true) + end +end diff --git a/db/schema.rb b/db/schema.rb index 68bd598..d32e2b3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -2,18 +2,17 @@ # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2017_05_16_194159) do - +ActiveRecord::Schema[8.0].define(version: 2025_08_09_045035) do # These are extensions that must be enabled in order to support this database - enable_extension "plpgsql" + enable_extension "pg_catalog.plpgsql" create_table "submissions", force: :cascade do |t| t.text "html" @@ -21,8 +20,7 @@ t.text "json" t.boolean "save_html" t.boolean "render_html_in_page" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false end - end diff --git a/public/400.html b/public/400.html new file mode 100644 index 0000000..282dbc8 --- /dev/null +++ b/public/400.html @@ -0,0 +1,114 @@ + + + + + + + The server cannot process the request due to a client error (400 Bad Request) + + + + + + + + + + + + + +
+
+ +
+
+

The server cannot process the request due to a client error. Please check the request and try again. If you’re the application owner check the logs for more information.

+
+
+ + + + diff --git a/public/404.html b/public/404.html index 2be3af2..c0670bc 100644 --- a/public/404.html +++ b/public/404.html @@ -1,67 +1,114 @@ - - - - The page you were looking for doesn't exist (404) - - - - - - -
-
-

The page you were looking for doesn't exist.

-

You may have mistyped the address or the page may have moved.

-
-

If you are the application owner check the logs for more information.

-
- + + + + + + + The page you were looking for doesn’t exist (404 Not found) + + + + + + + + + + + + + +
+
+ +
+
+

The page you were looking for doesn’t exist. You may have mistyped the address or the page may have moved. If you’re the application owner check the logs for more information.

+
+
+ + + diff --git a/public/406-unsupported-browser.html b/public/406-unsupported-browser.html new file mode 100644 index 0000000..9532a9c --- /dev/null +++ b/public/406-unsupported-browser.html @@ -0,0 +1,114 @@ + + + + + + + Your browser is not supported (406 Not Acceptable) + + + + + + + + + + + + + +
+
+ +
+
+

Your browser is not supported.
Please upgrade your browser to continue.

+
+
+ + + + diff --git a/public/422.html b/public/422.html index c08eac0..8bcf060 100644 --- a/public/422.html +++ b/public/422.html @@ -1,67 +1,114 @@ - - - - The change you wanted was rejected (422) - - - - - - -
-
-

The change you wanted was rejected.

-

Maybe you tried to change something you didn't have access to.

-
-

If you are the application owner check the logs for more information.

-
- + + + + + + + The change you wanted was rejected (422 Unprocessable Entity) + + + + + + + + + + + + + +
+
+ +
+
+

The change you wanted was rejected. Maybe you tried to change something you didn’t have access to. If you’re the application owner check the logs for more information.

+
+
+ + + diff --git a/public/500.html b/public/500.html index 78a030a..d77718c 100644 --- a/public/500.html +++ b/public/500.html @@ -1,66 +1,114 @@ - - - - We're sorry, but something went wrong (500) - - - - - - -
-
-

We're sorry, but something went wrong.

-
-

If you are the application owner check the logs for more information.

-
- + + + + + + + We’re sorry, but something went wrong (500 Internal Server Error) + + + + + + + + + + + + + +
+
+ +
+
+

We’re sorry, but something went wrong.
If you’re the application owner check the logs for more information.

+
+
+ + + diff --git a/public/icon.png b/public/icon.png new file mode 100644 index 0000000..c4c9dbf Binary files /dev/null and b/public/icon.png differ diff --git a/public/icon.svg b/public/icon.svg new file mode 100644 index 0000000..04b34bf --- /dev/null +++ b/public/icon.svg @@ -0,0 +1,3 @@ + + + diff --git a/public/robots.txt b/public/robots.txt index 37b576a..c19f78a 100644 --- a/public/robots.txt +++ b/public/robots.txt @@ -1 +1 @@ -# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file +# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file diff --git a/spec/controllers/microformats_controller_spec.rb b/spec/controllers/microformats_controller_spec.rb deleted file mode 100644 index 06c3ba8..0000000 --- a/spec/controllers/microformats_controller_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'rails_helper' - -RSpec.describe MicroformatsController, type: :controller do - describe 'GET #show' do - it 'returns http redirect' do - get :show - expect(response).to have_http_status(:redirect) - end - end -end diff --git a/spec/controllers/submissions_controller_spec.rb b/spec/controllers/submissions_controller_spec.rb deleted file mode 100644 index 69d32bd..0000000 --- a/spec/controllers/submissions_controller_spec.rb +++ /dev/null @@ -1,139 +0,0 @@ -require 'rails_helper' - -# This spec was generated by rspec-rails when you ran the scaffold generator. -# It demonstrates how one might use RSpec to specify the controller code that -# was generated by Rails when you ran the scaffold generator. -# -# It assumes that the implementation code is generated by the rails scaffold -# generator. If you are using any extension libraries to generate different -# controller code, this generated spec may or may not pass. -# -# It only uses APIs available in rails and/or rspec-rails. There are a number -# of tools you can use to make these specs even more expressive, but we're -# sticking to rails and rspec-rails APIs to keep things simple and stable. -# -# Compared to earlier versions of this generator, there is very limited use of -# stubs and message expectations in this spec. Stubs are only used when there -# is no simpler way to get a handle on the object needed for the example. -# Message expectations are only used when there is no simpler way to specify -# that an instance is receiving a specific message. -# -# Also compared to earlier versions of this generator, there are no longer any -# expectations of assigns and templates rendered. These features have been -# removed from Rails core in Rails 5, but can be added back in via the -# `rails-controller-testing` gem. - -RSpec.describe SubmissionsController, type: :controller do - # This should return the minimal set of attributes required to create a valid - # Submission. As you add validations to Submission, be sure to - # adjust the attributes here as well. - let(:valid_attributes) do - skip('Add a hash of attributes valid for your model') - end - - let(:invalid_attributes) do - skip('Add a hash of attributes invalid for your model') - end - - # This should return the minimal set of values that should be in the session - # in order to pass any filters (e.g. authentication) defined in - # SubmissionsController. Be sure to keep this updated too. - let(:valid_session) { {} } - - describe 'GET #index' do - it 'returns a success response' do - Submission.create! valid_attributes - get :index, params: {}, session: valid_session - expect(response).to be_success - end - end - - describe 'GET #show' do - it 'returns a success response' do - submission = Submission.create! valid_attributes - get :show, params: { id: submission.to_param }, session: valid_session - expect(response).to be_success - end - end - - describe 'GET #new' do - it 'returns a success response' do - get :new, params: {}, session: valid_session - expect(response).to be_success - end - end - - describe 'GET #edit' do - it 'returns a success response' do - submission = Submission.create! valid_attributes - get :edit, params: { id: submission.to_param }, session: valid_session - expect(response).to be_success - end - end - - describe 'POST #create' do - context 'with valid params' do - it 'creates a new Submission' do - expect do - post :create, params: { submission: valid_attributes }, session: valid_session - end.to change(Submission, :count).by(1) - end - - it 'redirects to the created submission' do - post :create, params: { submission: valid_attributes }, session: valid_session - expect(response).to redirect_to(Submission.last) - end - end - - context 'with invalid params' do - it "returns a success response (i.e. to display the 'new' template)" do - post :create, params: { submission: invalid_attributes }, session: valid_session - expect(response).to be_success - end - end - end - - describe 'PUT #update' do - context 'with valid params' do - let(:new_attributes) do - skip('Add a hash of attributes valid for your model') - end - - it 'updates the requested submission' do - submission = Submission.create! valid_attributes - put :update, params: { id: submission.to_param, submission: new_attributes }, session: valid_session - submission.reload - skip('Add assertions for updated state') - end - - it 'redirects to the submission' do - submission = Submission.create! valid_attributes - put :update, params: { id: submission.to_param, submission: valid_attributes }, session: valid_session - expect(response).to redirect_to(submission) - end - end - - context 'with invalid params' do - it "returns a success response (i.e. to display the 'edit' template)" do - submission = Submission.create! valid_attributes - put :update, params: { id: submission.to_param, submission: invalid_attributes }, session: valid_session - expect(response).to be_success - end - end - end - - describe 'DELETE #destroy' do - it 'destroys the requested submission' do - submission = Submission.create! valid_attributes - expect do - delete :destroy, params: { id: submission.to_param }, session: valid_session - end.to change(Submission, :count).by(-1) - end - - it 'redirects to the submissions list' do - submission = Submission.create! valid_attributes - delete :destroy, params: { id: submission.to_param }, session: valid_session - expect(response).to redirect_to(submissions_url) - end - end -end diff --git a/spec/factories/submissions.rb b/spec/factories/submissions.rb deleted file mode 100644 index acfc922..0000000 --- a/spec/factories/submissions.rb +++ /dev/null @@ -1,9 +0,0 @@ -FactoryBot.define do - factory :submission do - url 'MyText' - html 'MyText' - base_url 'MyText' - save_html false - render_html_in_page false - end -end diff --git a/spec/helpers/microformats_helper_spec.rb b/spec/helpers/microformats_helper_spec.rb deleted file mode 100644 index ffe2f13..0000000 --- a/spec/helpers/microformats_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'rails_helper' - -# Specs in this file have access to a helper object that includes -# the MicroformatsHelper. For example: -# -# describe MicroformatsHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -RSpec.describe MicroformatsHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/helpers/submissions_helper_spec.rb b/spec/helpers/submissions_helper_spec.rb deleted file mode 100644 index 591f28c..0000000 --- a/spec/helpers/submissions_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'rails_helper' - -# Specs in this file have access to a helper object that includes -# the SubmissionsHelper. For example: -# -# describe SubmissionsHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -RSpec.describe SubmissionsHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/submission_spec.rb b/spec/models/submission_spec.rb deleted file mode 100644 index 68fa859..0000000 --- a/spec/models/submission_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Submission, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index fae29fd..89befa8 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -5,6 +5,8 @@ # Prevent database truncation if the environment is production abort('The Rails environment is running in production mode!') if Rails.env.production? require 'rspec/rails' +require 'capybara/rails' +require 'capybara/rspec' # Add additional requires below this line. Rails is not loaded until this point! # Requires supporting ruby files with custom matchers and macros, etc, in @@ -28,7 +30,7 @@ RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures - config.fixture_path = "#{::Rails.root}/spec/fixtures" + # config.fixture_path = Rails.root.join('spec/fixtures') # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false @@ -55,3 +57,18 @@ # arbitrary gems may also be filtered via: # config.filter_gems_from_backtrace("gem name") end + +# Capybara configuration +Capybara.register_driver :headless_chrome do |app| + capabilities = Selenium::WebDriver::Chrome::Options.new + capabilities.add_argument '--headless' + capabilities.add_argument '--no-sandbox' + capabilities.add_argument '--disable-dev-shm-usage' + + Capybara::Selenium::Driver.new app, + browser: :chrome, + options: capabilities +end + +Capybara.javascript_driver = :headless_chrome +Capybara.default_driver = :rack_test diff --git a/spec/requests/submissions_spec.rb b/spec/requests/submissions_spec.rb deleted file mode 100644 index 2919f0f..0000000 --- a/spec/requests/submissions_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'rails_helper' - -RSpec.describe 'Submissions', type: :request do - describe 'GET /submissions' do - it 'works! (now write some real specs)' do - get submissions_path - expect(response).to have_http_status(:redirect) - end - end -end diff --git a/spec/routing/submissions_routing_spec.rb b/spec/routing/submissions_routing_spec.rb deleted file mode 100644 index 4acbf43..0000000 --- a/spec/routing/submissions_routing_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require 'rails_helper' - -RSpec.describe SubmissionsController, type: :routing do - describe 'routing' do - it 'routes to #index' do - expect(get: '/submissions').to route_to('submissions#index') - end - - it 'routes to #new' do - expect(get: '/submissions/new').to route_to('submissions#new') - end - - it 'routes to #show' do - expect(get: '/submissions/1').to route_to('submissions#show', id: '1') - end - - it 'routes to #edit' do - expect(get: '/submissions/1/edit').to route_to('submissions#edit', id: '1') - end - - it 'routes to #create' do - expect(post: '/submissions').to route_to('submissions#create') - end - - it 'routes to #update via PUT' do - expect(put: '/submissions/1').to route_to('submissions#update', id: '1') - end - - it 'routes to #update via PATCH' do - expect(patch: '/submissions/1').to route_to('submissions#update', id: '1') - end - - it 'routes to #destroy' do - expect(delete: '/submissions/1').to route_to('submissions#destroy', id: '1') - end - end -end diff --git a/spec/system/microformats_parsing_spec.rb b/spec/system/microformats_parsing_spec.rb new file mode 100644 index 0000000..52b73b1 --- /dev/null +++ b/spec/system/microformats_parsing_spec.rb @@ -0,0 +1,68 @@ +require 'rails_helper' + +RSpec.describe 'Microformats parsing' do + it 'parses microformats from a URL' do + visit '/' + + within 'form[action="/microformats"]' do + fill_in 'url', with: 'https://aaronparecki.com' + click_button 'Parse' + end + + expect(page).to have_content 'package' + expect(page).to have_content 'microformats-ruby' + expect(page).to have_content 'version' + end + + it 'parses microformats from HTML snippet without saving' do + visit '/' + + within 'form[action="/submissions"]' do + fill_in 'submission_html', with: '
Test
' + uncheck 'Save HTML?' + click_button 'Parse' + end + + expect(page).to have_content 'h-card' + end + + it 'parses and saves microformats from HTML snippet' do + visit '/' + + within 'form[action="/submissions"]' do + fill_in 'submission_html', with: '
Test
' + check 'Save HTML?' + click_button 'Parse' + end + + expect(page).to have_content 'Submission was successfully created' + end + + it 'parses empty HTML and shows empty results' do + visit '/' + + within 'form[action="/submissions"]' do + fill_in 'submission_html', with: '' + check 'Save HTML?' + click_button 'Parse' + end + + expect(page).to have_content 'items' + expect(page).to have_content '[]' + end + + it 'renders HTML in page when option is selected' do + visit '/' + + html_snippet = '
Test User
' + + within 'form[action="/submissions"]' do + fill_in 'submission_html', with: html_snippet + check 'Render HTML in Page?' + click_button 'Parse' + end + + expect(page).to have_css '.h-card' + expect(page).to have_content 'Test User' + end +end diff --git a/spec/views/microformats/show.html.erb_spec.rb b/spec/views/microformats/show.html.erb_spec.rb deleted file mode 100644 index 91ce3ee..0000000 --- a/spec/views/microformats/show.html.erb_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe 'microformats/show.html.erb', type: :view do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/submissions/new.html.erb_spec.rb b/spec/views/submissions/new.html.erb_spec.rb deleted file mode 100644 index 165cba1..0000000 --- a/spec/views/submissions/new.html.erb_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'rails_helper' - -RSpec.describe 'submissions/new', type: :view do - before do - assign(:submission, Submission.new( - html: 'MyText', - base_url: 'MyText', - save_html: false, - render_html_in_page: false - )) - end - - it 'renders new submission form' do - render - - assert_select 'form[action=?][method=?]', submissions_path, 'post' do - assert_select 'textarea[name=?]', 'submission[html]' - - assert_select 'input[name=?]', 'submission[base_url]' - - assert_select 'input[name=?]', 'submission[save_html]' - - assert_select 'input[name=?]', 'submission[render_html_in_page]' - end - end -end diff --git a/spec/views/submissions/show.html.erb_spec.rb b/spec/views/submissions/show.html.erb_spec.rb deleted file mode 100644 index 89afda9..0000000 --- a/spec/views/submissions/show.html.erb_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'rails_helper' - -RSpec.describe 'submissions/show', type: :view do - before do - @submission = assign(:submission, Submission.create!( - html: 'MyText', - base_url: 'MyText', - save_html: false, - render_html_in_page: false - )) - end - - it 'renders attributes in

' do - render - - assert_select 'form[action=?][method=?]', submission_path(@submission.id), 'post' do - assert_select 'textarea[name=?]', 'submission[html]' - - assert_select 'input[name=?][value=?]', 'submission[base_url]', 'MyText' - - assert_select 'textarea[name=?]', 'submission[json]' - end - end -end