Advertisement
  1. Code
  2. CMS

สร้าง CMS: rubyPress

Scroll to top
Read Time: 10 min

Thai (ภาษาไทย) translation by Muhammad Gufron (you can also view the original English article)

หลังจากสร้างเนื้อหาการจัดการระบบ(CMS)โครงสร้างพื้นฐานแล้วและแท้จริงเซิร์ฟเวอร์โดยใช้ไปแล้ว Node.js คุณพร้อมที่จะพยายามของคุณมือของที่อื่นภาษานะ

เวลานี้ฉันกำลังใช้ปัญญาอ่อนภาษาสร้างเครื่องเซิร์ฟเวอร์ ฉันต้องเจอโดยสร้างโปรแกรมเหมือนกันในหลายภาษาเธอเริ่มได้ใหม่บนวิธีที่ต้อนรับคำสั่งเข้าใจคนโปรแกรม คุณยังเห็นอีกวิธีที่จะเพิ่ม functionality ต้องโปรแกรม เรามาเริ่มกันเลย

ตั้งค่าและการเรียกใช้ไลบรารี

ต้องโปรแกรมในรูบี้คุณจะต้องได้เวอร์ชั่นล่าสุดถูกติดตั้งไว้ในระบบของคุณ หลายปฏิบัติการระบบมาก่อน-ถูกติดตั้งไว้กับรูบี้วันนี้(ระบบลินุกซ์และ O X)แต่พวกเขามักจะมีอายุรุ่นนี้ นี่ comment นคิดเอาเองว่าคุณมีรูบี้รุ่น 2.4 น

ทางที่ง่ายที่สุดที่จะอัพเกรดไปที่เวอร์ชั่นล่าสุดของรูบี้เป็นต้องใช้ RVM น ที่จะติดตั้ง RVM บนระบบลินุกซ์หรือ comment ประเภทต่อไปนี้ในเทอร์มินัล:

1
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
2
curl -sSL https://get.rvm.io | bash -s stable

รายการนี้จะทำการสร้างความปลอดภัยไว้ซึ่งการเชื่อมต่อดาวน์โหลและแต่งตั้ง RVM น นี่ installs ล่าสุดที่มั่นคงปล่อยตัวของรูบี้ด้วย คุณจะต้องเรียกใหม่ของเชลล์ให้เสร็จการติดตั้ง

สำหรับหน้าต่างคุณสามารถดาวน์โหลดหน้าต่างรูบี้ติดตั้ง ตอนนี้,แพกเกจนี้ขึ้นอยู่กับรูบี้ 2.2.2 ซึ่งจะปกครองไลบรารีแบบใช้ร่งและสคริปต์ในหัดเล่นนะ

เมื่อภาษารูบี้เป็นเหมาะสมที่ติดตั้ง,คุณสามารถตอนนี้ติดตั้งไลบรารีแบบใช้ร่ว รูบี้เหมือนที่ไปและโหนดมีจัดการแพ็คเกจสำหรับกำลังติดตั้งสามงานไลบรารีแบบใช้ร่ว ในเทอร์มินัลประเภทต่อไปนี้:

1
gem install sinatra
2
gem install ruby-handlebars
3
gem install kramdown
4
gem install slim

นี่ installs ที่ Sinatra รูบี้ Handlebars,Kramdown และเพียงน้อยบรรณารักษ์นะ Sinatra เป็นเว็บโปรแกรมเฟรมเวิร์กนะ รูบี้ Handlebars implements ที่ Handlebars templating เครื่องยนต์ในรูบี้ Kramdown เป็น Markdown ต้อง HTML converter น เพียงน้อยคือ Jade ทำงาน-เหมือนกันสมุดแต่มันก็ไม่ได้รวมเป็น Jade ว้างความหมายของคำน ดังนั้นเพิ่มมาสก์เคยอยู่ในข่าวและโพสในบล็อกขอ indexes ตอนนี้ปกติ Jade น

กำลังสร้างค rubyPress นrb แฟ้ม

ด้านบนไดเรกทอรี,การสร้างแฟ้ม rubyPress นrb และเพิ่มตามรหัส. ฉันจะออกความเห็นเรื่องแต่ละส่วนอย่างที่มันเพิ่มไปยังแฟ้ม

