From 2c8dab0b70760cdb3f8b9259e98b14b9cfba80f2 Mon Sep 17 00:00:00 2001 From: jepe-w Date: Fri, 29 Mar 2024 14:39:08 +0900 Subject: [PATCH 01/12] =?UTF-8?q?=E6=9E=A0=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- try_sinatra/Gemfile | 11 +++++ try_sinatra/Gemfile.lock | 49 +++++++++++++++++++ try_sinatra/main.rb | 26 ++++++++++ try_sinatra/public/test.html | 1 + .../views/erb_and_md_template_page.erb | 2 + .../views/erb_and_md_template_page.markdown | 1 + try_sinatra/views/erb_template_page.erb | 1 + try_sinatra/views/index.erb | 23 +++++++++ .../views/markdown_template_page.markdown | 1 + 9 files changed, 115 insertions(+) create mode 100644 try_sinatra/Gemfile create mode 100644 try_sinatra/Gemfile.lock create mode 100644 try_sinatra/main.rb create mode 100644 try_sinatra/public/test.html create mode 100644 try_sinatra/views/erb_and_md_template_page.erb create mode 100644 try_sinatra/views/erb_and_md_template_page.markdown create mode 100644 try_sinatra/views/erb_template_page.erb create mode 100644 try_sinatra/views/index.erb create mode 100644 try_sinatra/views/markdown_template_page.markdown diff --git a/try_sinatra/Gemfile b/try_sinatra/Gemfile new file mode 100644 index 0000000000..8cc20cc7b8 --- /dev/null +++ b/try_sinatra/Gemfile @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +# gem "rails" +gem "sinatra" +gem "webrick" +gem "rackup" +gem "puma" +gem "sinatra-contrib" +gem "redcarpet" diff --git a/try_sinatra/Gemfile.lock b/try_sinatra/Gemfile.lock new file mode 100644 index 0000000000..62f67041b2 --- /dev/null +++ b/try_sinatra/Gemfile.lock @@ -0,0 +1,49 @@ +GEM + remote: https://rubygems.org/ + specs: + base64 (0.2.0) + multi_json (1.15.0) + mustermann (3.0.0) + ruby2_keywords (~> 0.0.1) + nio4r (2.7.1) + puma (6.4.2) + nio4r (~> 2.0) + 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) + redcarpet (3.6.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) + tilt (2.3.0) + webrick (1.8.1) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + puma + rackup + redcarpet + sinatra + sinatra-contrib + webrick + +BUNDLED WITH + 2.4.10 diff --git a/try_sinatra/main.rb b/try_sinatra/main.rb new file mode 100644 index 0000000000..82e16e3fa6 --- /dev/null +++ b/try_sinatra/main.rb @@ -0,0 +1,26 @@ +require 'sinatra' +require 'sinatra/reloader' + +get '/' do + erb :index +end + +get '/path/to' do + "this is [/path/to]" +end + +get '/hello/*' do |name| + "hello #{name}. how are you?" +end + +get '/erb_template_page' do + erb :erb_template_page +end + +get '/markdown_template_page' do + markdown :markdown_template_page +end + +get '/erb_and_md_template_page' do + erb :erb_and_md_template_page +end diff --git a/try_sinatra/public/test.html b/try_sinatra/public/test.html new file mode 100644 index 0000000000..fa8c22aea5 --- /dev/null +++ b/try_sinatra/public/test.html @@ -0,0 +1 @@ +this is html file . diff --git a/try_sinatra/views/erb_and_md_template_page.erb b/try_sinatra/views/erb_and_md_template_page.erb new file mode 100644 index 0000000000..25a1cc7595 --- /dev/null +++ b/try_sinatra/views/erb_and_md_template_page.erb @@ -0,0 +1,2 @@ +<%= Time.now %>> +<%= markdown(:erb_and_md_template_page) %> diff --git a/try_sinatra/views/erb_and_md_template_page.markdown b/try_sinatra/views/erb_and_md_template_page.markdown new file mode 100644 index 0000000000..44bd51a1eb --- /dev/null +++ b/try_sinatra/views/erb_and_md_template_page.markdown @@ -0,0 +1 @@ +# this is erb_and_md.markdown \ No newline at end of file diff --git a/try_sinatra/views/erb_template_page.erb b/try_sinatra/views/erb_template_page.erb new file mode 100644 index 0000000000..013c74d12a --- /dev/null +++ b/try_sinatra/views/erb_template_page.erb @@ -0,0 +1 @@ +<%= Time.now %> diff --git a/try_sinatra/views/index.erb b/try_sinatra/views/index.erb new file mode 100644 index 0000000000..40af5607f7 --- /dev/null +++ b/try_sinatra/views/index.erb @@ -0,0 +1,23 @@ + + + + + + Document + + + メモアプリ +
+ +
+
right
+
+ +
+ + diff --git a/try_sinatra/views/markdown_template_page.markdown b/try_sinatra/views/markdown_template_page.markdown new file mode 100644 index 0000000000..f2fda8d8bc --- /dev/null +++ b/try_sinatra/views/markdown_template_page.markdown @@ -0,0 +1 @@ +# this is markdown_template_page! \ No newline at end of file From 62698f206ddc366cff2bafd15bff0f7c8a90e659 Mon Sep 17 00:00:00 2001 From: jepe-w Date: Mon, 1 Apr 2024 09:33:21 +0900 Subject: [PATCH 02/12] =?UTF-8?q?views/items.erb=E3=81=AE=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- try_sinatra/main.rb | 21 +++++++++++++-------- try_sinatra/views/index.erb | 11 ++++++----- try_sinatra/views/items.erb | 13 +++++++++++++ 3 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 try_sinatra/views/items.erb diff --git a/try_sinatra/main.rb b/try_sinatra/main.rb index 82e16e3fa6..10d3829f1d 100644 --- a/try_sinatra/main.rb +++ b/try_sinatra/main.rb @@ -13,14 +13,19 @@ "hello #{name}. how are you?" end -get '/erb_template_page' do - erb :erb_template_page +get '/items' do |number| + erb :items end -get '/markdown_template_page' do - markdown :markdown_template_page -end -get '/erb_and_md_template_page' do - erb :erb_and_md_template_page -end +# get '/erb_template_page' do +# erb :erb_template_page +# end + +# get '/markdown_template_page' do +# markdown :markdown_template_page +# end + +# get '/erb_and_md_template_page' do +# erb :erb_and_md_template_page +# end \ No newline at end of file diff --git a/try_sinatra/views/index.erb b/try_sinatra/views/index.erb index 40af5607f7..421af061fc 100644 --- a/try_sinatra/views/index.erb +++ b/try_sinatra/views/index.erb @@ -6,7 +6,12 @@ Document - メモアプリ +
+ メモアプリ +
+ +
+
  • メモ1
  • @@ -15,9 +20,5 @@
  • メモ4
