Skip to content

Commit

Permalink
Create command line for new template (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexB52 authored Jul 9, 2024
1 parent 3f6c097 commit 511e5fd
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
examples/*.sqlite*
**/*.sqlite*
log/*
**/uni_rails.gem
**/uni_rails.gem
.byebug_history
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
uni_rails (0.3.0)
uni_rails (0.4.0)
rackup (~> 2.1)
rails (~> 7.1)
turbo-rails (~> 2.0)
Expand Down
88 changes: 88 additions & 0 deletions assets/templates/default.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
ENV["SECRET_KEY_BASE"] = "1212312313"
ENV["DATABASE_URL"] = "sqlite3:///#{__dir__}/database.sqlite"

require "bundler/inline"

gemfile do
source "https://www.rubygems.org"
gem "uni_rails"
gem "sqlite3", "~> 1.7"
gem "byebug"
end

require "uni_rails"
require "sqlite3"
require "byebug"

# ==== ROUTES ====
UniRails::App.routes.append do
root "resource_names#new"
resources :resource_names
end

# ==== DB SCHEMA ====
ActiveRecord::Base.establish_connection
ActiveRecord::Schema.define do
create_table :resources, force: :cascade do |t|
t.string :title
end
end

# ==== MODELS ====
class Resource < ActiveRecord::Base
end

# ==== SEEDS ====
# Create your existing records here

# ==== CONTROLLERS ====
class ResourceNamesController < ActionController::Base
layout 'application'

def new
end

def create
end
end

# ==== IMPORT MAPS ====
UniRails.import_maps(
'stimulus' => 'https://unpkg.com/@hotwired/stimulus/dist/stimulus.js'
)


# ==== JAVASCRTIP ====
UniRails.javascript <<~JAVASCRIPT
import { Application, Controller } from "stimulus"
window.Stimulus = Application.start()

Stimulus.register("hello", class extends Controller {
connect() {
console.log("hello world")
}
})

JAVASCRIPT

# ==== CSS ====
UniRails.css <<~CSS
html { background-color:#EEE; }
body { width:500px; height:700px; margin:auto;
background-color:white; padding:1rem;
}
form {
label { display: block; }
input[type="submit"] { display: block; margin-top:1rem; }
.field_with_errors { color:red; display:inline; }
}
CSS

# ==== VIEWS ====
UniRails.register_view "resource_names/new.html.erb", <<~HTML
HTML

UniRails.register_view "resource_names/show.html.erb", <<~HTML
HTML

UniRails.run(Port: 3000)
18 changes: 18 additions & 0 deletions exe/unirails
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env ruby

# require "byebug"
# byebug

assets_path = File.expand_path('../assets', __dir__)

options = {}
case ARGV[0]
when "new"
filename = ARGV[1]
File.open(filename, 'wb+') do |f|
f.write File.read File.join(assets_path, 'templates', 'default.txt')
end
else
puts "unknown command"
puts "Usage: unirails new <filename>"
end
2 changes: 1 addition & 1 deletion lib/uni_rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module UniRails
VERSION = "0.3.0"
VERSION = "0.4.0"
end

0 comments on commit 511e5fd

Please sign in to comment.