1
#

2
# Load the Libraries.

3
#

4
require 'sinatra'  		# https://www.sinatrarb.com/

5
require 'ruby-handlebars' 	# https://github.com/vincent-psarga/ruby-handlebars

6
require 'kramdown' 			# http://kramdown.gettalong.org

7
require 'slim' 				# http://slim-lang.com/

8
require 'json'
9
require 'date'

สิ่งแรกที่ต้องทำคือการเรียกใช้งานไลบรารีแบบใช้ร่ว ไม่เหมือนกับ Node.js นี่ไม่ใช่โหลดเข้าไปในตัวแปรได้ รูบี้ไลบรารีแบบใช้ร่เพิ่มพวกเขาฟังก์ชันที่ต้องโปรแกรมขอบเขตนะ

1
#

2
# Setup the Handlebars engine.

3
#

4
$hbs = Handlebars::Handlebars.new
5
6
#

7
# HandleBars Helper:   date

8
#

9
# Description:         This helper returns the current date

10
#                      based on the format given.

11
#

12
$hbs.register_helper('date') {|context, format|
13
	now = Date.today
14
	now.strftime(format)
15
}
16
17
#

18
# HandleBars Helper:   cdate

19
#

20
# Description:         This helper returns the given date

21
#                      based on the format given.

22
#

23
$hbs.register_helper('cdate') {|context, date, format|
24
	day = Date.parse(date)
25
	day.strftime(format)
26
}
27
28
#

29
# HandleBars Helper:   save

30
#

31
# Description:         This helper expects a

32
#                      "|" where the name

33
#                      is saved with the value for future

34
#                      expansions. It also returns the

35
#                      value directly.

36
#

37
$hbs.register_helper('save') {|context, name, text|
38
	#

39
	# If the text parameter isn't there, then it is the 

40
	# goPress format all combined into the name. Split it 

41
	# out. The parameters are not String objects. 

42
	# Therefore, they need converted first.

43
	#

44
	name = String.try_convert(name)
45
	if name.count("|") > 0
46
		parts = name.split('|')
47
		name = parts[0]
48
		text = parts[1]
49
	end
50
51
	#

52
	# Register the new helper.

53
	#

54
	$hbs.register_helper(name) {|context, value|
55
		text
56
	}
57
58
	#

59
	# Return the text.

60
	#

61
	text
62
}

ที่ Handlebars องสมุดจะสามารถใช้ถอนกับที่ต่างออกช่วยฟังก์ชันที่ได้ถูกกำหนดไว้ ที่ช่วยฟังก์ชันที่กำหนดไว้เป็นวัน cdate และบันทึก

วันที่ช่วยฟังก์ชันต้องใช้ควันและเวลาปัจจุบันและรูปแบบมันตามรูปแบบข้อความผ่านไปเพื่อผู้ช่วย cdate เป็นที่คล้ายกันยกเว้นผ่านไปวันก่อน ที่บันทึกช่วยทำงานอนุญาตให้คุณกำหนดชื่อของและค่าย มันสร้างขึ้นใหม่ช่วยทำงานกับชื่อของชื่อและผ่านกลับมาที่ค่าย นี่จะอนุญาตให้คุณสร้างตัวแปรที่มีการกำหนดไว้ครั้งนึงและผลกระทบต่อหลายตำแหน่งของนะ ฟังก์ชันนี้ยังต้องไปเวอร์ชั่นซึ่งคาดหวังให้เป็นข้อความที่ชื่อ'|'เป็นเครื่องหมายแยกเลขหลักและค่าย

1
#

2
# Load Server Data.

3
#

4
$parts = {}
5
$parts = JSON.parse(File.read './server.json')
6
$styleDir = Dir.getwd + '/themes/styling/' + $parts['CurrentStyling']
7
$layoutDir = Dir.getwd + '/themes/layouts/' + $parts['CurrentLayout']
8
9
#

10
# Load the layouts and styles defaults.

11
#

12
$parts["layout"] = File.read $layoutDir + '/template.html'
13
$parts["404"] = File.read $styleDir + '/404.html'
14
$parts["footer"] = File.read $styleDir + '/footer.html'
15
$parts["header"] = File.read $styleDir + '/header.html'
16
$parts["sidebar"] = File.read $styleDir + '/sidebar.html'
17
18
#