-
right
-
- -
diff --git a/try_sinatra/views/items.erb b/try_sinatra/views/items.erb new file mode 100644 index 0000000000..9f96b97ff2 --- /dev/null +++ b/try_sinatra/views/items.erb @@ -0,0 +1,13 @@ + + + + + + Items + + + メモアプリ + + + + \ No newline at end of file From 614479a63d7d3a0634ac47b3c5b0469df89be452 Mon Sep 17 00:00:00 2001 From: jepe-w Date: Thu, 4 Apr 2024 10:02:21 +0900 Subject: [PATCH 03/12] =?UTF-8?q?index.erb,items.erb,edit.erb=E3=83=95?= =?UTF-8?q?=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92=E4=BF=AE=E6=AD=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- try_sinatra/main.rb | 15 +++++++------- try_sinatra/views/edit.erb | 7 +++++++ .../views/erb_and_md_template_page.markdown | 1 - try_sinatra/views/index.erb | 20 ++++++++++++------- try_sinatra/views/items.erb | 15 ++++++++++++-- .../views/markdown_template_page.markdown | 1 - try_sinatra/views/new_memo.erb | 15 ++++++++++++++ 7 files changed, 55 insertions(+), 19 deletions(-) create mode 100644 try_sinatra/views/edit.erb delete mode 100644 try_sinatra/views/erb_and_md_template_page.markdown delete mode 100644 try_sinatra/views/markdown_template_page.markdown create mode 100644 try_sinatra/views/new_memo.erb diff --git a/try_sinatra/main.rb b/try_sinatra/main.rb index 10d3829f1d..22e77d7616 100644 --- a/try_sinatra/main.rb +++ b/try_sinatra/main.rb @@ -5,18 +5,17 @@ erb :index end -get '/path/to' do - "this is [/path/to]" -end - -get '/hello/*' do |name| - "hello #{name}. how are you?" +get '/items' do + erb :items end -get '/items' do |number| - erb :items +get '/new' do + erb :new_memo end +get '/items/edit' do + erb :edit +end # get '/erb_template_page' do # erb :erb_template_page diff --git a/try_sinatra/views/edit.erb b/try_sinatra/views/edit.erb new file mode 100644 index 0000000000..b34bcf8bbf --- /dev/null +++ b/try_sinatra/views/edit.erb @@ -0,0 +1,7 @@ +

Eddit memo

+
+ + + + +
\ No newline at end of file diff --git a/try_sinatra/views/erb_and_md_template_page.markdown b/try_sinatra/views/erb_and_md_template_page.markdown deleted file mode 100644 index 44bd51a1eb..0000000000 --- a/try_sinatra/views/erb_and_md_template_page.markdown +++ /dev/null @@ -1 +0,0 @@ -# this is erb_and_md.markdown \ No newline at end of file diff --git a/try_sinatra/views/index.erb b/try_sinatra/views/index.erb index 421af061fc..eee0464a42 100644 --- a/try_sinatra/views/index.erb +++ b/try_sinatra/views/index.erb @@ -1,10 +1,16 @@ - - - - - - Document - + + +メモ一覧
メモアプリ diff --git a/try_sinatra/views/items.erb b/try_sinatra/views/items.erb index 9f96b97ff2..1dab39ba40 100644 --- a/try_sinatra/views/items.erb +++ b/try_sinatra/views/items.erb @@ -3,11 +3,22 @@ - Items + 詳細 +
メモアプリ - +
+

memo1

+ +

メモの内容。メモの内容。
+ memo,memo,memo +

+
+ + + +
\ No newline at end of file diff --git a/try_sinatra/views/markdown_template_page.markdown b/try_sinatra/views/markdown_template_page.markdown deleted file mode 100644 index f2fda8d8bc..0000000000 --- a/try_sinatra/views/markdown_template_page.markdown +++ /dev/null @@ -1 +0,0 @@ -# this is markdown_template_page! \ No newline at end of file diff --git a/try_sinatra/views/new_memo.erb b/try_sinatra/views/new_memo.erb new file mode 100644 index 0000000000..54e964a456 --- /dev/null +++ b/try_sinatra/views/new_memo.erb @@ -0,0 +1,15 @@ + +

新規memo

+
+
+

タイトル:
+ +

+

メモ内容:
+ +

+

+ +

