diff --git a/memo_app/.erb-lint.yml b/memo_app/.erb-lint.yml new file mode 100644 index 0000000000..dee1bef038 --- /dev/null +++ b/memo_app/.erb-lint.yml @@ -0,0 +1,5 @@ +--- +glob: "**/*.erb" +linters: + RequireInputAutocomplete: + enabled: false diff --git a/memo_app/.ruby-version b/memo_app/.ruby-version new file mode 100644 index 0000000000..b347b11eac --- /dev/null +++ b/memo_app/.ruby-version @@ -0,0 +1 @@ +3.2.3 diff --git a/memo_app/Gemfile b/memo_app/Gemfile new file mode 100644 index 0000000000..ee9baf8f1d --- /dev/null +++ b/memo_app/Gemfile @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +source 'https://rubygems.org' + +# gem "rails" +gem 'erb_lint', require: false +gem 'puma' +gem 'rackup' +gem 'redcarpet' +gem 'sinatra' +gem 'sinatra-contrib' +gem 'webrick' diff --git a/memo_app/Gemfile.lock b/memo_app/Gemfile.lock new file mode 100644 index 0000000000..916ad96f08 --- /dev/null +++ b/memo_app/Gemfile.lock @@ -0,0 +1,132 @@ +GEM + remote: https://rubygems.org/ + specs: + actionview (7.1.3.2) + activesupport (= 7.1.3.2) + builder (~> 3.1) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activesupport (7.1.3.2) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + minitest (>= 5.1) + mutex_m + tzinfo (~> 2.0) + ast (2.4.2) + base64 (0.2.0) + better_html (2.1.1) + actionview (>= 6.0) + activesupport (>= 6.0) + ast (~> 2.0) + erubi (~> 1.4) + parser (>= 2.4) + smart_properties + bigdecimal (3.1.7) + builder (3.2.4) + concurrent-ruby (1.2.3) + connection_pool (2.4.1) + crass (1.0.6) + drb (2.2.1) + erb_lint (0.5.0) + activesupport + better_html (>= 2.0.1) + parser (>= 2.7.1.4) + rainbow + rubocop + smart_properties + erubi (1.12.0) + i18n (1.14.4) + concurrent-ruby (~> 1.0) + json (2.7.2) + language_server-protocol (3.17.0.3) + loofah (2.22.0) + crass (~> 1.0.2) + nokogiri (>= 1.12.0) + minitest (5.22.3) + multi_json (1.15.0) + mustermann (3.0.0) + ruby2_keywords (~> 0.0.1) + mutex_m (0.2.0) + nio4r (2.7.1) + nokogiri (1.16.4-x86_64-linux) + racc (~> 1.4) + parallel (1.24.0) + parser (3.3.0.5) + ast (~> 2.4.1) + racc + puma (6.4.2) + nio4r (~> 2.0) + racc (1.7.3) + rack (3.0.10) + rack-protection (4.0.0) + base64 (>= 0.1.0) + rack (>= 3.0.0, < 4) + rack-session (2.0.0) + rack (>= 3.0.0) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest + nokogiri (>= 1.6) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + rainbow (3.1.1) + redcarpet (3.6.0) + regexp_parser (2.9.0) + rexml (3.2.6) + rubocop (1.63.3) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.2) + parser (>= 3.3.0.4) + ruby-progressbar (1.13.0) + ruby2_keywords (0.0.5) + sinatra (4.0.0) + mustermann (~> 3.0) + rack (>= 3.0.0, < 4) + rack-protection (= 4.0.0) + rack-session (>= 2.0.0, < 3) + tilt (~> 2.0) + sinatra-contrib (4.0.0) + multi_json (>= 0.0.2) + mustermann (~> 3.0) + rack-protection (= 4.0.0) + sinatra (= 4.0.0) + tilt (~> 2.0) + smart_properties (1.17.0) + tilt (2.3.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (2.5.0) + webrick (1.8.1) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + erb_lint + puma + rackup + redcarpet + sinatra + sinatra-contrib + webrick + +BUNDLED WITH + 2.4.10 diff --git a/memo_app/README.md b/memo_app/README.md new file mode 100644 index 0000000000..8ec401507e --- /dev/null +++ b/memo_app/README.md @@ -0,0 +1,25 @@ +# メモアプリ + +### 機能 +* メモ作成機能(閲覧可能) +* メモ編集機能 +* メモ削除機能 + + +### 操作手順 +1. ローカルに複製 +``` +git clone +``` + +1. ディレクトリを移動してGemファイルをインストール +``` +cd memo_app + +bundle install +``` + +1. 実行 +``` +ruby main.rb +``` diff --git a/memo_app/main.rb b/memo_app/main.rb new file mode 100644 index 0000000000..12e194105a --- /dev/null +++ b/memo_app/main.rb @@ -0,0 +1,74 @@ +# frozen_string_literal: true + +require 'sinatra' +require 'sinatra/reloader' +require 'json' +require 'cgi' + +FILE_PATH = 'public/memos.json' + +def get_memos(file_path) + File.open(file_path) { |item| JSON.parse(item.read) } +end + +def set_memos(file_path, memos) + File.open(file_path, 'w') { |item| JSON.dump(memos, item) } +end + +get '/' do + redirect '/memos' +end + +get '/memos' do + @memos = get_memos(FILE_PATH) + erb :index +end + +get '/memos/new' do + erb :new_memo +end + +get '/memos/:id' do + memos = get_memos(FILE_PATH) + @title = memos[params[:id]]['title'] + @content = memos[params[:id]]['content'] + erb :memo +end + +post '/memos' do + title = params[:title] + content = params[:content] + + memos = get_memos(FILE_PATH) + id = (memos.keys.map(&:to_i).max + 1).to_s + memos[id] = { 'title' => title, 'content' => content } + set_memos(FILE_PATH, memos) + + redirect '/memos' +end + +get '/memos/:id/edit' do + memos = get_memos(FILE_PATH) + @title = memos[params[:id]]['title'] + @content = memos[params[:id]]['content'] + erb :edit +end + +patch '/memos/:id' do + title = params[:title] + content = params[:content] + + memos = get_memos(FILE_PATH) + memos[params[:id]] = { 'title' => title, 'content' => content } + set_memos(FILE_PATH, memos) + + redirect "/memos/#{params[:id]}" +end + +delete '/memos/:id' do + memos = get_memos(FILE_PATH) + memos.delete(params[:id]) + set_memos(FILE_PATH, memos) + + redirect '/memos' +end diff --git a/memo_app/public/memos.json b/memo_app/public/memos.json new file mode 100644 index 0000000000..af8bd67d65 --- /dev/null +++ b/memo_app/public/memos.json @@ -0,0 +1 @@ +{"1":{"title":"あああ","content":"あああああああああああ"},"2":{"title":"いいいいい","content":"いいいいいいいい"},"3":{"title":"ううううああああ","content":"ううああああああ!"},"4":{"title":"今日の晩御飯","content":"カレーを作る\r\nそのために買い物をする\r\nカレールー\r\nジャガイモ\r\n人参\r\n肉\r\nたまねぎ"},"6":{"title":"tekisutotekisuto","content":"aaaaaa\r\naaaaaaa\r\ntext\r\ntex\r\nte\r\nt\r\n"},"7":{"title":"ああああああああ!","content":"ssssssssssss"}} \ No newline at end of file diff --git a/memo_app/public/style.css b/memo_app/public/style.css new file mode 100644 index 0000000000..78a05c1382 --- /dev/null +++ b/memo_app/public/style.css @@ -0,0 +1,74 @@ +.main-title{ + color:#805539; +} + +.title-font{ + color:#444; + font-weight: bold; +} + +.text-font{ + color:gray; + font-family: "Verdana"; +} +.link-text{ + text-decoration: none; +} + +.new-memo{ + color:#444; + margin:0 15px; + text-decoration: none; + font-weight:bold; +} +.container{ + width:500px; + background-color: #efefef; + padding:20px 10px; +} + +.contents-container{ + background-color:#ddd; + padding:5px 10px; + border-radius:3px +} + +.button{ + color:white; + border-radius: 5px; +} +.button.submit{ + border:1px solid #888; + background-color:#888; + padding:2px 5px; + margin:15px 0; + text-decoration: none; +} +.button.delete{ + background-color:#990; + border:1px solid #990; +} +.button.new{ + background-color:#666; + border-radius: 50%; + padding:0 4px; +} + +.text-box{ + border:1px solid white; + background-color:white; + padding:10px 20px; + border-radius:5px; + resize: none; +} + + +input:focus { + outline: none; + box-shadow: 0px 0px 3px 0px #5265a7; +} + +textarea:focus{ + outline: none; + box-shadow: 0px 0px 3px 0px #5265a7; +} diff --git a/memo_app/public/test.html b/memo_app/public/test.html new file mode 100644 index 0000000000..fa8c22aea5 --- /dev/null +++ b/memo_app/public/test.html @@ -0,0 +1 @@ +this is html file . diff --git a/memo_app/views/edit.erb b/memo_app/views/edit.erb new file mode 100644 index 0000000000..b69f12aa81 --- /dev/null +++ b/memo_app/views/edit.erb @@ -0,0 +1,15 @@ +
<%= CGI.escapeHTML(@title) %>
+ + +<%= CGI.escapeHTML(@content) %>
+ +