Coder Social home page Coder Social logo

railshelp's Issues

Generate from Rails classes

Slightly ambitious, should be interesting. Rough approach:

Example generator classes:

We should be able to extract the argument and class_options and generate some generic components in React. There will be some that we want special logic (e.g. in [migrations](- https://github.com/rails/rails/blob/main/railties/lib/rails/generators/rails/migration/migration_generator.rb
) there is an argument: :attributes, type: :array... which we could use to insert the AttributeArguments component) but those can be edited manually.

There's also some intricacy to how some generators hook into others, which I haven't quite figured out yet e.g. there's a lot more logic relating to the model/migration's attributes. I'm guessing it invokes the ActiveRecord Model Generator)

Add validations

Ideally break into smaller PRs. Some discussion can be found at #4 (comment) - the proposed is to have the individual FieldInputs (could we rename to AttributeForm?) do the validation and only call onUpdate if the inputs are valid (sort of an uncontrolled component). I think we don't need to show an error in the command UI at this moment, just the form inputs.

We can follow https://tailwindui.com/components/application-ui/forms/input-groups#component-7a5297f99a5ed22df80939dd1986de5f, example HTML / classes:

<!--
  This example requires Tailwind CSS v2.0+ 
  
  This example requires some changes to your config:
  
  // tailwind.config.js
  module.exports = {
    // ...
    plugins: [
      // ...
      require('@tailwindcss/forms'),
    ]
  }
-->
<div>
  <label for="email" class="block text-sm font-medium text-gray-700">Email</label>
  <div class="mt-1 relative rounded-md shadow-sm">
    <input type="text" name="email" id="email" class="block w-full pr-10 border-red-300 text-red-900 placeholder-red-300 focus:outline-none focus:ring-red-500 focus:border-red-500 sm:text-sm rounded-md" placeholder="[email protected]" value="adamwathan" aria-invalid="true" aria-describedby="email-error">
    <div class="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none">
      <!-- Heroicon name: solid/exclamation-circle -->
      <svg class="h-5 w-5 text-red-500" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
        <path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
      </svg>
    </div>
  </div>
  <p class="mt-2 text-sm text-red-600" id="email-error">Your password must be less than 4 characters.</p>
</div>

Model Generator

  • model name should be CamelCased or under_scored only
  • attribute name is required
  • does attribute name need to be under_scored?
  • field type is required
  • limit / precision / scale modifiers should be positive integers only
  • reserved attribute names e.g. type is used for single table inheritance

Add search on index page

  • Move model generator to it's own page
  • Users can find a generator by use case (e.g. "create a new model", "add attributes to an existing model")
  • Users can find a generator by command (e.g. "rails g model", "rails g migration")

Dependency #7

Bug with decimal precision example

https://rails.help provides wrong example:

bin/rails g model ExampleModel other_model:references{polymorphic}:uniq lng:decimal{10,6}

right example:

bin/rails g model ExampleModel other_model:references{polymorphic}:uniq lng:decimal{10-6}

Please change decimal{10,6} to decimal{10-6}

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.