+
+
From 0788ab8299bb5ff49bc0852457c06dbcb7f71f3c Mon Sep 17 00:00:00 2001 From: jepe-w Date: Mon, 15 Apr 2024 14:28:33 +0900 Subject: [PATCH 04/12] =?UTF-8?q?chore/=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E5=90=8D=E3=80=81=E5=86=85=E5=AE=B9=E3=82=92=E8=AA=BF?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- try_sinatra/views/edit.erb | 2 +- .../views/erb_and_md_template_page.erb | 2 - try_sinatra/views/erb_template_page.erb | 1 - try_sinatra/views/index.erb | 47 +++++++++---------- try_sinatra/views/items.erb | 24 ---------- try_sinatra/views/layout.erb | 14 ++++++ try_sinatra/views/memo.erb | 9 ++++ try_sinatra/views/new_memo.erb | 2 +- 8 files changed, 47 insertions(+), 54 deletions(-) delete mode 100644 try_sinatra/views/erb_and_md_template_page.erb delete mode 100644 try_sinatra/views/erb_template_page.erb delete mode 100644 try_sinatra/views/items.erb create mode 100644 try_sinatra/views/layout.erb create mode 100644 try_sinatra/views/memo.erb diff --git a/try_sinatra/views/edit.erb b/try_sinatra/views/edit.erb index b34bcf8bbf..95d339a618 100644 --- a/try_sinatra/views/edit.erb +++ b/try_sinatra/views/edit.erb @@ -1,4 +1,4 @@ -

Eddit memo

+

Edit memo

diff --git a/try_sinatra/views/erb_and_md_template_page.erb b/try_sinatra/views/erb_and_md_template_page.erb deleted file mode 100644 index 25a1cc7595..0000000000 --- a/try_sinatra/views/erb_and_md_template_page.erb +++ /dev/null @@ -1,2 +0,0 @@ -<%= Time.now %>> -<%= markdown(:erb_and_md_template_page) %> diff --git a/try_sinatra/views/erb_template_page.erb b/try_sinatra/views/erb_template_page.erb deleted file mode 100644 index 013c74d12a..0000000000 --- a/try_sinatra/views/erb_template_page.erb +++ /dev/null @@ -1 +0,0 @@ -<%= Time.now %> diff --git a/try_sinatra/views/index.erb b/try_sinatra/views/index.erb index eee0464a42..76601aa5f4 100644 --- a/try_sinatra/views/index.erb +++ b/try_sinatra/views/index.erb @@ -1,30 +1,27 @@ -メモ一覧 - -
- メモアプリ -
- -
-
-
-
    -
  • メモ1
  • -
  • メモ2
  • -
  • メモ3
  • -
  • メモ4
  • -
-
- - + +# メモ一覧 +# +#
+# メモアプリ +#
+# +#
+#
+#
+#
    +#
  • メモ1
  • +#
  • メモ2
  • +#
  • メモ3
  • +#
  • メモ4
  • +#
+#
+# +# diff --git a/try_sinatra/views/items.erb b/try_sinatra/views/items.erb deleted file mode 100644 index 1dab39ba40..0000000000 --- a/try_sinatra/views/items.erb +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - 詳細 - - -
- メモアプリ - -
-

memo1

- -

メモの内容。メモの内容。
- memo,memo,memo -

-
- - - -
- - \ No newline at end of file diff --git a/try_sinatra/views/layout.erb b/try_sinatra/views/layout.erb new file mode 100644 index 0000000000..fcff92f7ad --- /dev/null +++ b/try_sinatra/views/layout.erb @@ -0,0 +1,14 @@ + + + + + + memo + + +
+

メモ

+ <%= yield %> +
+ + \ No newline at end of file diff --git a/try_sinatra/views/memo.erb b/try_sinatra/views/memo.erb new file mode 100644 index 0000000000..721cc425cb --- /dev/null +++ b/try_sinatra/views/memo.erb @@ -0,0 +1,9 @@ +
+

<%= @title %>

+ +

<%= @content %>

+

メモの内容。メモの内容。
+

+
+ +
diff --git a/try_sinatra/views/new_memo.erb b/try_sinatra/views/new_memo.erb index 54e964a456..70651d84ed 100644 --- a/try_sinatra/views/new_memo.erb +++ b/try_sinatra/views/new_memo.erb @@ -1,7 +1,7 @@

新規memo

- +

タイトル:

From 8d2795be29d6f9ddade819e464a7ac62c07c143e Mon Sep 17 00:00:00 2001 From: jepe-w Date: Tue, 16 Apr 2024 08:26:52 +0900 Subject: [PATCH 05/12] =?UTF-8?q?chore/=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E5=90=8D=E3=80=81=E5=86=85=E5=AE=B9=E3=82=92=E8=AA=BF?= =?UTF-8?q?=E6=95=B4=E3=80=81=E3=83=AB=E3=83=BC=E3=83=86=E3=82=A3=E3=83=B3?= =?UTF-8?q?=E3=82=B0=E3=81=AE=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- try_sinatra/main.rb | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/try_sinatra/main.rb b/try_sinatra/main.rb index 22e77d7616..69b35097a3 100644 --- a/try_sinatra/main.rb +++ b/try_sinatra/main.rb @@ -1,19 +1,31 @@ require 'sinatra' require 'sinatra/reloader' +# def set_memos(file_path, memos) +# File.open(file_path, 'w') { |f| JSON.dump(memos, f) } +# end + get '/' do - erb :index + redirect '/memos' end -get '/items' do - erb :items +get '/memos' do + @memos = get_memos(FILE_PATH) + erb :index end -get '/new' do +get '/memos/new' do erb :new_memo end -get '/items/edit' do +get '/memos/:id' do + memos = get_memos(FILE_PATH) + @title = memos[parms[:id]]['title'] + @content = memos[parms[:id]]['content'] + erb :memo +end + +get '/memos/memo/edit' do erb :edit end From 787378ec11f37c5b2f3072064de29c71d7cf3e75 Mon Sep 17 00:00:00 2001 From: jepe-w Date: Thu, 18 Apr 2024 09:37:14 +0900 Subject: [PATCH 06/12] =?UTF-8?q?json=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E3=81=AE=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- try_sinatra/main.rb | 36 +++++++++++++++++++++++++++++------ try_sinatra/public/memos.json | 1 + try_sinatra/views/index.erb | 27 ++++++-------------------- try_sinatra/views/layout.erb | 2 +- try_sinatra/views/memo.erb | 3 +-- 5 files changed, 39 insertions(+), 30 deletions(-) create mode 100644 try_sinatra/public/memos.json diff --git a/try_sinatra/main.rb b/try_sinatra/main.rb index 69b35097a3..24c111e065 100644 --- a/try_sinatra/main.rb +++ b/try_sinatra/main.rb @@ -1,9 +1,16 @@ require 'sinatra' require 'sinatra/reloader' +require 'json' -# def set_memos(file_path, memos) -# File.open(file_path, 'w') { |f| JSON.dump(memos, f) } -# end +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' @@ -20,15 +27,32 @@ get '/memos/:id' do memos = get_memos(FILE_PATH) - @title = memos[parms[:id]]['title'] - @content = memos[parms[:id]]['content'] + @title = memos[params[:id]]['title'] + @content = memos[params[:id]]['content'] erb :memo end -get '/memos/memo/edit' do +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 + + # get '/erb_template_page' do # erb :erb_template_page # end diff --git a/try_sinatra/public/memos.json b/try_sinatra/public/memos.json new file mode 100644 index 0000000000..67e6fe4296 --- /dev/null +++ b/try_sinatra/public/memos.json @@ -0,0 +1 @@ +{"1":{"title":"メモ1","content":"メモ1の内容"},"2":{"title":"メモ2","content":"メモ2の内容"},"3":{"title":"あああ","content":null}} \ No newline at end of file diff --git a/try_sinatra/views/index.erb b/try_sinatra/views/index.erb index 76601aa5f4..e788e8d6de 100644 --- a/try_sinatra/views/index.erb +++ b/try_sinatra/views/index.erb @@ -1,27 +1,12 @@ + -# メモ一覧 -# -#
-# メモアプリ -#
-# -#
-#
-#
-#
    -#
  • メモ1
  • -#
  • メモ2
  • -#
  • メモ3
  • -#
  • メモ4
  • -#
