diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1c5f6b9..69188e1 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -7,8 +7,8 @@ module ApplicationHelper return "" unless story text_length = story.text.length template = "text" - template = "half" if text_length < 200 - template = "pic" if text_length < 100 + template = "half" if text_length < 400 + template = "pic" if text_length < 200 render partial: "stories/#{template}" , locals: {story: story} end @@ -33,6 +33,10 @@ module ApplicationHelper self.renderer.render(text).html_safe end + def shorten(text , to = 100) + return "" if text.blank? + "#{text[0..to]} . . . ".html_safe + end def main_app Rails.application.routes.url_helpers end @@ -41,4 +45,13 @@ module ApplicationHelper "mr-3 inline-block rounded-lg px-3 py-2 text-md font-medium border border-gray-500" end + def rows( text ) + return 5 if text.blank? + text = text.text unless text.is_a?(String) + return 5 if text.blank? + rows = (text.length / 60).to_i + return 5 if rows < 5 + rows + end + end diff --git a/app/views/stories/edit.html.haml b/app/views/stories/edit.html.haml index 49ce167..f383346 100644 --- a/app/views/stories/edit.html.haml +++ b/app/views/stories/edit.html.haml @@ -10,11 +10,12 @@ - @story.errors.full_messages.each do |message| %li= message - = f.input :picture , as: :file + = f.input :picture , as: :file , label: (@story.picture.blank? ? "Add picture" : "Change picture") = f.input :header - = f.input :text - = f.input :happened , class: "flex" - = f.submit 'Save' - = link_to 'Show', @story - = link_to 'Back', stories_path + = f.input :text , input_html: {rows: rows(@story.text)} + .mt-4= f.input :happened , class: "flex" + %button.mt-6.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400 + = f.submit 'Save' + %button.ml-20.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400 + = link_to 'Back', @story %div diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb index 9293903..d827da0 100644 --- a/config/initializers/simple_form.rb +++ b/config/initializers/simple_form.rb @@ -14,7 +14,7 @@ SimpleForm.setup do |config| # stack. The options given below are used to wrap the # whole input. - config.wrappers :default, tag: 'div', class: '', error_class: '', valid_class: '' do |b| + config.wrappers :default, tag: 'div', class: 'mt-2', error_class: '', valid_class: '' do |b| b.use :html5 b.use :placeholder b.optional :maxlength @@ -42,7 +42,7 @@ SimpleForm.setup do |config| b.use :label, class: "block text-sm font-medium text-gray-700" - b.wrapper tag: 'div', class: 'mt-1 flex rounded-md shadow-sm' do |d| + b.wrapper tag: 'div', class: 'mt-4 flex rounded-md shadow-sm' do |d| d.use :prepend d.use :input, class: "flex-1 min-w-0 block w-full px-3 py-2 rounded-none rounded-r-md focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm border-gray-300",