19
# Load all the page parts in the parts directory.

20
#

21
Dir.entries($parts["Sitebase"] + '/parts/').select {|f|
22
	if !File.directory? f
23
		$parts[File.basename(f, ".*")] = File.read $parts["Sitebase"] + '/parts/' + f
24
	end
25
}
26
27
#

28
# Setup server defaults:

29
#

30
port = $parts["ServerAddress"].split(":")[2]
31
set :port, port

ต่อส่วนหนึ่งของรหัสสำหรับการโหลด cacheable รายการของเว็บไซต์นะ นี่คือทุกสิ่งทุกอย่างในรูปแบบและแผนผังของชุดตกแต่งและรายการในส่วนรายการย่อยของไดเรกทอรีได้ เป็นโกลบอลตัวแปร$เป็นส่วนครั้งแรกโหลดจากเซิร์ฟเวอร์language แฟ้ม ข้อมูลนั่นคืนนั้นเคยเรียนที่เหมาะสมรายการสำหรับผังแป้นพิมพ์และชุดตกแต่งการกำหนดไว้แล้ว ที่ Handlebars ต้นแบบเครื่องยนต์ใช้ข้อมูลนี้ให้เติมเต็มออกจากต้นแบบนี้

1
#

2
# Define the routes for the CMS.

3
#

4
get '/' do
5
  page "main"
6
end
7
8
get '/favicon.ico', :provides => 'ico' do
9
	File.read "#{$parts['Sitebase']}/images/favicon.ico"
10
end
11
12
get '/stylesheets.css', :provides => 'css'  do
13
	File.read "#{$parts["Sitebase"]}/css/final/final.css"
14
end
15
16
get '/scripts.js', :provides => 'js'  do
17
	File.read "#{$parts["Sitebase"]}/js/final/final.js"
18
end
19
20
get '/images/:image', :provides => 'image' do
21
	File.read "#{$parts['Sitebase']}/images/#{parms['image']}"
22
end
23
24
get '/posts/blogs/:blog' do
25
	post 'blogs', params['blog'], 'index'
26
end
27
28
get '/posts/blogs/:blog/:post' do
29
	post 'blogs', params['blog'], params['post']
30
end
31
32
get '/posts/news/:news' do
33
	post 'news', params['news'], 'index'
34
end
35
36
get '/posts/news/:news/:post' do
37
	post 'news', params['news'], params['post']
38
end
39
40
get '/:page' do
41
	page params['page']
42
end

ต่อส่วนบรรจุความหมายของคำสำหรับตลอดเส้นทางนี้ Sinatra คือพักผ่อนให้เต็มที่ compliant เซิร์ฟเวอร์ แต่สำหรับนี่ CMS ฉันจะเพียงใช้ได้ the grammatical type of a word น แต่ละเส้นทางเอารายการจากเส้นทางที่จะส่งไปให้คนฟังก์ชันเพื่อร่วมที่ถูกต้องหน้าอก ใน Sinatra เป็นชื่อของ preceded โดยลำไส้คนเรายาวกำหนดตำแหน่งที่จะใช้เป็นส่วนของเส้นทางที่จะส่งไปยังเส้นทางเครื่องมือจัดการได้ รายการเหล่านี้อยู่ใน params ค่อยจัดการเรื่องโต๊ะด้วย

1
#

2
# Various functions used in the making of the server:

3
#

4
5
#

6
# Function:    page

7
#

8
# Description: This function is for processing a page

9
#              in the CMS.

10
#

11
# Inputs:

12
# 				pg 	The page name to lookup

13
#

14
def page(pg)
15
	processPage $parts["layout"], "#{$parts["Sitebase"]}/pages/#{pg}"
16
end

หน้าฟังก์ชันจะได้ชื่อของหน้าอกจากเส้นทางและผ่านไปที่ผังแป้นพิมพ์ในเงินบางส่วนตัวแปรพร้อมกับพาธเต็มไปที่หน้าแฟ้มต้องการสำหรับฟังก์ชัน processPage น ที่ processPage ฟังก์ชันต้องใช้ข้อมูลและสร้างสถานที่ที่เหมาะสมองหน้าซึ่งมันก็จะกลับมา ในรูบี้คนส่งออกของสุดท้ายฟังก์ชันคือการหวนคืนค่าสำหรับฟังก์ชันนี้