-#
-# -# diff --git a/try_sinatra/views/layout.erb b/try_sinatra/views/layout.erb index fcff92f7ad..e7a0417ae7 100644 --- a/try_sinatra/views/layout.erb +++ b/try_sinatra/views/layout.erb @@ -7,7 +7,7 @@
-

メモ

+

メモ一覧

<%= yield %>
diff --git a/try_sinatra/views/memo.erb b/try_sinatra/views/memo.erb index 721cc425cb..fd5b983f1c 100644 --- a/try_sinatra/views/memo.erb +++ b/try_sinatra/views/memo.erb @@ -2,8 +2,7 @@

<%= @title %>

<%= @content %>

-

メモの内容。メモの内容。

- + メモ一覧に戻る
From 034a2514efe977632c5a13d915018e9cbffd7ad0 Mon Sep 17 00:00:00 2001 From: jepe-w Date: Thu, 18 Apr 2024 17:04:27 +0900 Subject: [PATCH 07/12] =?UTF-8?q?=E6=96=B0=E8=A6=8F=E4=BD=9C=E6=88=90?= =?UTF-8?q?=E3=80=81=E7=B7=A8=E9=9B=86=E6=98=A8=E6=97=A5=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- try_sinatra/main.rb | 19 ++++++++++--------- try_sinatra/public/memos.json | 2 +- try_sinatra/views/edit.erb | 18 +++++++++++++----- try_sinatra/views/index.erb | 2 +- try_sinatra/views/layout.erb | 2 +- try_sinatra/views/memo.erb | 9 ++++++++- try_sinatra/views/new_memo.erb | 5 +++-- 7 files changed, 37 insertions(+), 20 deletions(-) diff --git a/try_sinatra/main.rb b/try_sinatra/main.rb index 24c111e065..c2f97aca9a 100644 --- a/try_sinatra/main.rb +++ b/try_sinatra/main.rb @@ -51,16 +51,17 @@ def set_memos(file_path, memos) 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) -# get '/erb_template_page' do -# erb :erb_template_page -# end + redirect "/memos/#{params[:id]}" +end -# get '/markdown_template_page' do -# markdown :markdown_template_page +# patch '/memo/1' do +# "Hello World" # end - -# get '/erb_and_md_template_page' do -# erb :erb_and_md_template_page -# end \ No newline at end of file diff --git a/try_sinatra/public/memos.json b/try_sinatra/public/memos.json index 67e6fe4296..b44b9faf8e 100644 --- a/try_sinatra/public/memos.json +++ b/try_sinatra/public/memos.json @@ -1 +1 @@ -{"1":{"title":"メモ1","content":"メモ1の内容"},"2":{"title":"メモ2","content":"メモ2の内容"},"3":{"title":"あああ","content":null}} \ No newline at end of file +{"1":{"title":"あああ","content":"あああああああああああ"},"2":{"title":"いいいいい","content":"いいいいいいいい"},"3":{"title":"うううう","content":"うう"},"4":{"title":"あああ","content":null},"5":{"title":"tttt","content":"ttttt"},"6":{"title":"あsdふぁdf","content":"ssssssssssssssssssssss"}} \ No newline at end of file diff --git a/try_sinatra/views/edit.erb b/try_sinatra/views/edit.erb index 95d339a618..870256ad00 100644 --- a/try_sinatra/views/edit.erb +++ b/try_sinatra/views/edit.erb @@ -1,7 +1,15 @@

Edit memo

- - - - - + +
+

タイトル

+ +
+
+

内容

