Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add Scriptures data

  • Loading branch information...
commit a2db5640ff2856ad114cfec85998abd3674f7b38 1 parent f275094
@stindall77 authored
View
3  app/assets/javascripts/scriptures.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/
View
69 app/assets/stylesheets/scaffolds.css.scss
@@ -0,0 +1,69 @@
+body {
+ background-color: #fff;
+ color: #333;
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px;
+}
+
+p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px;
+}
+
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px;
+}
+
+a {
+ color: #000;
+ &:visited {
+ color: #666;
+ }
+ &:hover {
+ color: #fff;
+ background-color: #000;
+ }
+}
+
+div {
+ &.field, &.actions {
+ margin-bottom: 10px;
+ }
+}
+
+#notice {
+ color: green;
+}
+
+.field_with_errors {
+ padding: 2px;
+ background-color: red;
+ display: table;
+}
+
+#error_explanation {
+ width: 450px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 0;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ margin-bottom: 0px;
+ background-color: #c00;
+ color: #fff;
+ }
+ ul li {
+ font-size: 12px;
+ list-style: square;
+ }
+}
View
3  app/assets/stylesheets/scriptures.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Scriptures controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
74 app/controllers/scriptures_controller.rb
@@ -0,0 +1,74 @@
+class ScripturesController < ApplicationController
+ before_action :set_scripture, only: [:show, :edit, :update, :destroy]
+
+ # GET /scriptures
+ # GET /scriptures.json
+ def index
+ @scriptures = Scripture.all
+ end
+
+ # GET /scriptures/1
+ # GET /scriptures/1.json
+ def show
+ end
+
+ # GET /scriptures/new
+ def new
+ @scripture = Scripture.new
+ end
+
+ # GET /scriptures/1/edit
+ def edit
+ end
+
+ # POST /scriptures
+ # POST /scriptures.json
+ def create
+ @scripture = Scripture.new(scripture_params)
+
+ respond_to do |format|
+ if @scripture.save
+ format.html { redirect_to @scripture, notice: 'Scripture was successfully created.' }
+ format.json { render action: 'show', status: :created, location: @scripture }
+ else
+ format.html { render action: 'new' }
+ format.json { render json: @scripture.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PATCH/PUT /scriptures/1
+ # PATCH/PUT /scriptures/1.json
+ def update
+ respond_to do |format|
+ if @scripture.update(scripture_params)
+ format.html { redirect_to @scripture, notice: 'Scripture was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: 'edit' }
+ format.json { render json: @scripture.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /scriptures/1
+ # DELETE /scriptures/1.json
+ def destroy
+ @scripture.destroy
+ respond_to do |format|
+ format.html { redirect_to scriptures_url }
+ format.json { head :no_content }
+ end
+ end
+
+ private
+ # Use callbacks to share common setup or constraints between actions.
+ def set_scripture
+ @scripture = Scripture.find(params[:id])
+ end
+
+ # Never trust parameters from the scary internet, only allow the white list through.
+ def scripture_params
+ params.require(:scripture).permit(:ref, :text)
+ end
+end
@shoe
shoe added a note

A lot of this is boilerplate controller. This is good to read thoroughly and understand. But, it also contains a lot of stuff you don't need (plus the kitchen sink) so about the same time you understand it will be about the time you feel like deleting it. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
View
2  app/helpers/scriptures_helper.rb
@@ -0,0 +1,2 @@
+module ScripturesHelper
+end
View
2  app/models/scripture.rb
@@ -0,0 +1,2 @@
+class Scripture < ActiveRecord::Base
+end
View
2  app/views/layouts/application.html.erb
@@ -3,7 +3,9 @@
<head>
<title>BibleApp</title>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
+ <link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
+ <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<%= csrf_meta_tags %>
</head>
<body>
@shoe
shoe added a note

ERB is simple, and it's the default. It will be a good choice while you're getting the hang of rails. When you're ready to introduce something new, HAML is way better, though.

@stindall77 Owner

I've looked into HAML -- we use mustache at work, I didn't want to meddle with the default when I hve som much other meddling to do.

@shoe
shoe added a note

good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
View
25 app/views/scriptures/_form.html.erb
@@ -0,0 +1,25 @@
+<%= form_for(@scripture) do |f| %>
+ <% if @scripture.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@scripture.errors.count, "error") %> prohibited this scripture from being saved:</h2>
+
+ <ul>
+ <% @scripture.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :ref %><br>
+ <%= f.text_field :ref %>
+ </div>
+ <div class="field">
+ <%= f.label :text %><br>
+ <%= f.text_area :text %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
View
6 app/views/scriptures/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing scripture</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @scripture %> |
+<%= link_to 'Back', scriptures_path %>
View
29 app/views/scriptures/index.html.erb
@@ -0,0 +1,29 @@
+<h1>Listing scriptures</h1>
+
+<table>
+ <thead>
+ <tr>
+ <th>Ref</th>
+ <th>Text</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+ </thead>
+
+ <tbody>
+ <% @scriptures.each do |scripture| %>
+ <tr>
+ <td><%= scripture.ref %></td>
+ <td><%= scripture.text %></td>
+ <td><%= link_to 'Show', scripture %></td>
+ <td><%= link_to 'Edit', edit_scripture_path(scripture) %></td>
+ <td><%= link_to 'Destroy', scripture, method: :delete, data: { confirm: 'Are you sure?' } %></td>
+ </tr>
+ <% end %>
+ </tbody>
+</table>
+
+<br>
+
+<%= link_to 'New Scripture', new_scripture_path %>
View
4 app/views/scriptures/index.json.jbuilder
@@ -0,0 +1,4 @@
+json.array!(@scriptures) do |scripture|
+ json.extract! scripture, :ref, :text
+ json.url scripture_url(scripture, format: :json)
+end
View
5 app/views/scriptures/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New scripture</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', scriptures_path %>
View
14 app/views/scriptures/show.html.erb
@@ -0,0 +1,14 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <strong>Ref:</strong>
+ <%= @scripture.ref %>
+</p>
+
+<p>
+ <strong>Text:</strong>
+ <%= @scripture.text %>
+</p>
+
+<%= link_to 'Edit', edit_scripture_path(@scripture) %> |
+<%= link_to 'Back', scriptures_path %>
View
1  app/views/scriptures/show.json.jbuilder
@@ -0,0 +1 @@
+json.extract! @scripture, :ref, :text, :created_at, :updated_at
View
2  config/routes.rb
@@ -1,4 +1,6 @@
BibleApp::Application.routes.draw do
+ resources :scriptures
+
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
View
10 db/migrate/20130925011106_create_scriptures.rb
@@ -0,0 +1,10 @@
+class CreateScriptures < ActiveRecord::Migration
+ def change
+ create_table :scriptures do |t|
+ t.string :ref
+ t.text :text
+
+ t.timestamps
+ end
+ end
+end
View
23 db/schema.rb
@@ -0,0 +1,23 @@
+# encoding: UTF-8
+# This file is auto-generated from the current state of the database. Instead
+# 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).
+#
+# It's strongly recommended that you check this file into your version control system.
+
+ActiveRecord::Schema.define(version: 20130925011106) do
+
+ create_table "scriptures", force: true do |t|
+ t.string "ref"
+ t.text "text"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+end
View
11 db/seeds.rb
@@ -5,3 +5,14 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
+
+Dir.glob("/home/stephen77/nt_verses_clean/*").each do |file|
@shoe
shoe added a note

How big are these? If they are under 5 MB or so, I think it's fine to just commit them to git, say under db/data/. If they are really big, we might need a better way of getting them in to the DB.

@shoe
shoe added a note

BTW, if you add these to the repo, and deploy to heroku, you'll need to manually run the rake db:seed task to load them.

@stindall77 Owner

276K total with each verse in an individual file. I'll try db:seed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ cur_file = File.open(file, "r")
+ name = File.basename(file)
+ data = cur_file.read
+ Scripture.create(ref: name, text: data)
+ cur_file.close
@shoe
shoe added a note

There's a convenient "block form" of File.open which takes a block, and automatically handles file closing for you:

File.open(file, "r") { |cur_file|
  Scripture.create(ref: File.basename(file), text: cur_file.read)
}
@stindall77 Owner

My first foray into Ruby.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ puts name
+ puts data
+end
+
View
49 test/controllers/scriptures_controller_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class ScripturesControllerTest < ActionController::TestCase
+ setup do
+ @scripture = scriptures(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:scriptures)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create scripture" do
+ assert_difference('Scripture.count') do
+ post :create, scripture: { ref: @scripture.ref, text: @scripture.text }
+ end
+
+ assert_redirected_to scripture_path(assigns(:scripture))
+ end
+
+ test "should show scripture" do
+ get :show, id: @scripture
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @scripture
+ assert_response :success
+ end
+
+ test "should update scripture" do
+ patch :update, id: @scripture, scripture: { ref: @scripture.ref, text: @scripture.text }
+ assert_redirected_to scripture_path(assigns(:scripture))
+ end
+
+ test "should destroy scripture" do
+ assert_difference('Scripture.count', -1) do
+ delete :destroy, id: @scripture
+ end
+
+ assert_redirected_to scriptures_path
+ end
+end
View
9 test/fixtures/scriptures.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ ref: MyString
+ text: MyText
+
+two:
+ ref: MyString
+ text: MyText
View
4 test/helpers/scriptures_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class ScripturesHelperTest < ActionView::TestCase
+end
View
7 test/models/scripture_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class ScriptureTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
@shoe

A lot of this is boilerplate controller. This is good to read thoroughly and understand. But, it also contains a lot of stuff you don't need (plus the kitchen sink) so about the same time you understand it will be about the time you feel like deleting it. :)

@shoe

ERB is simple, and it's the default. It will be a good choice while you're getting the hang of rails. When you're ready to introduce something new, HAML is way better, though.

@shoe

How big are these? If they are under 5 MB or so, I think it's fine to just commit them to git, say under db/data/. If they are really big, we might need a better way of getting them in to the DB.

@shoe

There's a convenient "block form" of File.open which takes a block, and automatically handles file closing for you:

File.open(file, "r") { |cur_file|
  Scripture.create(ref: File.basename(file), text: cur_file.read)
}
@shoe

BTW, if you add these to the repo, and deploy to heroku, you'll need to manually run the rake db:seed task to load them.

@stindall77

I've looked into HAML -- we use mustache at work, I didn't want to meddle with the default when I hve som much other meddling to do.

@stindall77

276K total with each verse in an individual file. I'll try db:seed.

@stindall77

My first foray into Ruby.

Please sign in to comment.
Something went wrong with that request. Please try again.