1
#

2
# Function:    post

3
#

4
# Description: This function is for processing a post type

5
#              page in the CMS. All blog and news pages are

6
#    				post type pages.

7
#

8
# Inputs:

9
#              type   The type of the post

10
#              cat    The category of the post (blog, news)

11
#              post   The actual page of the post

12
#

13
def post(type, cat, post)
14
	processPage $parts["layout"], "#{$parts["Sitebase"]}/posts/#{type}/#{cat}/#{post}"
15
end

เหรอเบนมีใบคำให้การปฟังก์ชันเหมือนกับหน้าฟังก์ชันยกเว้นแต่ว่ามันได้ผลสำหรับทุกโพสประเภทหน้าอก ฟังก์ชันนี้คาดหวังให้คนโพสประเภทตั้งหมวดหมู่และกลับตัวมันเอง พวกนี้จะทำการสร้างที่อยู่ที่ถูกต้องหน้าเว็บเพื่อให้มีการแสดง

1
#

2
# Function:    figurePage

3
#

4
# Description: This function is to figure out the page

5
#              type (ie: markdown, HTML, jade, etc), read

6
#              the contents, and translate it to HTML.

7
#

8
# Inputs:

9
#              page      The address of the page 

10
#                        without its extension.

11
#

12
def figurePage(page)
13
	result = ""
14
15
	if File.exist? page + ".html"
16
		#

17
		# It's an HTML file.

18
		#

19
		result = File.read page + ".html"
20
	elsif File.exist? page + ".md"
21
		#

22
		# It's a markdown file.

23
		#

24
		result = Kramdown::Document.new(File.read page + ".md").to_html
25
26
		#

27
		# Fix the fancy quotes from Kramdown. It kills

28
		# the Handlebars parser.

29
		#

30
		result.gsub!("“","\"")
31
		result.gsub!("”","\"")
32
	elsif File.exist? page + ".amber"
33
		#

34
		# It's a jade file. Slim doesn't support

35
		# macros. Therefore, not as powerful as straight jade.

36
		# Also, we have to render any Handlebars first

37
		# since the Slim engine dies on them.

38
		#

39
		File.write("./tmp.txt",$hbs.compile(File.read page + ".amber").call($parts))
40
		result = Slim::Template.new("./tmp.txt").render()
41
	else
42
		#

43
		# Doesn't exist. Give the 404 page.

44
		#

45
		result = $parts["404"]
46
	end
47
48
	#

49
	# Return the results.

50
	#

51
	return result
52
end

ที่ figurePage ฟังก์ชันใช้ processPage ฟังก์ชันเพื่ออ่านหน้าเนื้อหาจากแฟ้มของระบบได้ ฟังก์ชันนี้อย่างเราได้รับคำขู่แบบนี้เต็มของพาธไปยังแฟ้มโดยไม่ต้องเลื่อนเวลาออกไปหน่อย figurePage งั้นการทดสอบสำหรับแฟ้มที่มีชื่อกับ html ส่วนขยายสำหรับอ่านข้อยังแฟ้ม HTML น ที่สองเลือกสำหรับแพทย์ส่วนขยายสำหรับ Markdown แฟ้ม

Lastly มัเช็คสำหรับแอมเบอร์ส่วนขยายสำหรับเป็น Jade แฟ้ม จำ:แอมเบอร์คือชื่อของห้องสมุดสำหรับการประมวลผล Jade แฟ้มในรูปแบบการสั่งงานไปแล้ว ฉันเก็บมันแบบเดียวกันกับอิน functionality น เป็นยังแฟ้ม HTML คือแค่ผ่านกลับมาในขณะที่ทุก Markdown และ Jade แฟ้มที่จะแปลงเอกสาร HTML ก่อนที่ผ่านกลับมา