+ +
+
+ + +
\ No newline at end of file diff --git a/try_sinatra/views/index.erb b/try_sinatra/views/index.erb index e788e8d6de..895cad9b67 100644 --- a/try_sinatra/views/index.erb +++ b/try_sinatra/views/index.erb @@ -1,6 +1,6 @@
    <% @memos.each do |id, post| %> diff --git a/try_sinatra/views/layout.erb b/try_sinatra/views/layout.erb index e7a0417ae7..e3b8e2a475 100644 --- a/try_sinatra/views/layout.erb +++ b/try_sinatra/views/layout.erb @@ -7,7 +7,7 @@
    -

    メモ一覧

    +

    メモアプリ

    <%= yield %>
    diff --git a/try_sinatra/views/memo.erb b/try_sinatra/views/memo.erb index fd5b983f1c..0eb74ba23a 100644 --- a/try_sinatra/views/memo.erb +++ b/try_sinatra/views/memo.erb @@ -1,8 +1,15 @@
    -

    <%= @title %>

    +

    タイトル

    +

    <%= @title %>

    +

    内容

    <%= @content %>

    +
    +
    + +
    +
    diff --git a/try_sinatra/views/new_memo.erb b/try_sinatra/views/new_memo.erb index 70651d84ed..d118eee77c 100644 --- a/try_sinatra/views/new_memo.erb +++ b/try_sinatra/views/new_memo.erb @@ -1,14 +1,15 @@ -

    新規memo

    +

    新しいメモを作成

    タイトル:

    メモ内容:
    - +

    + 戻る

    From 928f4cbb09a573d26c2d39b2a675ee5a844fa0f0 Mon Sep 17 00:00:00 2001 From: jepe-w Date: Fri, 19 Apr 2024 09:19:56 +0900 Subject: [PATCH 08/12] =?UTF-8?q?=E3=82=B9=E3=82=BF=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- try_sinatra/public/memos.json | 2 +- try_sinatra/public/styles.css | 6 ++++++ try_sinatra/views/index.erb | 2 +- try_sinatra/views/new_memo.erb | 14 +++++++------- 4 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 try_sinatra/public/styles.css diff --git a/try_sinatra/public/memos.json b/try_sinatra/public/memos.json index b44b9faf8e..6749d938e1 100644 --- a/try_sinatra/public/memos.json +++ b/try_sinatra/public/memos.json @@ -1 +1 @@ -{"1":{"title":"あああ","content":"あああああああああああ"},"2":{"title":"いいいいい","content":"いいいいいいいい"},"3":{"title":"うううう","content":"うう"},"4":{"title":"あああ","content":null},"5":{"title":"tttt","content":"ttttt"},"6":{"title":"あsdふぁdf","content":"ssssssssssssssssssssss"}} \ No newline at end of file +{"1":{"title":"あああ","content":"あああああああああああ"},"2":{"title":"いいいいい","content":"いいいいいいいい"},"3":{"title":"うううう","content":"うう"},"4":{"title":"あああ","content":null},"5":{"title":"tttt","content":"ttttt"},"6":{"title":"あsdふぁdf","content":"ssssssssssssssssssssss"},"7":{"title":"テスト","content":"入力テスト"}} \ No newline at end of file diff --git a/try_sinatra/public/styles.css b/try_sinatra/public/styles.css new file mode 100644 index 0000000000..55d3807975 --- /dev/null +++ b/try_sinatra/public/styles.css @@ -0,0 +1,6 @@ +text-box { + border:1px solid #999; + border-radius:3px; + background-color:#eee; + color:white +} \ No newline at end of file diff --git a/try_sinatra/views/index.erb b/try_sinatra/views/index.erb index 895cad9b67..2e1de2775a 100644 --- a/try_sinatra/views/index.erb +++ b/try_sinatra/views/index.erb @@ -1,6 +1,6 @@
      <% @memos.each do |id, post| %> diff --git a/try_sinatra/views/new_memo.erb b/try_sinatra/views/new_memo.erb index d118eee77c..c922804140 100644 --- a/try_sinatra/views/new_memo.erb +++ b/try_sinatra/views/new_memo.erb @@ -1,16 +1,16 @@ -

      新しいメモを作成

      +

      新しいメモを作成

      -

      タイトル:
      - +

      タイトル
      +

      -

      メモ内容:
      - +

      メモ内容
      +

      - 戻る - + ≪ 戻る +

      From 3d1be8d99b9dbd4f8231f2b0eea97ff220ab663a Mon Sep 17 00:00:00 2001 From: jepe-w Date: Tue, 23 Apr 2024 08:29:53 +0900 Subject: [PATCH 09/12] =?UTF-8?q?=E5=89=8A=E9=99=A4=E6=A9=9F=E8=83=BD?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- try_sinatra/Gemfile | 14 +++---- try_sinatra/README.md | 0 try_sinatra/main.rb | 51 +++++++++++++---------- try_sinatra/public/memos.json | 2 +- try_sinatra/public/style.css | 74 ++++++++++++++++++++++++++++++++++ try_sinatra/public/styles.css | 6 --- try_sinatra/views/edit.erb | 15 +++---- try_sinatra/views/index.erb | 16 ++++---- try_sinatra/views/layout.erb | 7 ++-- try_sinatra/views/memo.erb | 27 ++++++++----- try_sinatra/views/new_memo.erb | 18 ++++----- 11 files changed, 157 insertions(+), 73 deletions(-) create mode 100644 try_sinatra/README.md create mode 100644 try_sinatra/public/style.css delete mode 100644 try_sinatra/public/styles.css diff --git a/try_sinatra/Gemfile b/try_sinatra/Gemfile index 8cc20cc7b8..b7cbd96dc9 100644 --- a/try_sinatra/Gemfile +++ b/try_sinatra/Gemfile @@ -1,11 +1,11 @@ # frozen_string_literal: true -source "https://rubygems.org" +source 'https://rubygems.org' # gem "rails" -gem "sinatra" -gem "webrick" -gem "rackup" -gem "puma" -gem "sinatra-contrib" -gem "redcarpet" +gem 'puma' +gem 'rackup' +gem 'redcarpet' +gem 'sinatra' +gem 'sinatra-contrib' +gem 'webrick' diff --git a/try_sinatra/README.md b/try_sinatra/README.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/try_sinatra/main.rb b/try_sinatra/main.rb index c2f97aca9a..12e194105a 100644 --- a/try_sinatra/main.rb +++ b/try_sinatra/main.rb @@ -1,6 +1,9 @@ +# frozen_string_literal: true + require 'sinatra' require 'sinatra/reloader' require 'json' +require 'cgi' FILE_PATH = 'public/memos.json' @@ -13,42 +16,42 @@ def set_memos(file_path, memos) end get '/' do - redirect '/memos' + redirect '/memos' end get '/memos' do - @memos = get_memos(FILE_PATH) - erb :index + @memos = get_memos(FILE_PATH) + erb :index end get '/memos/new' do - erb :new_memo + 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 + 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] + 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) + 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' + 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 + memos = get_memos(FILE_PATH) + @title = memos[params[:id]]['title'] + @content = memos[params[:id]]['content'] + erb :edit end patch '/memos/:id' do @@ -62,6 +65,10 @@ def set_memos(file_path, memos) redirect "/memos/#{params[:id]}" end -# patch '/memo/1' do -# "Hello World" -# 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/try_sinatra/public/memos.json b/try_sinatra/public/memos.json index 6749d938e1..ad672c3e09 100644 --- a/try_sinatra/public/memos.json +++ b/try_sinatra/public/memos.json @@ -1 +1 @@ -{"1":{"title":"あああ","content":"あああああああああああ"},"2":{"title":"いいいいい","content":"いいいいいいいい"},"3":{"title":"うううう","content":"うう"},"4":{"title":"あああ","content":null},"5":{"title":"tttt","content":"ttttt"},"6":{"title":"あsdふぁdf","content":"ssssssssssssssssssssss"},"7":{"title":"テスト","content":"入力テスト"}} \ No newline at end of file +{"1":{"title":"あああ","content":"あああああああああああ"},"2":{"title":"いいいいい","content":"いいいいいいいい"},"3":{"title":"うううう","content":"うう"},"4":{"title":"今日の晩御飯","content":"カレーを作る\r\nそのために買い物をする\r\nカレールー\r\nジャガイモ\r\n人参\r\n肉\r\nたまねぎ"},"5":{"title":"tttt","content":"ttttt"},"6":{"title":"tekisutotekisuto","content":"aaaaaa\r\naaaaaaa\r\ntext\r\ntex\r\nte\r\nt\r\n"}} \ No newline at end of file diff --git a/try_sinatra/public/style.css b/try_sinatra/public/style.css new file mode 100644 index 0000000000..ef155cb96e --- /dev/null +++ b/try_sinatra/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:5px 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/try_sinatra/public/styles.css b/try_sinatra/public/styles.css deleted file mode 100644 index 55d3807975..0000000000 --- a/try_sinatra/public/styles.css +++ /dev/null @@ -1,6 +0,0 @@ -text-box { - border:1px solid #999; - border-radius:3px; - background-color:#eee; - color:white -} \ No newline at end of file diff --git a/try_sinatra/views/edit.erb b/try_sinatra/views/edit.erb index 870256ad00..216318ae6c 100644 --- a/try_sinatra/views/edit.erb +++ b/try_sinatra/views/edit.erb @@ -1,15 +1,16 @@ -

      Edit memo

      +

      メモの内容を編集

      -

      タイトル

      - +

      タイトル

      +
      -

      内容

      - +

      内容

      +
      - +
      -
      \ No newline at end of file + +≪メモに戻る diff --git a/try_sinatra/views/index.erb b/try_sinatra/views/index.erb index 2e1de2775a..272fa427c0 100644 --- a/try_sinatra/views/index.erb +++ b/try_sinatra/views/index.erb @@ -1,12 +1,12 @@ - + メモを追加 +
    diff --git a/try_sinatra/views/layout.erb b/try_sinatra/views/layout.erb index e3b8e2a475..e9ef83050c 100644 --- a/try_sinatra/views/layout.erb +++ b/try_sinatra/views/layout.erb @@ -3,12 +3,13 @@ + memo -
    -

    メモアプリ

    +
    +

    メモアプリ

    <%= yield %>
    - \ No newline at end of file + diff --git a/try_sinatra/views/memo.erb b/try_sinatra/views/memo.erb index 0eb74ba23a..715be7015b 100644 --- a/try_sinatra/views/memo.erb +++ b/try_sinatra/views/memo.erb @@ -1,15 +1,22 @@
    -

    タイトル

    -

    <%= @title %>

    -

    内容

    -

    <%= @content %>

    +

    タイトル +

    <%= CGI.escapeHTML(@title) %>

    +

    + +

    内容 +

    <%= CGI.escapeHTML(@content) %>

    +

    -
    +

    - +
    -
    - +

    +

    +

    + + +
    +

    +≪メモ一覧に戻る diff --git a/try_sinatra/views/new_memo.erb b/try_sinatra/views/new_memo.erb index c922804140..71479f20d3 100644 --- a/try_sinatra/views/new_memo.erb +++ b/try_sinatra/views/new_memo.erb @@ -1,16 +1,16 @@ -

    新しいメモを作成

    +

    新しいメモを作成

    -

    タイトル
    - -

    -

    メモ内容
    - -

    +

    タイトル
    + +

    +

    メモ内容
    + +

    - ≪ 戻る - +

    + ≪メモ一覧に戻る
    From ecd5a637532ae51185be6f355c9f1be93d32b09a Mon Sep 17 00:00:00 2001 From: jepe-w Date: Tue, 23 Apr 2024 11:52:46 +0900 Subject: [PATCH 10/12] =?UTF-8?q?readmefile=E4=BD=9C=E6=88=90=E3=80=82?= =?UTF-8?q?=E3=83=87=E3=82=A3=E3=83=AC=E3=82=AF=E3=83=88=E3=83=AA=E5=90=8D?= =?UTF-8?q?=E3=82=92memo=5Fapp=E3=81=AB=E5=A4=89=E6=9B=B4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- memo_app/.erb-lint.yml | 5 ++ memo_app/.ruby-version | 1 + memo_app/Gemfile | 12 ++++ memo_app/Gemfile.lock | 132 ++++++++++++++++++++++++++++++++++++ memo_app/README.md | 25 +++++++ memo_app/main.rb | 74 ++++++++++++++++++++ memo_app/public/memos.json | 1 + memo_app/public/style.css | 74 ++++++++++++++++++++ memo_app/public/test.html | 1 + memo_app/views/edit.erb | 15 ++++ memo_app/views/index.erb | 12 ++++ memo_app/views/layout.erb | 15 ++++ memo_app/views/memo.erb | 21 ++++++ memo_app/views/new_memo.erb | 16 +++++ 14 files changed, 404 insertions(+) create mode 100644 memo_app/.erb-lint.yml create mode 100644 memo_app/.ruby-version create mode 100644 memo_app/Gemfile create mode 100644 memo_app/Gemfile.lock create mode 100644 memo_app/README.md create mode 100644 memo_app/main.rb create mode 100644 memo_app/public/memos.json create mode 100644 memo_app/public/style.css create mode 100644 memo_app/public/test.html create mode 100644 memo_app/views/edit.erb create mode 100644 memo_app/views/index.erb create mode 100644 memo_app/views/layout.erb create mode 100644 memo_app/views/memo.erb create mode 100644 memo_app/views/new_memo.erb 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..7d313aa6b6 --- /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たまねぎ"},"5":{"title":"tttt","content":"ttttt"},"6":{"title":"tekisutotekisuto","content":"aaaaaa\r\naaaaaaa\r\ntext\r\ntex\r\nte\r\nt\r\n"}} \ 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..625dd2c997 --- /dev/null +++ b/memo_app/views/edit.erb @@ -0,0 +1,15 @@ +

    メモの内容を編集

    +
    +
    +

    タイトル

    + + +

    内容

    + +
    +
    +
    + + +
    +≪メモに戻る diff --git a/memo_app/views/index.erb b/memo_app/views/index.erb new file mode 100644 index 0000000000..08a33db0bd --- /dev/null +++ b/memo_app/views/index.erb @@ -0,0 +1,12 @@ + +
    +

    メモ一覧

    + + メモを追加 +
    diff --git a/memo_app/views/layout.erb b/memo_app/views/layout.erb new file mode 100644 index 0000000000..857711420f --- /dev/null +++ b/memo_app/views/layout.erb @@ -0,0 +1,15 @@ + + + + + + + memo + + +
    +

    メモアプリ

    + <%= yield %> +
    + + diff --git a/memo_app/views/memo.erb b/memo_app/views/memo.erb new file mode 100644 index 0000000000..d0f183cb74 --- /dev/null +++ b/memo_app/views/memo.erb @@ -0,0 +1,21 @@ +
    +

    タイトル +

    <%= CGI.escapeHTML(@title) %>

    +

    + +

    内容 +

    <%= CGI.escapeHTML(@content) %>

    +

    +
    +
    +
    + +
    +
    +
    +
    + + +
    +
    +≪メモ一覧に戻る diff --git a/memo_app/views/new_memo.erb b/memo_app/views/new_memo.erb new file mode 100644 index 0000000000..c5a33ab2d8 --- /dev/null +++ b/memo_app/views/new_memo.erb @@ -0,0 +1,16 @@ + +

    新しいメモを作成

    +
    +
    +

    タイトル
    + +

    +

    メモ内容
    + +

    +
    +
    + +
    + ≪メモ一覧に戻る +
    From a1a9684db3b1b8070a38161e16992ad402a990cc Mon Sep 17 00:00:00 2001 From: jepe-w Date: Tue, 23 Apr 2024 13:36:50 +0900 Subject: [PATCH 11/12] =?UTF-8?q?=E5=89=8A=E9=99=A4=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=82=A4=E3=83=AB=E3=82=92=E3=82=B3=E3=83=9F=E3=83=83=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- try_sinatra/Gemfile | 11 ----- try_sinatra/Gemfile.lock | 49 ---------------------- try_sinatra/README.md | 0 try_sinatra/main.rb | 74 ---------------------------------- try_sinatra/public/memos.json | 1 - try_sinatra/public/style.css | 74 ---------------------------------- try_sinatra/public/test.html | 1 - try_sinatra/views/edit.erb | 16 -------- try_sinatra/views/index.erb | 12 ------ try_sinatra/views/layout.erb | 15 ------- try_sinatra/views/memo.erb | 22 ---------- try_sinatra/views/new_memo.erb | 16 -------- 12 files changed, 291 deletions(-) delete mode 100644 try_sinatra/Gemfile delete mode 100644 try_sinatra/Gemfile.lock delete mode 100644 try_sinatra/README.md delete mode 100644 try_sinatra/main.rb delete mode 100644 try_sinatra/public/memos.json delete mode 100644 try_sinatra/public/style.css delete mode 100644 try_sinatra/public/test.html delete mode 100644 try_sinatra/views/edit.erb delete mode 100644 try_sinatra/views/index.erb delete mode 100644 try_sinatra/views/layout.erb delete mode 100644 try_sinatra/views/memo.erb delete mode 100644 try_sinatra/views/new_memo.erb diff --git a/try_sinatra/Gemfile b/try_sinatra/Gemfile deleted file mode 100644 index b7cbd96dc9..0000000000 --- a/try_sinatra/Gemfile +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -source 'https://rubygems.org' - -# gem "rails" -gem 'puma' -gem 'rackup' -gem 'redcarpet' -gem 'sinatra' -gem 'sinatra-contrib' -gem 'webrick' diff --git a/try_sinatra/Gemfile.lock b/try_sinatra/Gemfile.lock deleted file mode 100644 index 62f67041b2..0000000000 --- a/try_sinatra/Gemfile.lock +++ /dev/null @@ -1,49 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - base64 (0.2.0) - multi_json (1.15.0) - mustermann (3.0.0) - ruby2_keywords (~> 0.0.1) - nio4r (2.7.1) - puma (6.4.2) - nio4r (~> 2.0) - 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) - redcarpet (3.6.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) - tilt (2.3.0) - webrick (1.8.1) - -PLATFORMS - x86_64-linux - -DEPENDENCIES - puma - rackup - redcarpet - sinatra - sinatra-contrib - webrick - -BUNDLED WITH - 2.4.10 diff --git a/try_sinatra/README.md b/try_sinatra/README.md deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/try_sinatra/main.rb b/try_sinatra/main.rb deleted file mode 100644 index 12e194105a..0000000000 --- a/try_sinatra/main.rb +++ /dev/null @@ -1,74 +0,0 @@ -# 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/try_sinatra/public/memos.json b/try_sinatra/public/memos.json deleted file mode 100644 index ad672c3e09..0000000000 --- a/try_sinatra/public/memos.json +++ /dev/null @@ -1 +0,0 @@ -{"1":{"title":"あああ","content":"あああああああああああ"},"2":{"title":"いいいいい","content":"いいいいいいいい"},"3":{"title":"うううう","content":"うう"},"4":{"title":"今日の晩御飯","content":"カレーを作る\r\nそのために買い物をする\r\nカレールー\r\nジャガイモ\r\n人参\r\n肉\r\nたまねぎ"},"5":{"title":"tttt","content":"ttttt"},"6":{"title":"tekisutotekisuto","content":"aaaaaa\r\naaaaaaa\r\ntext\r\ntex\r\nte\r\nt\r\n"}} \ No newline at end of file diff --git a/try_sinatra/public/style.css b/try_sinatra/public/style.css deleted file mode 100644 index ef155cb96e..0000000000 --- a/try_sinatra/public/style.css +++ /dev/null @@ -1,74 +0,0 @@ -.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:5px 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/try_sinatra/public/test.html b/try_sinatra/public/test.html deleted file mode 100644 index fa8c22aea5..0000000000 --- a/try_sinatra/public/test.html +++ /dev/null @@ -1 +0,0 @@ -this is html file . diff --git a/try_sinatra/views/edit.erb b/try_sinatra/views/edit.erb deleted file mode 100644 index 216318ae6c..0000000000 --- a/try_sinatra/views/edit.erb +++ /dev/null @@ -1,16 +0,0 @@ -

    メモの内容を編集

    -
    -
    -

    タイトル

    - -
    -
    -

    内容

    - -
    -
    - - -
    -
    -≪メモに戻る diff --git a/try_sinatra/views/index.erb b/try_sinatra/views/index.erb deleted file mode 100644 index 272fa427c0..0000000000 --- a/try_sinatra/views/index.erb +++ /dev/null @@ -1,12 +0,0 @@ - -
    -

    メモ一覧

    - - メモを追加 -
    diff --git a/try_sinatra/views/layout.erb b/try_sinatra/views/layout.erb deleted file mode 100644 index e9ef83050c..0000000000 --- a/try_sinatra/views/layout.erb +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - memo - - -
    -

    メモアプリ

    - <%= yield %> -
    - - diff --git a/try_sinatra/views/memo.erb b/try_sinatra/views/memo.erb deleted file mode 100644 index 715be7015b..0000000000 --- a/try_sinatra/views/memo.erb +++ /dev/null @@ -1,22 +0,0 @@ -
    - -

    タイトル -

    <%= CGI.escapeHTML(@title) %>

    -

    - -

    内容 -

    <%= CGI.escapeHTML(@content) %>

    -

    -
    -

    -

    - -
    -

    -

    -

    - - -
    -

    -≪メモ一覧に戻る diff --git a/try_sinatra/views/new_memo.erb b/try_sinatra/views/new_memo.erb deleted file mode 100644 index 71479f20d3..0000000000 --- a/try_sinatra/views/new_memo.erb +++ /dev/null @@ -1,16 +0,0 @@ - -

    新しいメモを作成

    -
    -
    -

    タイトル
    - -

    -

    メモ内容
    - -

    -

    - -

    -
    - ≪メモ一覧に戻る -
    From 600f4278e65ebf26cf61e7bc729bc9f47127ce28 Mon Sep 17 00:00:00 2001 From: jepe-w Date: Tue, 23 Apr 2024 13:48:14 +0900 Subject: [PATCH 12/12] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E3=83=9C=E3=82=BF?= =?UTF-8?q?=E3=83=B3=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 保存ボタンが効かないと思ったら、なぜかformの外に出していたため、修正 --- memo_app/public/memos.json | 2 +- memo_app/views/edit.erb | 6 +++--- memo_app/views/new_memo.erb | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/memo_app/public/memos.json b/memo_app/public/memos.json index 7d313aa6b6..af8bd67d65 100644 --- a/memo_app/public/memos.json +++ b/memo_app/public/memos.json @@ -1 +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たまねぎ"},"5":{"title":"tttt","content":"ttttt"},"6":{"title":"tekisutotekisuto","content":"aaaaaa\r\naaaaaaa\r\ntext\r\ntex\r\nte\r\nt\r\n"}} \ No newline at end of file +{"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/views/edit.erb b/memo_app/views/edit.erb index 625dd2c997..b69f12aa81 100644 --- a/memo_app/views/edit.erb +++ b/memo_app/views/edit.erb @@ -7,9 +7,9 @@

    内容

    -
    - - + +
    + ≪メモに戻る diff --git a/memo_app/views/new_memo.erb b/memo_app/views/new_memo.erb index c5a33ab2d8..a4959971b5 100644 --- a/memo_app/views/new_memo.erb +++ b/memo_app/views/new_memo.erb @@ -8,9 +8,9 @@

    メモ内容

    -
    - +
    + ≪メモ一覧に戻る