GithubHelp home page GithubHelp logo

rails-project-lvl1's Introduction

Hexlet tests and linter status:

Actions Status

Actions Status

HexletCode

The gem HexletCode is a simple gem that allow you to get html code of form, using only Ruby code.

Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add hexlet_code

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install hexlet_code

Usage

How to create form with input type: text and with textarea. Default size is cols="20" and rows="40", default tag's id is its name. But you can override these attributes values, as in the example below:

<%= HexletCode.form_for @user do |f| %>
  <%= f.input :name %>
  <%= f.input :job, as: :text, class: "form-control", id: "exampleFormControlTextarea1", rows: 80 %>
  <%= f.submit %>
<%= end %>

As a result we have such html code:

<form action="#" method="post">
  <label for="name">Name</label>
  <input name="name" id="name" type="text" value="rob">
  <label for="exampleFormControlTextarea1">Job</label>
  <textarea cols="20" rows="40" name="job" id="exampleFormControlTextarea1" class="form-control">hexlet</textarea>
  <input name="commit" type="submit" value="Save">
</form>

How to create form with input type: text and two selects (the first one is with multiple select). You can use array of arrays or array of strings for option's values and for option's bodies. But if you use array of strings, you will get options where every value is equal to every body as in the second select:

<%= HexletCode.form_for @user, url: "/users" do |f| %>
  <%= f.input :name %>
  <%= f.input :hobby, as: :select, options: [["1", "First select"], ["2", "Second select"], ["3", "Third select"]], multiple: true %>
  <%= f.input :gender, as: :select, class: "form-control", options: %w[m f] %>
  <%= f.submit "Send", name: "sending" %>
<%= end %>

As a result we have such html code with one input and two selects:

<form action="/users" method="post">
  <label for="name">Name</label>
  <input name="name" id="name" type="text" value="rob">
  <label for="hobby">Hobby</label>
  <select name="hobby" id="hobby" multiple>
    <option value="1">First select</option>
    <option selected value="2">Second select</option>
    <option selected value="3">Third select</option>
  </select>
  <label for="gender">Gender</label>
  <select name="gender" id="gender" class="form-control">
    <option selected value="m">m</option>
    <option value="f">f</option>
  </select>
  <input name="sending" type="submit" value="Send">
</form>

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

License

The gem is available as open source under the terms of the MIT License.

rails-project-lvl1's People

Contributors

kalash-job avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.