ถ้าเป็นแฟ้มไม่ได้เจอผู้ใช้ที่จะได้รับกา 404 หน้าอก ทางนี้ของคุณ"หน้าไม่พบหน้าที่ดูเหมือนอื่นหน้ายกเว้นสำหรับเนื้อหาอยู่ภายใน

1
#

2
# Function:    processPage

3
#

4
# Description: The function processes a page by getting

5
#              its contents, combining with all the page

6
#              parts using Handlebars, and processing the

7
#              shortcodes.

8
#

9
# Inputs:

10
#              layout  The layout structure for the page

11
#              page    The complete path to the desired

12
#                      page without its extension.

13
#

14
def processPage(layout, page)
15
	#

16
	# Get the page contents and name.

17
	#

18
	$parts["content"] = figurePage page
19
	$parts["PageName"] = File.basename page
20
21
	#

22
	# Run the page through Handlebars engine.

23
	#

24
	begin
25
		pageHB = $hbs.compile(layout).call($parts)
26
	rescue
27
		pageHB = "

28
Render Error

29


30
"
31
	end
32
33
	#

34
	# Run the page through the shortcodes processor.

35
	#

36
	pageSH = processShortCodes pageHB
37
38
	#

39
	# Run the page through the Handlebar engine again.

40
	#

41
	begin
42
		pageFinal = $hbs.compile(pageSH).call($parts)
43
	rescue
44
		pageFinal = "

45
Render Error

46


47
" + pageSH
48
	end
49
50
	#

51
	# Return the results.

52
	#

53
	return pageFinal
54
end

ที่ processPage ฟังก์ชัน performs ทั้งหมดต้นแบบ expansions บหน้าข้อมูล มันจะเริ่มโดยการโทรหา figurePage ฟังก์ชันจะต้องไปที่หน้าของเนื้อหาย มันก็โพรเซสที่ผังแป้นพิมพ์ผ่านให้มันกับ Handlebars ต้องขยายรายการต้นแบบนี้

จากนั้นก็ processShortCode ฟังก์ชันจะหาและโพรเซสทั้งหมด shortcodes ในหน้าอก ได้ผลลัพธ์แล้วผ่านไป Handlebars สำหรับครั้งที่สองต้องการอะไรเพิ่มมาสก์เหลือโดย shortcodes น ผู้ใช้อย่างเราได้รับคำขู่แบบนี้คนสุดท้ายผลลัพธ์เดียวกันนั่นแหละ

1
#

2
# Function:    processShortCodes

3
#

4
# Description: This function takes the page and processes

5
#              all of the shortcodes in the page.

6
#

7
# Inputs:

8
#              page     The contents of the page to 

9
#                       process.

10
#

11
def processShortCodes(page)
12
	#

13
	# Initialize the result variable for returning.

14
	#

15
	result = ""
16
17
	#

18
	# Find the first shortcode

19
	#

20
	scregFind = /\-\[([^\]]*)\]\-/
21
	match1 = scregFind.match(page)
22
	if match1 != nil
23
		#

24
		# We found one! get the text before it

25
		# into the result variable and initialize

26
		# the name, param, and contents variables.

27
		#

28
		name = ""
29
		param = ""
30
		contents = ""
31
		nameLine = match1[1]
32
		loc1 = scregFind =~ page
33
		result = page[0, loc1]
34
35
		#

36
		# Separate out the nameLine into a shortcode

37
		# name and parameters.

38
		#

39
		match2 = /(\w+)(.*)*/.match(nameLine)
40
		if match2.length == 2
41
			#

42
			# Just a name was found.

43
			#

44
			name = match2[1]
45
		else
46
			#

47
			# A name and parameter were found.

48
			#

49
			name = match2[1]
50
			param = match2[2]
51
		end
52
53
		#

54
		# Find the closing shortcode

55
		#

56
		rest = page[loc1+match1[0].length, page.length]
57
		regEnd = Regexp.new("\\-\\[\\/#{name}\\]\\-")
58
		match3 = regEnd.match(rest)
59
		if match3 != nil
60
			#

61
			# Get the contents the tags enclose.

62
			#

63
			loc2 = regEnd =~ rest
64
			contents = rest[0, loc2]
65
66
			#

67
			# Search the contents for shortcodes.

68
			#

69
			contents = processShortCodes(contents)
70
71
			#

72
			# If the shortcode exists, run it and include

73
			# the results. Otherwise, add the contents to

74
			# the result.

75
			#

76
			if $shortcodes.include?(name)
77
				result += $shortcodes[name].call(param, contents)
78
			else
79
				result += contents
80
			end
81
82
			#

83
			# process the shortcodes in the rest of the

84
			# page.

85
			#

86
			rest = rest[loc2 + match3[0].length, page.length]
87
			result += processShortCodes(rest)
88
		else
89
			#

90
			# There wasn't a closure. Therefore, just 

91
			# send the page back.

92
			#

93
			result = page
94
		end
95
	else
96
		#

97
		# No shortcodes. Just return the page.

98
		#

99
		result = page
100
	end
101
102
	return result
103
end

ที่ processShortCodes ฟังก์ชันต้องใช้ข้อความรัก,เจอกัน shortcode แล้ววิ่งที่กำหนด shortcode กับอาร์กิวเมนต์และเนื้อหาของ shortcode น ฉันใช้ shortcode ประจำวันเพื่อระบวนการที่เนื้อหาสำหรับ shortcodes เช่นกัน

เป็น shortcode เป็น HTML-เหมือนป้ายกำกับที่ใช้-ไม่แล้ว-อยา delimit เป็นการเปิดแท็กกัน/แล้ว-ปิดป้ายกำกับนะ เป็นการเปิดแท็บรรจุสำหรับพารามิเตอร์ที่ shortcode เช่นกัน เพราะฉะนั้นเป็นตัวอย่าง shortcode จะเป็น:

1
-[box]-
2
This is inside a box.
3
-[/box]-

นี่ shortcode กำหนกล่องที่ shortcode นโดยที่ไม่มีพารามิเตอร์กับที่เนื้อหาของนี่มันอยู่ในกล่องน กล่องที่ shortcode ลุงเนื้อหาของที่เหมาะสม HTML ที่จะแสดงกล่องรอบๆข้อความกับข้อความจัดกึ่งกลางในกล่อง ถ้าคุณทีหลังต้องการจะเปลี่ยนแปลงในกล่องต้องเป็นค่าการแสดงผลคุณก็แค่ต้องเปลี่ยนนิยามของ shortcode น นี่ถูกต้องสามารถช่วยผู้พันอาร์ชวู้ดไปหาสตาร์เบิร์น

1
#

2
# Data Structure:  $shortcodes

3
#

4
# Description:     This data structure contains all

5
#                  the valid shortcodes names and the

6
#                  function. All shortcodes should

7
#                  receive the arguments and the

8
#                  that the shortcode encompasses.

9
#

10
$shortcodes = {
11
	"box" => lambda { |args, contents|
12
		return("#{contents}")
13
	},
14
   'Column1'=> lambda { |args, contents|
15
		return("#{contents}")
16
   },
17
   'Column2' => lambda { |args, contents|
18
      return("#{contents}")
19
   },
20
   'Column1of3' => lambda { |args, contents|
21
      return("#{contents}")
22
   },
23
   'Column2of3' => lambda { |args, contents|
24
      return("#{contents}")
25
   },
26
   'Column3of3' => lambda { |args, contents|
27
      return("#{contents}")
28
   },
29
   'php' => lambda { |args, contents|
30
      return("#{contents}") }, 'js' => lambda { |args, contents| return("#{contents}") }, "html" => lambda { |args, contents| return("#{contents}") }, 'css' => lambda {|args, contents| return("#{contents}") } }

สิ่งสุดท้ายที่อยู่ในแฟ้มข้อมูลที่$shortcodes ค่อยจัดการเรื่องโต๊ะที่บรรจุ shortcode นกิจวัตรประจำวัน พวกนี้เป็นแบบเรียบง่าย shortcodes แต่คุณสามารถสร้างอื่น shortcodes เป็นต้อย่างที่ซับซ้อนอย่างที่คุณต้องการ

ทุ shortcodes ต้องยอมรับสองคนพารามิเตอร์:args และเนื้อหาอยู่ภายใน พวกนี้เงื่อนมีพารามิเตอร์ของ shortcode และเนื้อหาของที่ shortcodes อยู่ล้อมรอบตัว ตั้งแต่ shortcodes อยู่ข้างในเป็นค่อยจัดการเรื่องโต๊ะฉันเคยเป็น lambda ฟังก์ชันที่กำหนดพวกมัน เป็น lambda ฟังก์ชันเป็นงานโดยไม่มีชื่อหรอก ทางเดียวที่จะหนีพวกนี้ฟังก์ชันคืออกจากค่อยจัดการเรื่องอาเรย์นะ

ทำงานอยู่ที่เซิร์ฟเวอร์

ครั้งหนึ่งคุณต้องสร้าง rubyPress นrb แฟ้มที่อยู่เหนือเนื้อหาของคุณวิ่งได้โดยเซิร์ฟเวอร์ด้วย:

1
ruby rubyPress.rb

ตั้งแต่ Sinatra เฟรมเวิร์กทำงานกับรูบี้บนลู่นอกทางชั้นโครงสร้างของคุณสามารถใช้โครต้องวิ่งเครื่องเซิร์ฟเวอร์ Pow จะตั้งค่าระบบของคุณเป็นเครื่องแฟ้มสำหรับการทำงานของเซิร์ฟเวอร์ในท้องถิ่นเหมือนมันจะมาจากเว็บไซต์เป็นเจ้าภาพนะ คุณสามารถติดตั้งโครงกับแป้งโดยใช้ตามคำสั่งของอยู่ในบรรทัดคำสั่ง:

1
gem install powder
2
powder install

เขม่าดินคือบรรทัดคำสั่งประจำวันสำหรับจัดการโครเว็บไซต์บนคอมพิวเตอร์ของคุณ. ต้องได้รับนิดเห็นของคุณเว็บไซต์คุณต้องสร้างอ่อนเชื่อมโยงไปยังโครงการของคุณไดเรกทอรีอยู่ที่~/.pow ไดเรกทอรีได้ ถ้าเซิร์ฟเวอร์อยู่ใน/ผู้ใช้/ทดสอบ/เอกสาร/rubyPress ไดเรกทอรี,คุณจะประมวลผลที่ตามคำสั่งของ:

1
cd ~/.pow
2
ln -s /Users/test/Documents/rubyPress rubyPress

ที่ ln-s สร้างอ่อนเชื่อมโยงไปยังไดเรกทอรีที่ระบุไว้ก่อนกับระบุชื่อของอย่างที่สอง Pow จะตั้งเป็นโดเมนอยู่บนระบบของคุณกับชื่อของอ่อนโยน ในด้านบวอย่างเช่นกำลังบนเว็บไซต์ http://rubyPress.dev ในเบราว์เซอร์จะโหลดหน้าเว็บจากเซิร์ฟเวอร์

เริ่มเซิร์ฟเวอร์ประเภทที่ตามหลังจากสร้างที่อ่อนนุ่มเชื่อมโยง:

1
powder start

ต้องเรียกใหม่โดยเซิร์ฟเวอร์หลังจากทำบางอย่างรหัสเปลี่ยนแปลงประเภทต่อไปนี้:

1
powder restart
rubyPress Main PagerubyPress Main PagerubyPress Main Page
rubyPress หลักหน้า

จะไปที่เว็บไซต์ของในเบราว์เซอร์จะถูกด้านบนภาพรวม Pow จะตั้งค่าเว็บไซต์ที่ http://rubyPress.dev ได้ ไม่สำคัญซึ่งวิธีการคุณใช้รถเรียกโปรแกรมเว็บไซต์เธอจะเห็นคนเดียวกับผลลัพธ์จากหน้าอก

สรุป

งั้นคุณต้องทำมัน อีก CMS แต่ครั้งนี้อยู่ในรูบี้ เวอร์ชั่นนี้เป็นห่าเวอร์ชั่นของทั้งหมด CMSs สร้างขึ้นมาอยู่ในนี้ต่อเนื่อง การทดลองกับรหัสและดูว่าคุณสามารถขยายนี้พื้นฐานเฟรมเวิร์กนะ

Advertisement
Did you find this post useful?
Want a weekly email summary?
Subscribe below and we’ll send you a weekly email summary of all new Code tutorials. Never miss out on learning about the next big thing.
Advertisement
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.